Grammar

This is the current LL(1) grammar that the parse is suitable for:

Exp  -> Int Oper
Oper -> * Exp |
/ Exp |
+ Exp |
- Exp |
epsilon
Int -> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

First and Follow Functions

First:Follow:

Parser Table

*/+-01. . .9$
ExpN/AN/AN/AN/AExp -> Int OperExp -> Int Oper. . .Exp -> Int OperN/A
OperOper -> * Int OperOper -> / Int OperOper -> + Int OperOper -> - Int OperN/AN/A. . .N/AOper -> epsilon
IntN/AN/AN/AN/AInt -> 0Int -> 1. . .Int -> 9N/A

Click *here* to read more about parsers and grammars.

Contents

Derive token

This is how a current nonterminal symbol found in an expression will be derived based on the next terminal (lookahead).

Scenarios

Non terminal Lookahead Derivation
EXP 0 EXP -> INT OPER
EXP 1 EXP -> INT OPER
EXP 2 EXP -> INT OPER
EXP 3 EXP -> INT OPER
EXP 4 EXP -> INT OPER
EXP 5 EXP -> INT OPER
EXP 6 EXP -> INT OPER
EXP 7 EXP -> INT OPER
EXP 8 EXP -> INT OPER
EXP 9 EXP -> INT OPER
OPER * OPER -> * INT OPER
OPER / OPER -> / INT OPER
OPER + OPER -> + INT OPER
OPER - OPER -> - INT OPER
OPER EOF OPER -> epsilon
INT 0 INT -> 0
INT 1 INT -> 1
INT 2 INT -> 2
INT 3 INT -> 3
INT 4 INT -> 4
INT 5 INT -> 5
INT 6 INT -> 6
INT 7 INT -> 7
INT 8 INT -> 8
INT 9 INT -> 9

Specification

Assert that derivation for non terminal EXP and lookahead 0 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 1 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 2 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 3 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 4 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 5 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 6 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 7 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 8 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal EXP and lookahead 9 is "EXP -> INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal OPER and lookahead "*" is "OPER -> * INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal OPER and lookahead "/" is "OPER -> / INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal OPER and lookahead "+" is "OPER -> + INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal OPER and lookahead "-" is "OPER -> - INT OPER"

Test results:

Test passed

Specification

Assert that derivation for non terminal OPER and lookahead EOF is "OPER -> epsilon"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 0 is "INT -> 0"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 1 is "INT -> 1"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 2 is "INT -> 2"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 3 is "INT -> 3"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 4 is "INT -> 4"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 5 is "INT -> 5"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 6 is "INT -> 6"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 7 is "INT -> 7"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 8 is "INT -> 8"

Test results:

Test passed

Specification

Assert that derivation for non terminal INT and lookahead 9 is "INT -> 9"

Test results:

Test passed

Invalid derivation

Specification

ADD
Try
Parser table action to take NTS_ EXP TS_0
Fail
Catch illegal state exception e
Assert equals "unknown operation for: " TS_0 e get message

Test results:

Test passed