comparison libinterp/parse-tree/lex.ll @ 16269:488b0fef52c5

7/10 commits reworking the lexer
author John W. Eaton <jwe@octave.org>
date Mon, 11 Mar 2013 14:31:48 -0400
parents 15f55df088e7
children 3b0381ea8737 87069bd38107
comparison
equal deleted inserted replaced
16267:15f55df088e7 16269:488b0fef52c5
1501 { 1501 {
1502 if (c == tmp) 1502 if (c == tmp)
1503 return true; 1503 return true;
1504 } 1504 }
1505 return false; 1505 return false;
1506 }
1507
1508 // Given information about the spacing surrounding an operator,
1509 // return 1 if it looks like it should be treated as a binary
1510 // operator. For example,
1511 //
1512 // [ 1 + 2 ] or [ 1+ 2] or [ 1+2 ] ==> binary
1513 //
1514 // [ 1 +2 ] ==> unary
1515
1516 static bool
1517 looks_like_bin_op (bool spc_prev, int next_char)
1518 {
1519 bool spc_next = (next_char == ' ' || next_char == '\t');
1520
1521 return ((spc_prev && spc_next) || ! spc_prev);
1522 } 1506 }
1523 1507
1524 bool 1508 bool
1525 is_keyword (const std::string& s) 1509 is_keyword (const std::string& s)
1526 { 1510 {
2680 } 2664 }
2681 2665
2682 return (isalnum (c) || match_any (c, "!\"'(-[_{~")); 2666 return (isalnum (c) || match_any (c, "!\"'(-[_{~"));
2683 } 2667 }
2684 2668
2685 static bool
2686 can_be_command (const std::string& tok)
2687 {
2688 // Don't allow these names to be treated as commands to avoid
2689 // surprises when parsing things like "NaN ^2".
2690
2691 return ! (tok == "e"
2692 || tok == "I" || tok == "i"
2693 || tok == "J" || tok == "j"
2694 || tok == "Inf" || tok == "inf"
2695 || tok == "NaN" || tok == "nan");
2696 }
2697
2698 bool 2669 bool
2699 octave_lexer::looks_like_command_arg (void) 2670 octave_lexer::looks_like_command_arg (void)
2700 { 2671 {
2701 bool retval = true; 2672 bool retval = true;
2702 2673
3111 tok = "__end__"; 3082 tok = "__end__";
3112 3083
3113 token *tok_val = new token (NAME, &(symbol_table::insert (tok)), 3084 token *tok_val = new token (NAME, &(symbol_table::insert (tok)),
3114 input_line_number, current_input_column); 3085 input_line_number, current_input_column);
3115 3086
3116 if (at_beginning_of_statement) 3087 if (at_beginning_of_statement
3088 && (! (tok == "e"
3089 || tok == "I" || tok == "i"
3090 || tok == "J" || tok == "j"
3091 || tok == "Inf" || tok == "inf"
3092 || tok == "NaN" || tok == "nan")))
3117 tok_val->mark_may_be_command (); 3093 tok_val->mark_may_be_command ();
3118 3094
3119 push_token (tok_val); 3095 push_token (tok_val);
3120 3096
3121 current_input_column += flex_yyleng (); 3097 current_input_column += flex_yyleng ();