PARSER_BEGIN(calc)
public class calc {
    public static void main(String args[]) throws ParseException {
        int result;
        calc parser = new calc(System.in);
        parser.complete_expression();
    }
}
PARSER_END(calc)

SKIP : 
{
        " "
}

TOKEN : 
{
        < INTEGER_LITERAL: (["0"-"9"])+ >
|       < PLUS:  "+"    >
|       < MINUS:  "-"   >
|       < MULTIPLY:  "*">
|       < DIVIDE:  "/"  >
|       < LPAREN: "("   >
|       < RPAREN: ")"   >
|       < EOL: "\n" >
}

void complete_expression():
{  }
{
   expression() <EOL> {  }
}

void expression():
{ }
{
   term() ((<PLUS> | <MINUS>)  term())* 
}

void term():
{ }
{
  factor() ( (<MULTIPLY> |  <DIVIDE>)  factor() )*
}

void factor():
{ }
{
    <MINUS> factor() 
|   <INTEGER_LITERAL> 
|   <LPAREN>  expression() <RPAREN> 
}