2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Bison file for the Eval grammar.
20 extern
void yyerror(char *s
);
31 } while
(c
== ' ' || c
== '\t');
38 sscanf
(text
+ 1, "%x", &yylval);
42 while
((*text
>= '0' && *text
<= '9') ||
43 (*text
>= 'a' && *text
<= 'f') ||
44 (*text
>= 'A' && *text
<= 'F'))
59 sscanf
(text
- 1, "%o", &yylval);
61 while
((*text
>= '0' && *text
<= '7'))
70 /* Skip 08... and 09... constructions and let them be ordinary
75 /* It was just the constant 0 */
89 sscanf
(text
, "%x", &yylval);
91 while
((*text
>= '0' && *text
<= '9') ||
92 (*text
>= 'a' && *text
<= 'f') ||
93 (*text
>= 'A' && *text
<= 'F'))
102 sscanf
(text
- 1, "%o", &yylval);
104 while
((*text
>= '0' && *text
<= '7'))
113 yyerror("Lexer error");
127 sscanf
(text
- 1, "%i", &yylval);
129 while
(isdigit
(*text
))
140 char *textCopy
= text
- 1;
142 while
(isalpha
(text
[i
]))
149 if
(strncasecmp
(textCopy
, "m", i
) == 0 ||
150 strncmp
(textCopy
, "mod", i
) == 0)
155 if
(strncmp
(textCopy
, "xor", i
) == 0 ||
156 strncasecmp
(textCopy
, "x", i
) == 0)
161 if
(strncmp
(textCopy
, "eqv", i
) == 0 ||
162 strncasecmp
(textCopy
, "e", i
) == 0)
167 if
(strncmp
(textCopy
, "lsh", i
) == 0 ||
168 strncasecmp
(textCopy
, "l", i
) == 0)
173 if
(strncmp
(textCopy
, "rsh", i
) == 0 ||
174 strncasecmp
(textCopy
, "r", i
) == 0)
179 yyerror("Lexing error");
186 int intPow
(int x
, int y
)
200 void yyerror(char *s
)
227 expr: NUM
{ $$
= $1; }
228 | expr
'l' expr
{ $$
= $1 << $3; }
229 | expr
'r' expr
{ $$
= $1 >> $3; }
230 | expr
'e' expr
{ $$
= ($1 & $3) |
(~
$1 & ~
$3); }
231 | expr
'|' expr
{ $$
= $1 |
$3; }
232 | expr
'x' expr
{ $$
= $1 ^
$3; }
233 | expr
'&' expr
{ $$
= $1 & $3; }
234 | expr
'+' expr
{ $$
= $1 + $3; }
235 | expr
'-' expr
{ $$
= $1 - $3; }
236 | expr
'*' expr
{ $$
= $1 * $3; }
237 | expr
'/' expr
{ $$
= $1 / $3; }
238 | expr
'%' expr
{ $$
= $1 %
$3; }
239 |
'-' expr %prec NEG
{ $$
= -$2; }
240 |
'~' expr
{ $$
= ~
$2; }
241 | expr
'^' expr
{ $$
= intPow
($1, $3); }
242 |
'(' expr
')' { $$
= $2; }
252 text
= "(1 lsh 4) mod 2";
256 printf
("Parse error\n");
260 printf
("The answer is %i\n", g_result
);