the leftmost derivation of input: ID + ID,
ie. E =>* ID + ID
E => E + T
E => T + T
E => ID + T
E => ID + ID
Parse Tree Sequence
E
|
E
/ \ E + T
|
E
/ \ E + T | | T ID | ID |
the rightmost derivation of input: ID + ID,
ie. E =>* ID + ID
E => E + T
E => E + ID
E => T + ID
E => ID + ID
Parse Tree Sequence
T T
|
E
/ \ E \ | T T | | ID + ID |
E
/ \ E \ | | T T | | ID + ID |
(typical to an if/then/else vs. if/then construct - I think in regards to closing constructs like "fi")
Case Input Successive # steps Total
1 | a | 1 | 1 |
2 | (a] | 1+1+3+2 | 7 |
3 | ((a]] | 1+1+7+1+7 | 17 |
4 | (((a]]] | 1+(1+17)+(1+17) | 37 |
Explanation for test case #2 (possible)
input - (a]
token - (
. try - a
n
. try - (S) y
token - a
. try - a
y
token - ]
.
should be - ) n
token (
. try - (S] y
token - a
. try - a
y
token - ]
.
should be - ] y
---------------------
7 total steps
For the input (a] with i ('s and i ]'s, the number
of steps is (5*2^i)-3, which expands very
quickly. Even with dynamic programming, the
algorithm is O(i^3).
Using this method will alleviate
the problems of going down wrong paths as in the first
algorithm presented.