-
Notifications
You must be signed in to change notification settings - Fork 2
AFParser Creation Example
Ronald Franco edited this page Dec 27, 2018
·
3 revisions
The below AFG has two productions that counts the first x
number of a’s.
// Define nonterminal A, token ‘a’, and flow variables
Parser<int> A;
int x = 0, y = 0;
// Inline Grammar Specification of 2 productions
A>>x = Token(‘a’) & A>>y & [&]{ x = y + 1; } | Token(‘a’) & [&]{ x = 1; };
The AFG would result in the creation of 7 BaseParser objects and 2 Parser objects. They are as follows:
Parser #1: DEF node for A>>x
BaseParser #1: TOK node for Token(’a’)
Parser #2: NON node for A>>y
BaseParser #2: ACT node for [&]{ x = y + 1; }
BaseParser #3: SEQ node for Token(‘a’) & A>>y & [&]{ x = y + 1; }
BaseParser #4: TOK node for Token(’a’)
BaseParser #5: ACT node for [&]{ x = 1; }
BaseParser #6: SEQ node for Token(’a’) & [&]{ x = 1; }
BaseParser #7: ALT node for Token(‘a’) & A>>y & [&]{ x = y + 1; }
and Token(’a’) & [&]{ x = 1; }
An illustration of the data structure generated by this production is given here: