%{ #define isaddop(c) (c == '+') #define add(x, y) ((x) + (y)) #define addnum(x, y) ((x) * 10 + (y)) #define mul(x, y) ((x) * (y)) #define ismulop(c) (c == '*') #define islparen(c) (c == '(') #define isrparen(c) (c == ')') } %token digit int %token exp int %token num int %token epsilon int %token term int %entry exp exp = <| add "isaddop" term {$0}; term = <| mul "ismulop" num {$0}; num = <| addnum epsilon digit {$0} | "islparen" exp "isrparen" {$1}; epsilon = {0}; digit = "isdigit" {(int)($0-'0')}; %{int main(int argc, char* argv[]) { int val; char *s = (char *)malloc(80); s = gets(s); val = auentry(s); printf("%d", val); free(s); return 0; }}