comparison src/lex.l @ 2877:5c1b9e545dd1

[project @ 1997-04-24 09:07:39 by jwe]
author jwe
date Thu, 24 Apr 1997 09:10:13 +0000
parents 6dcb8e1c9bb2
children 1a30f46e1870
comparison
equal deleted inserted replaced
2876:b4a9f014a8ea 2877:5c1b9e545dd1
570 "--" { do_comma_insert_check (); BIN_OP_RETURN (MINUS_MINUS, true); } 570 "--" { do_comma_insert_check (); BIN_OP_RETURN (MINUS_MINUS, true); }
571 "<=" { BIN_OP_RETURN (EXPR_LE, false); } 571 "<=" { BIN_OP_RETURN (EXPR_LE, false); }
572 "==" { BIN_OP_RETURN (EXPR_EQ, false); } 572 "==" { BIN_OP_RETURN (EXPR_EQ, false); }
573 {NOTEQ} { BIN_OP_RETURN (EXPR_NE, false); } 573 {NOTEQ} { BIN_OP_RETURN (EXPR_NE, false); }
574 ">=" { BIN_OP_RETURN (EXPR_GE, false); } 574 ">=" { BIN_OP_RETURN (EXPR_GE, false); }
575 "&" { BIN_OP_RETURN (EXPR_AND, false); }
575 "|" { BIN_OP_RETURN (EXPR_OR, false); } 576 "|" { BIN_OP_RETURN (EXPR_OR, false); }
576 "&" { BIN_OP_RETURN (EXPR_AND, false); }
577 "<" { BIN_OP_RETURN (EXPR_LT, false); } 577 "<" { BIN_OP_RETURN (EXPR_LT, false); }
578 ">" { BIN_OP_RETURN (EXPR_GT, false); } 578 ">" { BIN_OP_RETURN (EXPR_GT, false); }
579 "*" { BIN_OP_RETURN ('*', false); } 579 "*" { BIN_OP_RETURN ('*', false); }
580 "/" { BIN_OP_RETURN ('/', false); } 580 "/" { BIN_OP_RETURN ('/', false); }
581 "\\" { BIN_OP_RETURN (LEFTDIV, false); } 581 "\\" { BIN_OP_RETURN (LEFTDIV, false); }
582 ";" { BIN_OP_RETURN (';', true); } 582 ";" { BIN_OP_RETURN (';', true); }
583 "," { BIN_OP_RETURN (',', true); } 583 "," { BIN_OP_RETURN (',', true); }
584 {POW} { BIN_OP_RETURN (POW, false); } 584 {POW} { BIN_OP_RETURN (POW, false); }
585 "=" { BIN_OP_RETURN ('=', true); } 585 "=" { BIN_OP_RETURN ('=', true); }
586 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); }
586 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); } 587 "||" { BIN_OP_RETURN (EXPR_OR_OR, false); }
587 "&&" { BIN_OP_RETURN (EXPR_AND_AND, false); }
588 588
589 {NOT} { 589 {NOT} {
590 if (lexer_flags.plotting && ! lexer_flags.in_plot_range) 590 if (lexer_flags.plotting && ! lexer_flags.in_plot_range)
591 lexer_flags.past_plot_range = true; 591 lexer_flags.past_plot_range = true;
592 BIN_OP_RETURN (EXPR_NOT, false); 592 BIN_OP_RETURN (EXPR_NOT, false);
624 } 624 }
625 625
626 "." { 626 "." {
627 TOK_RETURN ('.'); 627 TOK_RETURN ('.');
628 } 628 }
629
630 "+=" { BIN_OP_RETURN (ADD_EQ, false); }
631 "-=" { BIN_OP_RETURN (SUB_EQ, false); }
632 "*=" { BIN_OP_RETURN (MUL_EQ, false); }
633 "/=" { BIN_OP_RETURN (DIV_EQ, false); }
634 ".+=" { BIN_OP_RETURN (ADD_EQ, false); }
635 ".-=" { BIN_OP_RETURN (SUB_EQ, false); }
636 ".*=" { BIN_OP_RETURN (EMUL_EQ, false); }
637 "./=" { BIN_OP_RETURN (EDIV_EQ, false); }
638 "&=" { BIN_OP_RETURN (AND_EQ, false); }
639 "|=" { BIN_OP_RETURN (OR_EQ, false); }
629 640
630 %{ 641 %{
631 // Unrecognized input is a lexical error. 642 // Unrecognized input is a lexical error.
632 %} 643 %}
633 644
924 { 935 {
925 return 0; 936 return 0;
926 } 937 }
927 } 938 }
928 939
929 // Handle keywords. Could probably be more efficient... 940 // Handle keywords.
930 941
931 static int 942 static int
932 is_keyword (const string& s) 943 is_keyword (const string& s)
933 { 944 {
934 if (lexer_flags.plotting && lexer_flags.in_plot_style) 945 if (lexer_flags.plotting && lexer_flags.in_plot_style)
1046 1057
1047 return LEXICAL_ERROR; 1058 return LEXICAL_ERROR;
1048 } 1059 }
1049 else 1060 else
1050 { 1061 {
1062 // Prepare for local symbols.
1063
1051 tmp_local_sym_tab = new symbol_table (); 1064 tmp_local_sym_tab = new symbol_table ();
1052 curr_sym_tab = tmp_local_sym_tab; 1065
1066 promptflag--;
1067
1053 lexer_flags.defining_func = true; 1068 lexer_flags.defining_func = true;
1054 promptflag--; 1069 lexer_flags.parsed_function_name = false;
1055 lexer_flags.beginning_of_function = true; 1070 lexer_flags.beginning_of_function = true;
1071
1056 if (! (reading_fcn_file || reading_script_file)) 1072 if (! (reading_fcn_file || reading_script_file))
1057 input_line_number = 1; 1073 input_line_number = 1;
1058 } 1074 }
1059 break; 1075 break;
1060 1076
1766 bool next_tok_is_paren = (c == '('); 1782 bool next_tok_is_paren = (c == '(');
1767 1783
1768 // Make sure we put the return values of a function in the symbol 1784 // Make sure we put the return values of a function in the symbol
1769 // table that is local to the function. 1785 // table that is local to the function.
1770 1786
1787 // If we are defining a function and we have not seen the function
1788 // name yet and the next token is `=', then this identifier must be
1789 // the only return value for the function and it belongs in the
1790 // local symbol table.
1791
1771 if (next_tok_is_eq 1792 if (next_tok_is_eq
1772 && lexer_flags.defining_func && lexer_flags.maybe_screwed) 1793 && lexer_flags.defining_func
1794 && ! lexer_flags.parsed_function_name)
1773 curr_sym_tab = tmp_local_sym_tab; 1795 curr_sym_tab = tmp_local_sym_tab;
1774 1796
1775 // Kluge alert. 1797 // Kluge alert.
1776 // 1798 //
1777 // If we are looking at a text style function, set up to gobble its 1799 // If we are looking at a text style function, set up to gobble its
1809 // After seeing an identifer, it is ok to convert spaces to a comma 1831 // After seeing an identifer, it is ok to convert spaces to a comma
1810 // (if needed). 1832 // (if needed).
1811 1833
1812 lexer_flags.convert_spaces_to_comma = true; 1834 lexer_flags.convert_spaces_to_comma = true;
1813 1835
1814 // If we are defining a function and we have not seen the parameter 1836 if (! next_tok_is_eq)
1815 // list yet and the next token is `=', return a token that 1837 {
1816 // represents the only return value for the function. For example, 1838 lexer_flags.quote_is_transpose = true;
1817 // 1839
1818 // function SCREW = f (args); 1840 do_comma_insert_check ();
1819 // 1841
1820 // The variable maybe_screwed is reset in parse.y. 1842 maybe_unput_comma (spc_gobbled);
1821 1843 }
1822 if (next_tok_is_eq)
1823 {
1824 current_input_column += yyleng;
1825 if (lexer_flags.defining_func && lexer_flags.maybe_screwed)
1826 return SCREW;
1827 else
1828 return NAME;
1829 }
1830
1831 // At this point, we are only dealing with identifiers that are not
1832 // followed by `=' (if the next token is `=', there is no need to
1833 // check to see if we should insert a comma (invalid syntax), or
1834 // allow a following `'' to be treated as a transpose (the next
1835 // token is `=', so it can't be `''.
1836
1837 lexer_flags.quote_is_transpose = true;
1838 do_comma_insert_check ();
1839
1840 maybe_unput_comma (spc_gobbled);
1841 1844
1842 current_input_column += yyleng; 1845 current_input_column += yyleng;
1846
1843 return NAME; 1847 return NAME;
1844 } 1848 }
1845 1849
1846 // Print a warning if a function file that defines a function has 1850 // Print a warning if a function file that defines a function has
1847 // anything other than comments and whitespace following the END token 1851 // anything other than comments and whitespace following the END token
1903 looping = 0; 1907 looping = 0;
1904 1908
1905 // Not initially defining a function. 1909 // Not initially defining a function.
1906 beginning_of_function = false; 1910 beginning_of_function = false;
1907 defining_func = false; 1911 defining_func = false;
1912 parsed_function_name = false;
1908 1913
1909 // Not parsing a function return or parameter list. 1914 // Not parsing a function return or parameter list.
1910 looking_at_return_list = false; 1915 looking_at_return_list = false;
1911 looking_at_parameter_list = false; 1916 looking_at_parameter_list = false;
1912 1917
1928 1933
1929 // Not initially looking at indirect references. 1934 // Not initially looking at indirect references.
1930 looking_at_indirect_ref = false; 1935 looking_at_indirect_ref = false;
1931 1936
1932 // Not initially screwed by `function [...] = f (...)' syntax. 1937 // Not initially screwed by `function [...] = f (...)' syntax.
1933 maybe_screwed = false;
1934 maybe_screwed_again = 0; 1938 maybe_screwed_again = 0;
1935 1939
1936 // Quote marks strings intially. 1940 // Quote marks strings intially.
1937 quote_is_transpose = false; 1941 quote_is_transpose = false;
1938 } 1942 }
1957 symbols_of_lex (void) 1961 symbols_of_lex (void)
1958 { 1962 {
1959 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix, 1963 DEFVAR (whitespace_in_literal_matrix, "", 0, whitespace_in_literal_matrix,
1960 "control auto-insertion of commas and semicolons in literal matrices"); 1964 "control auto-insertion of commas and semicolons in literal matrices");
1961 } 1965 }
1962
1963 // Maybe someday...
1964 //
1965 // "+=" return ADD_EQ;
1966 // "-=" return SUB_EQ;
1967 // "*=" return MUL_EQ;
1968 // "/=" return DIV_EQ;
1969 // "\\=" return LEFTDIV_EQ;
1970 // ".+=" return ADD_EQ;
1971 // ".-=" return SUB_EQ;
1972 // ".*=" return EMUL_EQ;
1973 // "./=" return EDIV_EQ;
1974 // ".\\=" return ELEFTDIV_EQ;
1975 1966
1976 /* 1967 /*
1977 ;;; Local Variables: *** 1968 ;;; Local Variables: ***
1978 ;;; mode: C++ *** 1969 ;;; mode: C++ ***
1979 ;;; End: *** 1970 ;;; End: ***