prec_inline.opp.exp 1.21 KB
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
Warning: you are using the standard library and/or the %inline keyword. We
recommend switching on --infer in order to avoid obscure type error messages.
%start main
%token RPAREN
%token LPAREN
%token <int> INT
%token EOL
%token PLUS
%token MINUS
%token TIMES
%token DIV
%left PLUS MINUS 
%left TIMES DIV 
%nonassoc UMINUS 
%type <int> main
%%

main:
| e = expr _2 = EOL
    {    ( e )}

expr:
| i0 = INT
    {let e =
  let i = i0 in
      ( i )
in
    ( e )}
| _10 = LPAREN e0 = expr _30 = RPAREN
    {let e =
  let _3 = _30 in
  let e = e0 in
  let _1 = _10 in
      ( e )
in
    ( e )}
| e10 = expr _20 = PLUS e20 = expr
    {let e =
  let e2 = e20 in
  let _2 = _20 in
  let e1 = e10 in
      ( e1 + e2 )
in
    ( e )}
| e10 = expr _20 = MINUS e20 = expr
    {let e =
  let e2 = e20 in
  let _2 = _20 in
  let e1 = e10 in
      ( e1 - e2 )
in
    ( e )}
| e10 = expr _20 = TIMES e20 = expr
    {let e =
  let e2 = e20 in
  let _2 = _20 in
  let e1 = e10 in
      ( e1 * e2 )
in
    ( e )}
| e10 = expr _20 = DIV e20 = expr
    {let e =
  let e2 = e20 in
  let _2 = _20 in
  let e1 = e10 in
      ( e1 / e2 )
in
    ( e )}
| _10 = MINUS e0 = expr %prec UMINUS
    {let e =
  let e = e0 in
  let _1 = _10 in
      ( - e )
in
    ( e )}

%%