foo.opp.exp 429 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
%start exp
%token <int> INT
%token PLUS
%token TIMES
%left PLUS 
%left TIMES 
%type <int> exp
%%

exp:
| lhs = exp TIMES rhs = exp
    {
let op =                   ( fun x y -> x * y ) in
                                    ( op lhs rhs )
}
| lhs = exp PLUS rhs = exp
    {
let op =                  ( fun x y -> x + y ) in
                                    ( op lhs rhs )
}
| x = INT
    {
                     ( x )
}

%%