Mercurial > hg > octave-lyh
comparison libinterp/parse-tree/lex.ll @ 16164:c5bfdc4c0963
move end_of_input flag from octve_parser class to octave_lexer class
* lex.h, lex.ll, parse.h, oct-parse.yy, toplev.cc
(octave_lexer::end_of_input): Move data member from octave_parser.
Change all uses.
* lex.h, lex.ll (octave_lexer::handle_end_of_input): New function.
(<<EOF>>): Use it.
({CCHAR}, .): USe it instead of simply returning END_OF_INPUT token.
* lex.ll (octave_lexer::xunput): Don't unput EOF.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 01 Mar 2013 07:10:31 -0500 |
parents | 7eb614760ddb |
children | cb80b1d062b1 |
comparison
equal
deleted
inserted
replaced
16163:34898b3fc32a | 16164:c5bfdc4c0963 |
---|---|
610 %{ | 610 %{ |
611 // End of file. | 611 // End of file. |
612 %} | 612 %} |
613 | 613 |
614 <<EOF>> { | 614 <<EOF>> { |
615 LEXER_DEBUG ("<<EOF>>"); | 615 return curr_lexer->handle_end_of_input (); |
616 | |
617 if (curr_lexer->block_comment_nesting_level != 0) | |
618 { | |
619 warning ("block comment open at end of input"); | |
620 | |
621 if ((reading_fcn_file || reading_script_file || reading_classdef_file) | |
622 && ! curr_fcn_file_name.empty ()) | |
623 warning ("near line %d of file '%s.m'", | |
624 curr_lexer->input_line_number, curr_fcn_file_name.c_str ()); | |
625 } | |
626 | |
627 TOK_RETURN (END_OF_INPUT); | |
628 } | 616 } |
629 | 617 |
630 %{ | 618 %{ |
631 // Identifiers. Truncate the token at the first space or tab but | 619 // Identifiers. Truncate the token at the first space or tab but |
632 // don't write directly on yytext. | 620 // don't write directly on yytext. |
774 | 762 |
775 bool eof = false; | 763 bool eof = false; |
776 int tok = curr_lexer->process_comment (false, eof); | 764 int tok = curr_lexer->process_comment (false, eof); |
777 | 765 |
778 if (eof) | 766 if (eof) |
779 TOK_RETURN (END_OF_INPUT); | 767 return curr_lexer->handle_end_of_input (); |
780 else if (tok > 0) | 768 else if (tok > 0) |
781 COUNT_TOK_AND_RETURN (tok); | 769 COUNT_TOK_AND_RETURN (tok); |
782 } | 770 } |
783 | 771 |
784 %{ | 772 %{ |
973 curr_lexer->input_line_number, curr_lexer->current_input_column); | 961 curr_lexer->input_line_number, curr_lexer->current_input_column); |
974 | 962 |
975 return LEXICAL_ERROR; | 963 return LEXICAL_ERROR; |
976 } | 964 } |
977 else | 965 else |
978 TOK_RETURN (END_OF_INPUT); | 966 return curr_lexer->handle_end_of_input (); |
979 } | 967 } |
980 | 968 |
981 %% | 969 %% |
982 | 970 |
983 static void | 971 static void |
1449 } | 1437 } |
1450 | 1438 |
1451 return status; | 1439 return status; |
1452 } | 1440 } |
1453 | 1441 |
1442 int | |
1443 octave_lexer::handle_end_of_input (void) | |
1444 { | |
1445 // FIXME -- we need this because of the way TOK_RETURN is defined. DO | |
1446 // something better than that... | |
1447 OCTAVE_YYG; | |
1448 | |
1449 LEXER_DEBUG ("<<EOF>>"); | |
1450 | |
1451 if (block_comment_nesting_level != 0) | |
1452 { | |
1453 warning ("block comment open at end of input"); | |
1454 | |
1455 if ((reading_fcn_file || reading_script_file || reading_classdef_file) | |
1456 && ! curr_fcn_file_name.empty ()) | |
1457 warning ("near line %d of file '%s.m'", | |
1458 input_line_number, curr_fcn_file_name.c_str ()); | |
1459 } | |
1460 | |
1461 TOK_RETURN (END_OF_INPUT); | |
1462 } | |
1463 | |
1454 char * | 1464 char * |
1455 octave_lexer::flex_yytext (void) | 1465 octave_lexer::flex_yytext (void) |
1456 { | 1466 { |
1457 return yyget_text (scanner); | 1467 return yyget_text (scanner); |
1458 } | 1468 } |
1523 } | 1533 } |
1524 | 1534 |
1525 void | 1535 void |
1526 octave_lexer::xunput (char c, char *buf) | 1536 octave_lexer::xunput (char c, char *buf) |
1527 { | 1537 { |
1528 if (lexer_debug_flag) | 1538 if (c != EOF) |
1529 { | 1539 { |
1530 std::cerr << "U: "; | 1540 if (lexer_debug_flag) |
1531 display_character (c); | 1541 { |
1532 std::cerr << std::endl; | 1542 std::cerr << "U: "; |
1533 } | 1543 display_character (c); |
1534 | 1544 std::cerr << std::endl; |
1535 if (c == '\n') | 1545 } |
1536 input_line_number--; | 1546 |
1537 | 1547 if (c == '\n') |
1538 yyunput (c, buf, scanner); | 1548 input_line_number--; |
1549 | |
1550 yyunput (c, buf, scanner); | |
1551 } | |
1539 } | 1552 } |
1540 | 1553 |
1541 void | 1554 void |
1542 octave_lexer::xunput (char c) | 1555 octave_lexer::xunput (char c) |
1543 { | 1556 { |