Mercurial > hg > octave-lyh
diff src/lex.ll @ 12627:002948ae5bc0
fix precedence level of transpose operators (bug #32533)
* Makefile.am: Note 16 shift/reduce conflicts in oct-parse.yy.
* lex.ll (BIN_OP_RETURN_INTERNAL, XBIN_OP_RETURN_INTERNAL): New macros.
(BIN_OP_RETURN): Define using BIN_OP_RETURN_INTERNAL.
("--", "++"): Use XBIN_OP_RETURN_INTERNAL to set
lexer_flags.quote_is_transpose to true.
* oct-parse.yy: Set precedence level as documented and for
compatibility with Matlab. Don't set precedence for comma, semicolon
or newline characters.
(UNARY, PLUS_PLUS, MINUS_MINUS, EXPR_NOT): Associativity is now right,
not left.
(oper_expr): New non-terminal. Merge all operator non-terminals
except postfix increment and decrement into oper_expr.
(prefix_expr, binary_expr): Delete unused non-terminals.
* expr.txi: Document precedence to match reality.
* test_parser.m: Fix tests for increment and decrement operators to
match current behavior.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Apr 2011 17:41:56 -0400 |
parents | db1f49eaba6b |
children | 2837514cf178 |
line wrap: on
line diff
--- a/src/lex.ll +++ b/src/lex.ll @@ -164,13 +164,13 @@ } \ while (0) -#define BIN_OP_RETURN(tok, convert, bos) \ +#define BIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ do \ { \ yylval.tok_val = new token (input_line_number, current_input_column); \ token_stack.push (yylval.tok_val); \ current_input_column += yyleng; \ - lexer_flags.quote_is_transpose = false; \ + lexer_flags.quote_is_transpose = qit; \ lexer_flags.convert_spaces_to_comma = convert; \ lexer_flags.looking_for_object_index = false; \ lexer_flags.at_beginning_of_statement = bos; \ @@ -178,6 +178,21 @@ } \ while (0) +#define XBIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ + do \ + { \ + gripe_matlab_incompatible_operator (yytext); \ + BIN_OP_RETURN_INTERNAL (tok, convert, bos, qit); \ + } \ + while (0) + +#define BIN_OP_RETURN(tok, convert, bos) \ + do \ + { \ + BIN_OP_RETURN_INTERNAL (tok, convert, bos, false); \ + } \ + while (0) + #define XBIN_OP_RETURN(tok, convert, bos) \ do \ { \ @@ -896,8 +911,8 @@ ".^" { LEXER_DEBUG (".^"); BIN_OP_RETURN (EPOW, false, false); } ".**" { LEXER_DEBUG (".**"); XBIN_OP_RETURN (EPOW, false, false); } ".'" { LEXER_DEBUG (".'"); do_comma_insert_check (); BIN_OP_RETURN (TRANSPOSE, true, false); } -"++" { LEXER_DEBUG ("++"); do_comma_insert_check (); XBIN_OP_RETURN (PLUS_PLUS, true, false); } -"--" { LEXER_DEBUG ("--"); do_comma_insert_check (); XBIN_OP_RETURN (MINUS_MINUS, true, false); } +"++" { LEXER_DEBUG ("++"); do_comma_insert_check (); XBIN_OP_RETURN_INTERNAL (PLUS_PLUS, true, false, true); } +"--" { LEXER_DEBUG ("--"); do_comma_insert_check (); XBIN_OP_RETURN_INTERNAL (MINUS_MINUS, true, false, true); } "<=" { LEXER_DEBUG ("<="); BIN_OP_RETURN (EXPR_LE, false, false); } "==" { LEXER_DEBUG ("=="); BIN_OP_RETURN (EXPR_EQ, false, false); } "~=" { LEXER_DEBUG ("~="); BIN_OP_RETURN (EXPR_NE, false, false); }