Mercurial > hg > octave-avbm
changeset 1276:cbdf7db98554
[project @ 1995-04-24 15:31:24 by jwe]
author | jwe |
---|---|
date | Mon, 24 Apr 1995 15:31:24 +0000 |
parents | d607adf5af66 |
children | db4f4009d6e8 |
files | src/lex.l src/parse.y |
diffstat | 2 files changed, 24 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lex.l +++ b/src/lex.l @@ -142,8 +142,6 @@ NOTEQ ((~=)|(!=)|(<>)) POW ((\*\*)|(\^)) EPOW (\.{POW}) -PLUS ((\+)|(\.\+)) -MINUS ((\-)|(\.\-)) NOT ((\~)|(\!)) IDENT ([_a-zA-Z][_a-zA-Z0-9]*) EXPON ([DdEe][+-]?{D}+) @@ -503,6 +501,8 @@ // Other operators. %} +".+" { BIN_OP_RETURN (EPLUS, 0); } +".-" { BIN_OP_RETURN (EMINUS, 0); } ".*" { BIN_OP_RETURN (EMUL, 0); } "./" { BIN_OP_RETURN (EDIV, 0); } ".\\" { BIN_OP_RETURN (ELEFTDIV, 0); } @@ -548,13 +548,13 @@ BIN_OP_RETURN (EXPR_NOT, 0); } -{PLUS} { +"+" { if (plotting && ! in_plot_range) past_plot_range = 1; BIN_OP_RETURN ('+', 0); } -{MINUS} { +"-" { if (plotting && ! in_plot_range) past_plot_range = 1; BIN_OP_RETURN ('-', 0); @@ -1239,96 +1239,49 @@ // Try to determine if the next token should be treated as a binary // operator. This is even uglier, but it also seems to do the right -// thing. +// thing. Note that it is only necessary to check the spacing for `+' +// and `-', since those are the only tokens that can appear as unary +// ops too. static int next_token_is_bin_op (int spc_prev, char *yytext) { int bin_op = 0; - int spc_next = 0; int c0 = yyinput (); - int c1 = yyinput (); switch (c0) { case '+': case '-': + { + int c1 = yyinput (); + yyunput (c1, yytext); + int spc_next = (c1 == ' ' || c1 == '\t'); + bin_op = looks_like_bin_op (spc_prev, spc_next); + } + break; + case '/': case ':': case '\\': case '^': - spc_next = (c1 == ' ' || c1 == '\t'); - break; - case '&': - if (c1 == '&') - spc_next = next_char_is_space (); - else - spc_next = (c1 == ' ' || c1 == '\t'); - break; - case '*': - if (c1 == '*') - spc_next = next_char_is_space (); - else - spc_next = (c1 == ' ' || c1 == '\t'); - break; - case '|': - if (c1 == '|') - spc_next = next_char_is_space (); - else - spc_next = (c1 == ' ' || c1 == '\t'); - break; - case '<': - if (c1 == '=' || c1 == '>') - spc_next = next_char_is_space (); - else - spc_next = (c1 == ' ' || c1 == '\t'); - break; - case '>': - if (c1 == '=') - spc_next = next_char_is_space (); - else - spc_next = (c1 == ' ' || c1 == '\t'); - break; - case '~': case '!': case '=': - if (c1 == '=') - spc_next = next_char_is_space (); - else - goto done; - break; - case '.': - if (c1 == '*') - { - int c2 = yyinput (); - if (c2 == '*') - spc_next = next_char_is_space (); - else - spc_next = (c2 == ' ' || c2 == '\t'); - yyunput (c2, yytext); - } - else if (c1 == '/' || c1 == '\\' || c1 == '^') - spc_next = next_char_is_space (); - else - goto done; + bin_op = 1; break; default: - goto done; + break; } - bin_op = looks_like_bin_op (spc_prev, spc_next); - - done: - yyunput (c1, yytext); yyunput (c0, yytext); return bin_op;
--- a/src/parse.y +++ b/src/parse.y @@ -213,7 +213,8 @@ %token <tok_val> EXPR_AND_AND EXPR_OR_OR %token <tok_val> EXPR_AND EXPR_OR EXPR_NOT %token <tok_val> EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT -%token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV QUOTE TRANSPOSE +%token <tok_val> LEFTDIV EMUL EDIV ELEFTDIV EPLUS EMINUS +%token <tok_val> QUOTE TRANSPOSE %token <tok_val> PLUS_PLUS MINUS_MINUS POW EPOW %token <tok_val> NUM IMAG_NUM %token <tok_val> NAME SCREW @@ -271,7 +272,7 @@ %left EXPR_AND EXPR_OR %left EXPR_LT EXPR_LE EXPR_EQ EXPR_NE EXPR_GE EXPR_GT %left ':' -%left '-' '+' +%left '-' '+' EPLUS EMINUS %left '*' '/' LEFTDIV EMUL EDIV ELEFTDIV %left QUOTE TRANSPOSE %left UNARY PLUS_PLUS MINUS_MINUS EXPR_NOT @@ -767,6 +768,10 @@ { $$ = make_binary_op ('*', $1, $2, $3); } | simple_expr '/' simple_expr { $$ = make_binary_op ('/', $1, $2, $3); } + | simple_expr EPLUS simple_expr + { $$ = make_binary_op ('+', $1, $2, $3); } + | simple_expr EMINUS simple_expr + { $$ = make_binary_op ('-', $1, $2, $3); } | simple_expr EMUL simple_expr { $$ = make_binary_op (EMUL, $1, $2, $3); } | simple_expr EDIV simple_expr