This is the original grammar that is used in the example parser. It is shown in the Java CUP specification format that is required to use this particular visualization tool. Visual YACC in Java uses Java CUP and JLEX as the parser and lexer, respectively.

Back to Visual YACC page or HOME page

terminal PLUS, MINUS, TIMES, DIVIDE;
terminal Integer NUMBER;

non terminal statement, expr_part;
non terminal Integer expr, term, factor;

statement ::= statement expr_part
| expr_part
;

expr_part ::= expr:e ;

expr ::= expr:e1 PLUS term:e2
{:
RESULT = new Integer(e1.intValue() + e2.intValue());
:}
|
term:t
{:
RESULT = new Integer(e1.intValue() + e2.intValue());
:}
term:t
{:
RESULT = t;
:}
;

term ::= term:e1 TIMES factor:e2
{:
RESULT = new Integer(e1.intValue() * e2.intValue());
:}
|
term:e1 DIVIDE factor:e2
{:
RESULT = new Integer(e1.intValue() / e2.intValue());
:}
|
factor:f
{:
RESULT = f;
:}
;

factor ::= NUMBER:n
{:
RESULT = n;
:}
;