%token <int> INT
%token PLUS MINUS TIMES DIV UMINUS
%token LPAREN RPAREN
%token EOL EOF

%left PLUS MINUS        /* lowest precedence */
%left TIMES DIV         /* medium precedence */
%nonassoc UMINUS        /* highest precedence */


%type <int> Expr

%start Main             /* the entry point */
%type <int> Main

%%

Main:
    Expr EOL                { $1 }
;
Expr:
    INT                     { $1 }
  | LPAREN Expr RPAREN      { $2 }
  | Expr PLUS Expr          { $1 + $3 }
  | Expr MINUS Expr         { $1 - $3 }
  | Expr TIMES Expr         { $1 * $3 }
  | Expr DIV Expr           { $1 div $3 }
  | UMINUS Expr             { ~ $2 }
;
