/media/sda-magnetic/david/Dok-15-2023-11-27/fernuni-hagen/cs-i-ii/fsm/fsm/lex-yacc-bash-etc/yacc01.cc


%{
#include <ctype.h>
#include <stdio.h>
%}
%token NUMBER
%%
lines           : lines expr '\n' {printf("%d\n", $2); }
                | lines '\n'
                |
                ;
expr            : expr '+' term { $$ = $1 + $3; }
                | expr '-' term { $$ = $1 - $3; }
                | term
                ;
term            : term '*' factor { $$ = $1 * $3; }
                | term '/' factor { $$ = $1 * $3; }
                | factor
                ;
factor          : '(' expr ')' { $$ = $2; }
                | NUMBER
                ;
%%
int yylex() {
    int c;
    c = getchar();
    if (isdigit(c)) {
        ungetc(c, stdin); 
        scanf("%d", &yylval);
        return NUMBER;
    }
    return c;
}