Mercurial > octave-nkf
comparison src/lex.l @ 971:fe71abb43457
[project @ 1994-12-12 15:10:22 by jwe]
author | jwe |
---|---|
date | Mon, 12 Dec 1994 15:10:22 +0000 |
parents | 9382316a8a01 |
children | 3e25eb05b6c6 |
comparison
equal
deleted
inserted
replaced
970:9382316a8a01 | 971:fe71abb43457 |
---|---|
107 static void grab_help_text (void); | 107 static void grab_help_text (void); |
108 static int match_any (char c, char *s); | 108 static int match_any (char c, char *s); |
109 static int next_token_is_bin_op (int spc_prev, char *yytext); | 109 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); | 110 static int next_token_is_postfix_unary_op (int spc_prev, char *yytext); |
111 static char *strip_trailing_whitespace (char *s); | 111 static char *strip_trailing_whitespace (char *s); |
112 static int handle_close_brace (char *yytext); | |
112 static int handle_identifier (char *s, int next_tok_is_eq); | 113 static int handle_identifier (char *s, int next_tok_is_eq); |
113 | 114 |
114 %} | 115 %} |
115 | 116 |
116 D [0-9] | 117 D [0-9] |
306 } | 307 } |
307 return TEXT; | 308 return TEXT; |
308 } | 309 } |
309 | 310 |
310 %{ | 311 %{ |
311 // It's also a pain in the ass to decide whether to insert a comma | |
312 // after seeing a ']' character... | |
313 // | |
314 // For this and the next two rules, we're looking at ']', and we | 312 // For this and the next two rules, we're looking at ']', and we |
315 // need to know if the next token is '='. | 313 // need to know if the next token is `=' or `=='. |
316 // | |
317 // All this so we can handle the bogus syntax | |
318 // | |
319 // [x,y] % an expression by itself | |
320 // [x,y] = expression % assignment to a list of identifiers | |
321 // [x,y] == expression % test for equality | |
322 // | 314 // |
323 // It would have been so much easier if the delimiters were simply | 315 // It would have been so much easier if the delimiters were simply |
324 // different for the expression on the left hand side of the equals | 316 // different for the expression on the left hand side of the equals |
325 // operator. | 317 // operator. |
318 // | |
319 // It's also a pain in the ass to decide whether to insert a comma | |
320 // after seeing a ']' character... | |
326 %} | 321 %} |
327 | 322 |
328 <MATRIX>{SNL}*\]{S}* { | 323 <MATRIX>{SNL}*\]{S}* { |
329 fixup_column_count (yytext); | 324 return handle_close_brace (yytext); |
330 | |
331 if (! in_brace_or_paren.empty ()) | |
332 { | |
333 in_brace_or_paren.pop (); | |
334 braceflag--; | |
335 } | |
336 | |
337 if (braceflag == 0) | |
338 { | |
339 if (! defining_func) | |
340 promptflag++; | |
341 BEGIN 0; | |
342 } | |
343 | |
344 int c1 = yyinput (); | |
345 | |
346 if (c1 == '=') | |
347 { | |
348 quote_is_transpose = 0; | |
349 cant_be_identifier = 0; | |
350 convert_spaces_to_comma = 1; | |
351 | |
352 int c2 = yyinput (); | |
353 unput (c2); | |
354 unput (c1); | |
355 | |
356 if (c2 != '=' && maybe_screwed_again) | |
357 return SCREW_TWO; | |
358 else | |
359 return ']'; | |
360 } | |
361 else | |
362 { | |
363 unput (c1); | |
364 | |
365 if (braceflag && user_pref.commas_in_literal_matrix != 2) | |
366 { | |
367 int c0 = yytext[yyleng-1]; | |
368 int spc_prev = (c0 == ' ' || c0 == '\t'); | |
369 int bin_op = next_token_is_bin_op (spc_prev, yytext); | |
370 int postfix_un_op = next_token_is_postfix_unary_op | |
371 (spc_prev, yytext); | |
372 | |
373 int other_op = match_any (c1, ",;\n]"); | |
374 | |
375 if (! (postfix_un_op || bin_op || other_op | |
376 || in_brace_or_paren.empty ()) | |
377 && in_brace_or_paren.top () | |
378 && convert_spaces_to_comma) | |
379 { | |
380 unput (','); | |
381 return ']'; | |
382 } | |
383 } | |
384 } | |
385 | |
386 quote_is_transpose = 1; | |
387 cant_be_identifier = 0; | |
388 convert_spaces_to_comma = 1; | |
389 return ']'; | |
390 } | 325 } |
391 | 326 |
392 %{ | 327 %{ |
393 // Commas are element separators in matrix constants. | 328 // Commas are element separators in matrix constants. |
394 %} | 329 %} |
588 else | 523 else |
589 BEGIN STRING; | 524 BEGIN STRING; |
590 } | 525 } |
591 | 526 |
592 %{ | 527 %{ |
593 // Colon operator is handled differently if we are in the range part | 528 // Double quotes always begin strings. |
594 // of a plot command. | 529 %} |
530 | |
531 \" { BEGIN DQSTRING; } | |
532 | |
533 %{ | |
534 // The colon operator is handled differently if we are in the range | |
535 // part of a plot command. | |
595 %} | 536 %} |
596 | 537 |
597 ":" { | 538 ":" { |
598 if (plotting && (in_plot_range || in_plot_using)) | 539 if (plotting && (in_plot_range || in_plot_using)) |
599 BIN_OP_RETURN (COLON, 1); | 540 BIN_OP_RETURN (COLON, 1); |
627 | 568 |
628 %{ | 569 %{ |
629 // Other operators. | 570 // Other operators. |
630 %} | 571 %} |
631 | 572 |
632 \" { BEGIN DQSTRING; } | |
633 ".*" { BIN_OP_RETURN (EMUL, 0); } | 573 ".*" { BIN_OP_RETURN (EMUL, 0); } |
634 "./" { BIN_OP_RETURN (EDIV, 0); } | 574 "./" { BIN_OP_RETURN (EDIV, 0); } |
635 ".\\" { BIN_OP_RETURN (ELEFTDIV, 0); } | 575 ".\\" { BIN_OP_RETURN (ELEFTDIV, 0); } |
636 {EPOW} { BIN_OP_RETURN (EPOW, 0); } | 576 {EPOW} { BIN_OP_RETURN (EPOW, 0); } |
637 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, 1); } | 577 ".'" { do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, 1); } |
1471 *t = '\0'; | 1411 *t = '\0'; |
1472 | 1412 |
1473 return retval; | 1413 return retval; |
1474 } | 1414 } |
1475 | 1415 |
1416 static int | |
1417 handle_close_brace (char *yytext) | |
1418 { | |
1419 fixup_column_count (yytext); | |
1420 | |
1421 if (! in_brace_or_paren.empty ()) | |
1422 { | |
1423 in_brace_or_paren.pop (); | |
1424 braceflag--; | |
1425 } | |
1426 | |
1427 if (braceflag == 0) | |
1428 { | |
1429 if (! defining_func) | |
1430 promptflag++; | |
1431 BEGIN 0; | |
1432 } | |
1433 | |
1434 int c1 = yyinput (); | |
1435 | |
1436 if (c1 == '=') | |
1437 { | |
1438 quote_is_transpose = 0; | |
1439 cant_be_identifier = 0; | |
1440 convert_spaces_to_comma = 1; | |
1441 | |
1442 int c2 = yyinput (); | |
1443 unput (c2); | |
1444 unput (c1); | |
1445 | |
1446 if (c2 != '=' && maybe_screwed_again) | |
1447 return SCREW_TWO; | |
1448 else | |
1449 return ']'; | |
1450 } | |
1451 else | |
1452 { | |
1453 unput (c1); | |
1454 | |
1455 if (braceflag && user_pref.commas_in_literal_matrix != 2) | |
1456 { | |
1457 int c0 = yytext[yyleng-1]; | |
1458 int spc_prev = (c0 == ' ' || c0 == '\t'); | |
1459 int bin_op = next_token_is_bin_op (spc_prev, yytext); | |
1460 int postfix_un_op = next_token_is_postfix_unary_op | |
1461 (spc_prev, yytext); | |
1462 | |
1463 int other_op = match_any (c1, ",;\n]"); | |
1464 | |
1465 if (! (postfix_un_op || bin_op || other_op | |
1466 || in_brace_or_paren.empty ()) | |
1467 && in_brace_or_paren.top () | |
1468 && convert_spaces_to_comma) | |
1469 { | |
1470 unput (','); | |
1471 return ']'; | |
1472 } | |
1473 } | |
1474 } | |
1475 | |
1476 quote_is_transpose = 1; | |
1477 cant_be_identifier = 0; | |
1478 convert_spaces_to_comma = 1; | |
1479 return ']'; | |
1480 } | |
1481 | |
1476 // Figure out exactly what kind of token to return when we have seen | 1482 // Figure out exactly what kind of token to return when we have seen |
1477 // an identifier. Handles keywords. | 1483 // an identifier. Handles keywords. |
1478 | 1484 |
1479 static int | 1485 static int |
1480 handle_identifier (char *tok, int next_tok_is_eq) | 1486 handle_identifier (char *tok, int next_tok_is_eq) |