Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <stdio.h>
- #include <stdlib.h>
- #define YYSTYPE long long
- long long Result = 0;
- %}
- %token INT EOL
- %left '+' '*'
- %start File
- %%
- File: | File Line
- Line: Expression EOL { Result += $1; }
- Expression:
- INT { $$ = $1; }
- | '(' Expression ')' { $$ = $2; }
- | Expression '+' Expression { $$ = $1 + $3; }
- | Expression '*' Expression { $$ = $1 * $3; }
- ;
- %%
- int yyerror( char *s ) {
- printf( "Error: %s\n", s );
- }
- int main() {
- yyparse();
- printf( "%lld\n", Result );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement