Alpag converts generated grammar into pushdown automaton. During parser development it is usually necessary to understand and inspect generated automaton, especially if does not behave as expected. Alpag can generate report file with description of automaton structure for easy browsing.
To get the report run Alpag once again, this time with –pr (parser report) switch:
This time Alpag generates also myParser.pr.txt. The file contains both input grammar, as well as generated pushdown automaton.
Format of the file can be further customized using additional –pro <options> switch.
Generated file contains a number of sections. First come sections with summary of input grammar:
The automaton section contains several subsections. The most important is the list of automaton states and actions defined in each state:
List of actions in each state should be self-explanatory. Note the use of #n notation for state numbers and @n for production numbers.
Itemsets show which elements of source grammar participated in creation of particular state. The dot '.' symbol marks the exact point within production which corresponds to given state. If state corresponds to several places in various productions it will have multiple itemset rows.
Analysis of parser automaton is much more complicated than that of lexer automaton. Parser automaton features additional data structure, a stack, which changes during parser operation. In order to analyze parser's automaton operation one must also consider current situation on the stack. This is especially important when reduction (reduce by) action is performed. Next state after reduction is taken form the stack and cannot be deduced from parser automaton tables. This means that static analysis of parser automaton alone is not sufficient to foresee its behavior.
Using the –prx option you can also generate XML report. This will produce one more file:
XML report can be used to export generated parser tables to third party tools, or to create browsable HTML version of the report. Use XSL template parser.xsl included with Alpag, to generate HTML version of the report. You must use third party XSL translator (like msxsl) to perform the task. When using msxsl the HTML report can be generated with command:
Generated HTML file is similar in structure to text file generated with –pr option with a few improvements. It includes an emulator of LR(1) parser. The emulator enables editing and tracking parser stack. Using a simple point and click interface one can perform simulated walk over the automaton feeding it with sample input. The emulator does not support more advanced parser features like error recovery. It can be used only to verify simple scenarios.