alpag.net manual
Introduction / Parser / Parser algorithm
< Grammar definition | Parsing example >

Parser algorithm

Once CFG grammar is correctly defined, the process of parser generation is fully automatic. Generation may fail if defined grammar is outside of LR(1) grammar class that Alpag can handle even if grammar itself is correct.

The process of defining CFG grammar that matches the language, is not ambiguous and fits the LR(1) grammar class can be long, complex and require many iterations. That’s why it is necessary to fully understand the way LR algorithm works.

LR parsers perform bottom-up parsing using a pushdown automaton (PDA). Pushdown automaton has two major components:

A state does not contain actions for all possible input symbols but only for symbols that are expected in that state. If next input symbol does not match any of symbols defined in current state an error is reported.

There are three types of actions. Two of these – shift, and reduce – are performed conditionally depending on next input terminal. Third type of action – goto – is performed for nonterminals being results of reductions.

Most publications prefer to treat goto as different type of action from shift and reduce and present two parser tables, one for shift/reduce and one for goto. In this manual and in report files generated by Alpag always single parser table is presented covering all shift/reduce/goto actions.

This chapter contains a minimum necessary to understand contents of parser tables presented further. A more detailed description of parser operation can be found in Parser operation chapter.

< Grammar definition | Parsing example >
Alpag Manual