To design an online Lexical Analyzer simulator to derive leftmost derivation tree and rightmost derivation tree from a given grammar for a goal string.
The process of deriving a string is called as derivation. The geometrical representation of a derivation is called as a parse tree or derivation tree.
The process of deriving a string by expanding the leftmost non-terminal at each step is called as leftmost derivation.
The process of deriving a string by expanding the rightmost non-terminal at each step is called as rightmost derivation.
Let's consider a Grammar:
S → aB / bA
S → aS / bAA / a
B → bS / aBB / b
Let us consider a string
w = aaabbabbba
S → aB
→ aaBB (Using B → aBB)
→ aaaBBB (Using B → aBB)
→ aaabBB (Using B → b)
→ aaabbB (Using B → b)
→ aaabbaBB (Using B → aBB)
→ aaabbabB (Using B → b)
→ aaabbabbS (Using B → bS)
→ aaabbabbbA (Using S → bA)
→ aaabbabbba (Using A → a)
S → aB
→ aaBB (Using B → aBB)
→ aaBaBB (Using B → aBB)
→ aaBaBbS (Using B → bS)
→ aaBaBbbA (Using S → bA)
→ aaBaBbba (Using A → a)
→ aaBabbba (Using B → b)
→ aaaBBabbba (Using B → aBB)
→ aaaBbabbba (Using B → b)
→ aaabbabbba (Using B → b)
Click on this Link to go to the simulator.
We wrote the online simulator using HTML, CSS, JavaScript and successfully implemented the concept of left and right derivation tree.
If the grammar is ambiguous i.e., if there exist more than one left or right derivations for the same string. For an ambiguous grammar left and right derivation tree of a given grammar may yield different results.