Mercurial > octave-nkf
comparison src/lex.l @ 973:46673c918034
[project @ 1994-12-12 17:50:07 by jwe]
author | jwe |
---|---|
date | Mon, 12 Dec 1994 17:50:07 +0000 |
parents | 3e25eb05b6c6 |
children | e7165acbf96f |
comparison
equal
deleted
inserted
replaced
972:3e25eb05b6c6 | 973:46673c918034 |
---|---|
21 */ | 21 */ |
22 | 22 |
23 %x NEW_MATRIX | 23 %x NEW_MATRIX |
24 %x HELP_FCN | 24 %x HELP_FCN |
25 %s TEXT_FCN | 25 %s TEXT_FCN |
26 %s DQSTRING | |
27 %s STRING | |
28 %s MATRIX | 26 %s MATRIX |
29 | 27 |
30 %{ | 28 %{ |
31 #define SHORT_CIRCUIT_LOGICALS 1 | 29 #define SHORT_CIRCUIT_LOGICALS 1 |
32 | 30 |
33 #ifdef HAVE_CONFIG_H | 31 #ifdef HAVE_CONFIG_H |
34 #include "config.h" | 32 #include "config.h" |
35 #endif | 33 #endif |
36 | 34 |
35 #include <strstream.h> | |
37 #include <string.h> | 36 #include <string.h> |
38 | 37 |
39 #include "input.h" | 38 #include "input.h" |
40 #include "token.h" | 39 #include "token.h" |
41 | 40 |
108 static int match_any (char c, char *s); | 107 static int match_any (char c, char *s); |
109 static int next_token_is_bin_op (int spc_prev, char *yytext); | 108 static int next_token_is_bin_op (int spc_prev, char *yytext); |
110 static int next_token_is_postfix_unary_op (int spc_prev, char *yytext); | 109 static int next_token_is_postfix_unary_op (int spc_prev, char *yytext); |
111 static char *strip_trailing_whitespace (char *s); | 110 static char *strip_trailing_whitespace (char *s); |
112 static void handle_number (char *yytext); | 111 static void handle_number (char *yytext); |
112 static int handle_string (char delim); | |
113 static int handle_close_brace (char *yytext); | 113 static int handle_close_brace (char *yytext); |
114 static int handle_identifier (char *s, int next_tok_is_eq); | 114 static int handle_identifier (char *s, int next_tok_is_eq); |
115 | 115 |
116 %} | 116 %} |
117 | 117 |
246 } | 246 } |
247 return TEXT; | 247 return TEXT; |
248 } | 248 } |
249 | 249 |
250 %{ | 250 %{ |
251 // XXX FIXME XXX -- these need to be merged into a single function. | |
252 %} | |
253 | |
254 <STRING>{QSTR}*[\n\'] { | |
255 if (braceflag) | |
256 BEGIN MATRIX; | |
257 else | |
258 BEGIN 0; | |
259 | |
260 if (yytext[yyleng-1] == '\n') | |
261 { | |
262 error ("unterminated string constant"); | |
263 current_input_column = 1; | |
264 return LEXICAL_ERROR; | |
265 } | |
266 else | |
267 { | |
268 static char *tok = 0; | |
269 delete [] tok; | |
270 tok = strsave (yytext); | |
271 tok[yyleng-1] = '\0'; | |
272 do_string_escapes (tok); | |
273 yylval.tok_val = new token (tok); | |
274 token_stack.push (yylval.tok_val); | |
275 quote_is_transpose = 1; | |
276 cant_be_identifier = 1; | |
277 convert_spaces_to_comma = 1; | |
278 current_input_column += yyleng; | |
279 } | |
280 return TEXT; | |
281 } | |
282 | |
283 <DQSTRING>{DQSTR}*[\n\"] { | |
284 if (braceflag) | |
285 BEGIN MATRIX; | |
286 else | |
287 BEGIN 0; | |
288 | |
289 if (yytext[yyleng-1] == '\n') | |
290 { | |
291 error ("unterminated string constant"); | |
292 current_input_column = 1; | |
293 return LEXICAL_ERROR; | |
294 } | |
295 else | |
296 { | |
297 static char *tok = 0; | |
298 delete [] tok; | |
299 tok = strsave (yytext); | |
300 tok[yyleng-1] = '\0'; | |
301 do_string_escapes (tok); | |
302 yylval.tok_val = new token (tok); | |
303 token_stack.push (yylval.tok_val); | |
304 quote_is_transpose = 1; | |
305 cant_be_identifier = 1; | |
306 convert_spaces_to_comma = 1; | |
307 current_input_column += yyleng; | |
308 } | |
309 return TEXT; | |
310 } | |
311 | |
312 %{ | |
313 // For this and the next two rules, we're looking at ']', and we | 251 // For this and the next two rules, we're looking at ']', and we |
314 // need to know if the next token is `=' or `=='. | 252 // need to know if the next token is `=' or `=='. |
315 // | 253 // |
316 // It would have been so much easier if the delimiters were simply | 254 // It would have been so much easier if the delimiters were simply |
317 // different for the expression on the left hand side of the equals | 255 // different for the expression on the left hand side of the equals |
496 { | 434 { |
497 do_comma_insert_check (); | 435 do_comma_insert_check (); |
498 return QUOTE; | 436 return QUOTE; |
499 } | 437 } |
500 else | 438 else |
501 BEGIN STRING; | 439 return handle_string ('\''); |
502 } | 440 } |
503 | 441 |
504 %{ | 442 %{ |
505 // Double quotes always begin strings. | 443 // Double quotes always begin strings. |
506 %} | 444 %} |
507 | 445 |
508 \" { BEGIN DQSTRING; } | 446 \" { |
447 current_input_column++; | |
448 return handle_string ('"'); | |
449 } | |
509 | 450 |
510 %{ | 451 %{ |
511 // The colon operator is handled differently if we are in the range | 452 // The colon operator is handled differently if we are in the range |
512 // part of a plot command. | 453 // part of a plot command. |
513 %} | 454 %} |
775 converting to `%c'", *p2, *p2); | 716 converting to `%c'", *p2, *p2); |
776 *p1 = *p2; | 717 *p1 = *p2; |
777 break; | 718 break; |
778 } | 719 } |
779 } | 720 } |
780 else if (*p2 == '\'' && *(p2+1) == '\'') | |
781 { | |
782 *p1 = '\''; | |
783 p2++; | |
784 } | |
785 else | 721 else |
786 { | 722 { |
787 *p1 = *p2; | 723 *p1 = *p2; |
788 } | 724 } |
789 | 725 |
1413 current_input_column += yyleng; | 1349 current_input_column += yyleng; |
1414 | 1350 |
1415 do_comma_insert_check (); | 1351 do_comma_insert_check (); |
1416 } | 1352 } |
1417 | 1353 |
1354 // Match whitespace only, followed by a comment character or newline. | |
1355 // Once a comment character is found, discard all input until newline. | |
1356 // If non-whitespace characters are found before comment | |
1357 // characters, return 0. Otherwise, return 1. | |
1358 | |
1359 static int | |
1360 have_continuation (void) | |
1361 { | |
1362 ostrstream buf; | |
1363 | |
1364 int in_comment = 0; | |
1365 char c; | |
1366 while ((c = yyinput ()) != EOF) | |
1367 { | |
1368 buf << (char) c; | |
1369 | |
1370 switch (c) | |
1371 { | |
1372 case ' ': | |
1373 case '\t': | |
1374 break; | |
1375 | |
1376 case '%': | |
1377 case '#': | |
1378 in_comment = 1; | |
1379 break; | |
1380 | |
1381 case '\n': | |
1382 return 1; | |
1383 | |
1384 default: | |
1385 if (in_comment) | |
1386 break; | |
1387 else | |
1388 { | |
1389 buf << ends; | |
1390 char *s = buf.str (); | |
1391 if (s) | |
1392 { | |
1393 int len = strlen (s); | |
1394 while (len--) | |
1395 yyunput (s[len], yytext); | |
1396 } | |
1397 delete [] s; | |
1398 return 0; | |
1399 } | |
1400 } | |
1401 } | |
1402 | |
1403 yyunput (c, yytext); | |
1404 | |
1405 return 0; | |
1406 } | |
1407 | |
1408 static int | |
1409 have_ellipsis_continuation (void) | |
1410 { | |
1411 char c1 = yyinput (); | |
1412 if (c1 == '.') | |
1413 { | |
1414 char c2 = yyinput (); | |
1415 if (c2 == '.' && have_continuation ()) | |
1416 return 1; | |
1417 else | |
1418 { | |
1419 yyunput (c2, yytext); | |
1420 yyunput (c1, yytext); | |
1421 } | |
1422 } | |
1423 else | |
1424 yyunput (c1, yytext); | |
1425 | |
1426 return 0; | |
1427 } | |
1428 | |
1429 static int | |
1430 handle_string (char delim) | |
1431 { | |
1432 ostrstream buf; | |
1433 | |
1434 int c; | |
1435 int prev = 0; | |
1436 | |
1437 while ((c = yyinput ()) != EOF) | |
1438 { | |
1439 current_input_column++; | |
1440 | |
1441 if (c == '\\') | |
1442 { | |
1443 if (have_continuation ()) | |
1444 promptflag--; | |
1445 else | |
1446 buf << (char) c; | |
1447 goto next; | |
1448 } | |
1449 else if (c == '.') | |
1450 { | |
1451 if (have_ellipsis_continuation ()) | |
1452 promptflag--; | |
1453 else | |
1454 buf << (char) c; | |
1455 goto next; | |
1456 } | |
1457 else if (c == '\n') | |
1458 { | |
1459 break; | |
1460 } | |
1461 else if (c == delim) | |
1462 { | |
1463 if (prev == '\\') | |
1464 buf << (char) c; | |
1465 else | |
1466 { | |
1467 c = yyinput (); | |
1468 if (c == delim) | |
1469 buf << (char) c; | |
1470 else | |
1471 { | |
1472 yyunput (c, yytext); | |
1473 buf << ends; | |
1474 char *tok = buf.str (); | |
1475 do_string_escapes (tok); | |
1476 yylval.tok_val = new token (tok); | |
1477 delete [] tok; | |
1478 token_stack.push (yylval.tok_val); | |
1479 quote_is_transpose = 1; | |
1480 cant_be_identifier = 1; | |
1481 convert_spaces_to_comma = 1; | |
1482 return TEXT; | |
1483 } | |
1484 } | |
1485 } | |
1486 else | |
1487 { | |
1488 buf << (char) c; | |
1489 } | |
1490 | |
1491 next: | |
1492 prev = c; | |
1493 } | |
1494 | |
1495 return LEXICAL_ERROR; | |
1496 } | |
1497 | |
1418 static int | 1498 static int |
1419 handle_close_brace (char *yytext) | 1499 handle_close_brace (char *yytext) |
1420 { | 1500 { |
1421 fixup_column_count (yytext); | 1501 fixup_column_count (yytext); |
1422 | 1502 |