xref: /original-bsd/bin/sh/arith_lex.l (revision ebf693c1)
1 %{
2 /*-
3  * Copyright (c) 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Kenneth Almquist.
8  *
9  * %sccs.include.redist.c%
10  */
11 
12 #ifndef lint
13 static char sccsid[] = "@(#)arith_lex.l	8.1 (Berkeley) 05/31/93";
14 #endif /* not lint */
15 
16 #include "y.tab.h"
17 
18 extern yylval;
19 extern char *arith_buf, *arith_startbuf;
20 int arith_wasoper;
21 #undef YY_INPUT
22 #define YY_INPUT(buf,result,max) \
23 	result = (*buf = *arith_buf++) ? 1 : YY_NULL;
24 %}
25 
26 %%
27 [ \t\n]	{ ; }
28 [0-9]+	{ arith_wasoper = 0; yylval = atol(yytext); return(ARITH_NUM); }
29 "("	{ arith_wasoper = 1; return(ARITH_LPAREN); }
30 ")"	{ arith_wasoper = 0; return(ARITH_RPAREN); }
31 "||"	{ arith_wasoper = 1; return(ARITH_OR); }
32 "&&"	{ arith_wasoper = 1; return(ARITH_AND); }
33 "=="	{ arith_wasoper = 1; return(ARITH_EQ); }
34 ">"	{ arith_wasoper = 1; return(ARITH_GT); }
35 ">="	{ arith_wasoper = 1; return(ARITH_GEQ); }
36 "<"	{ arith_wasoper = 1; return(ARITH_LT); }
37 "<="	{ arith_wasoper = 1; return(ARITH_LEQ); }
38 "!="	{ arith_wasoper = 1; return(ARITH_NEQ); }
39 "*"	{ arith_wasoper = 1; return(ARITH_MULT); }
40 "/"	{ arith_wasoper = 1; return(ARITH_DIV); }
41 "%"	{ arith_wasoper = 1; return(ARITH_REM); }
42 "+"	{ if (!arith_wasoper) {	/* ignore unary plus */
43 		arith_wasoper = 1;
44 		return(ARITH_ADD);
45 	 }
46 	}
47 "-"	{ if (arith_wasoper) {
48 		return(ARITH_UNARYMINUS);
49 	  } else {
50 		arith_wasoper = 1;
51 		return(ARITH_SUBT);
52 	  }
53 	}
54 "!"	{ arith_wasoper = 1; return(ARITH_NOT); }
55 .	{ error("arith: syntax error: \"%s\"\n", arith_startbuf); }
56 %%
57 
58 arith_lex_reset() {
59 	YY_NEW_FILE;
60 }
61