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
28 lines
663 B
Plaintext
28 lines
663 B
Plaintext
# Grammar
|
|
|
|
Expr <- SPACE Sum EOL { printf("%d\n", pop()); }
|
|
/ (!EOL .)* EOL { printf("error\n"); }
|
|
|
|
Sum <- Product ( PLUS Product { int r= pop(), l= pop(); push(l + r); }
|
|
/ MINUS Product { int r= pop(), l= pop(); push(l - r); }
|
|
)*
|
|
|
|
Product <- Value ( TIMES Value { int r= pop(), l= pop(); push(l * r); }
|
|
/ DIVIDE Value { int r= pop(), l= pop(); push(l / r); }
|
|
)*
|
|
|
|
Value <- NUMBER { push(atoi(yytext)); }
|
|
/ OPEN Sum CLOSE
|
|
|
|
# Lexemes
|
|
|
|
NUMBER <- < [0-9]+ > SPACE
|
|
PLUS <- '+' SPACE
|
|
MINUS <- '-' SPACE
|
|
TIMES <- '*' SPACE
|
|
DIVIDE <- '/' SPACE
|
|
OPEN <- '(' SPACE
|
|
CLOSE <- ')' SPACE
|
|
SPACE <- [ \t]*
|
|
EOL <- '\n' / '\r\n' / '\r'
|