date and time created 92/06/23 18:44:57 by marc
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Wed, 24 Jun 1992 09:44:57 +0000 (01:44 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Wed, 24 Jun 1992 09:44:57 +0000 (01:44 -0800)
SCCS-vsn: bin/sh/arith_lex.l 5.1

usr/src/bin/sh/arith_lex.l [new file with mode: 0644]

diff --git a/usr/src/bin/sh/arith_lex.l b/usr/src/bin/sh/arith_lex.l
new file mode 100644 (file)
index 0000000..a7f1686
--- /dev/null
@@ -0,0 +1,45 @@
+%{
+#include "y.tab.h"
+extern yylval;
+extern char *arith_buf, *arith_startbuf;
+int arith_wasoper;
+#undef YY_INPUT
+#define YY_INPUT(buf,result,max) \
+       result = (*buf = *arith_buf++) ? 1 : YY_NULL;
+%}
+
+%%
+[ \t\n]        { ; }
+[0-9]+ { arith_wasoper = 0; yylval = atol(yytext); return(ARITH_NUM); }
+"("    { arith_wasoper = 1; return(ARITH_LPAREN); }
+")"    { arith_wasoper = 0; return(ARITH_RPAREN); }
+"||"   { arith_wasoper = 1; return(ARITH_OR); }
+"&&"   { arith_wasoper = 1; return(ARITH_AND); }
+"=="   { arith_wasoper = 1; return(ARITH_EQ); }
+">"    { arith_wasoper = 1; return(ARITH_GT); }
+">="   { arith_wasoper = 1; return(ARITH_GEQ); }
+"<"    { arith_wasoper = 1; return(ARITH_LT); }
+"<="   { arith_wasoper = 1; return(ARITH_LEQ); }
+"!="   { arith_wasoper = 1; return(ARITH_NEQ); }
+"*"    { arith_wasoper = 1; return(ARITH_MULT); }
+"/"    { arith_wasoper = 1; return(ARITH_DIV); }
+"%"    { arith_wasoper = 1; return(ARITH_REM); }
+"+"    { if (!arith_wasoper) { /* ignore unary plus */
+               arith_wasoper = 1; 
+               return(ARITH_ADD);
+        } 
+       }       
+"-"    { if (arith_wasoper) {
+               return(ARITH_UNARYMINUS);
+         } else {
+               arith_wasoper = 1;
+               return(ARITH_SUBT);
+         }
+       }
+"!"    { arith_wasoper = 1; return(ARITH_NOT); }
+.      { error("arith: syntax error: \"%s\"\n", arith_startbuf); }
+%%
+
+arith_lex_reset() {
+       YY_NEW_FILE;
+}