/media/sda-magnetic/david/Extern-Magnetic-2022-06-29/Extern01/Dokumente-2020-11-16/disk10-ab-2020-01-10/02-debian-pc2-work/informatik/bash-programming/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;
}