1 %{ 2 #include "y.tab.h" 3 extern yylval; 4 extern char *arith_buf, *arith_startbuf; 5 int arith_wasoper; 6 #undef YY_INPUT 7 #define YY_INPUT(buf,result,max) \ 8 result = (*buf = *arith_buf++) ? 1 : YY_NULL; 9 %} 10 11 %% 12 [ \t\n] { ; } 13 [0-9]+ { arith_wasoper = 0; yylval = atol(yytext); return(ARITH_NUM); } 14 "(" { arith_wasoper = 1; return(ARITH_LPAREN); } 15 ")" { arith_wasoper = 0; return(ARITH_RPAREN); } 16 "||" { arith_wasoper = 1; return(ARITH_OR); } 17 "&&" { arith_wasoper = 1; return(ARITH_AND); } 18 "==" { arith_wasoper = 1; return(ARITH_EQ); } 19 ">" { arith_wasoper = 1; return(ARITH_GT); } 20 ">=" { arith_wasoper = 1; return(ARITH_GEQ); } 21 "<" { arith_wasoper = 1; return(ARITH_LT); } 22 "<=" { arith_wasoper = 1; return(ARITH_LEQ); } 23 "!=" { arith_wasoper = 1; return(ARITH_NEQ); } 24 "*" { arith_wasoper = 1; return(ARITH_MULT); } 25 "/" { arith_wasoper = 1; return(ARITH_DIV); } 26 "%" { arith_wasoper = 1; return(ARITH_REM); } 27 "+" { if (!arith_wasoper) { /* ignore unary plus */ 28 arith_wasoper = 1; 29 return(ARITH_ADD); 30 } 31 } 32 "-" { if (arith_wasoper) { 33 return(ARITH_UNARYMINUS); 34 } else { 35 arith_wasoper = 1; 36 return(ARITH_SUBT); 37 } 38 } 39 "!" { arith_wasoper = 1; return(ARITH_NOT); } 40 . { error("arith: syntax error: \"%s\"\n", arith_startbuf); } 41 %% 42 43 arith_lex_reset() { 44 YY_NEW_FILE; 45 } 46