mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-11 08:54:34 -05:00
3be22536df
git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5953 b45a01b8-16f6-495d-af2f-9b41ad6348cc
47 lines
800 B
Plaintext
47 lines
800 B
Plaintext
%{
|
|
#include <stdio.h>
|
|
int vars[26];
|
|
%}
|
|
|
|
Stmt = - e:Expr EOL { printf("%d\n", e); }
|
|
| ( !EOL . )* EOL { printf("error\n"); }
|
|
|
|
Expr = i:ID ASSIGN s:Sum { $$= vars[i]= s; }
|
|
| s:Sum { $$= s; }
|
|
|
|
Sum = l:Product
|
|
( PLUS r:Product { l += r; }
|
|
| MINUS r:Product { l -= r; }
|
|
)* { $$= l; }
|
|
|
|
Product = l:Value
|
|
( TIMES r:Value { l *= r; }
|
|
| DIVIDE r:Value { l /= r; }
|
|
)* { $$= l; }
|
|
|
|
Value = i:NUMBER { $$= atoi(yytext); }
|
|
| i:ID !ASSIGN { $$= vars[i]; }
|
|
| OPEN i:Expr CLOSE { $$= i; }
|
|
|
|
NUMBER = < [0-9]+ > - { $$= atoi(yytext); }
|
|
ID = < [a-z] > - { $$= yytext[0] - 'a'; }
|
|
ASSIGN = '=' -
|
|
PLUS = '+' -
|
|
MINUS = '-' -
|
|
TIMES = '*' -
|
|
DIVIDE = '/' -
|
|
OPEN = '(' -
|
|
CLOSE = ')' -
|
|
|
|
- = [ \t]*
|
|
EOL = '\n' | '\r\n' | '\r' | ';'
|
|
|
|
%%
|
|
|
|
int main()
|
|
{
|
|
while (yyparse());
|
|
|
|
return 0;
|
|
}
|