2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Bison file for the Eval grammar.
20 static void yyerror(char *s
);
21 static int intPow
(int x
, int y
);
48 expr: NUM
{ $$
= $1; }
49 | expr
'l' expr
{ $$
= $1 << $3; }
50 | expr
'r' expr
{ $$
= $1 >> $3; }
51 | expr
'e' expr
{ $$
= ($1 & $3) |
(~
$1 & ~
$3); }
52 | expr
'|' expr
{ $$
= $1 |
$3; }
53 | expr
'x' expr
{ $$
= $1 ^
$3; }
54 | expr
'&' expr
{ $$
= $1 & $3; }
55 | expr
'+' expr
{ $$
= $1 + $3; }
56 | expr
'-' expr
{ $$
= $1 - $3; }
57 | expr
'*' expr
{ $$
= $1 * $3; }
58 | expr
'/' expr
{ $$
= $1 / $3; }
59 | expr
'%' expr
{ $$
= $1 %
$3; }
60 |
'-' expr %prec NEG
{ $$
= -$2; }
61 |
'~' expr
{ $$
= ~
$2; }
62 | expr
'^' expr
{ $$
= intPow
($1, $3); }
63 |
'(' expr
')' { $$
= $2; }
75 } while
(c
== ' ' || c
== '\t');
82 sscanf
(text
+ 1, "%x", &yylval);
86 while
((*text
>= '0' && *text
<= '9') ||
87 (*text
>= 'a' && *text
<= 'f') ||
88 (*text
>= 'A' && *text
<= 'F'))
103 sscanf
(text
- 1, "%o", &yylval);
105 while
((*text
>= '0' && *text
<= '7'))
114 /* Skip 08... and 09... constructions and let them be ordinary
119 /* It was just the constant 0 */
133 sscanf
(text
, "%x", &yylval);
135 while
((*text
>= '0' && *text
<= '9') ||
136 (*text
>= 'a' && *text
<= 'f') ||
137 (*text
>= 'A' && *text
<= 'F'))
146 sscanf
(text
- 1, "%o", &yylval);
148 while
((*text
>= '0' && *text
<= '7'))
157 yyerror("Lexer error");
171 sscanf
(text
- 1, "%i", &yylval);
173 while
(isdigit
(*text
))
184 char *textCopy
= text
- 1;
186 while
(isalpha
(text
[i
]))
193 if
(strncasecmp
(textCopy
, "m", i
) == 0 ||
194 strncmp
(textCopy
, "mod", i
) == 0)
199 if
(strncmp
(textCopy
, "xor", i
) == 0 ||
200 strncasecmp
(textCopy
, "x", i
) == 0)
205 if
(strncmp
(textCopy
, "eqv", i
) == 0 ||
206 strncasecmp
(textCopy
, "e", i
) == 0)
211 if
(strncmp
(textCopy
, "lsh", i
) == 0 ||
212 strncasecmp
(textCopy
, "l", i
) == 0)
217 if
(strncmp
(textCopy
, "rsh", i
) == 0 ||
218 strncasecmp
(textCopy
, "r", i
) == 0)
223 yyerror("Lexing error");
230 static int intPow
(int x
, int y
)
244 static void yyerror(char *s
)
255 text
= "(1 lsh 4) mod 2";
259 printf
("Parse error\n");
263 printf
("The answer is %i\n", g_result
);