![]() |
Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
|
Classes for parsing LL(1) context-free grammars.

Classes | |
| class | elementa::parsing::LL1Parser |
| A parser for an LL(1) grammar. More... | |
| class elementa::parsing::LL1Parser |
A parser for an LL(1) grammar.
If constructing an AST, the resulting tree will produce the original input if going through leaf vertices in depth-first fashion. Observers used in this class may contain the syntax-guided code equivalent to the one written in a Bison-like parser inside each rule: it executes in the same order as the rule is being built.
Definition at line 51 of file ll1parsing.h.


Public Member Functions | |
Constructors | |
| LL1Parser (const CFGrammar &gr, const CFGrammar::LL1Table &table, Lexer &lexer, const TransfTokenId &transftid=[](Token &) ->void{}) | |
| Constructor for a grammar. More... | |
| ~LL1Parser (void)=default | |
| Destructor. | |
Pure virtual methods in Parser class | |
| Parser::Result | parseStep (Parser::Observer &obs) |
| Do a parsing step. More... | |
| void | reset (void) |
| Must prepare to begin a new parsing (not needed after construction). More... | |
| void | printStatus (elementa::base::OutSerCh &chout) const |
| Must serialize current status in text format through CHOUT, for debug. More... | |
Methods | |
| const CFGrammar & | grammar (void) const noexcept |
| Return a reference to the internal grammar. More... | |
| Lexer & | lexer (void) const noexcept |
| Return a reference to the internal lexer. More... | |
| void | parse (Observer &obs) |
| Parse the input until a complete sentence of the language is read. More... | |
Types, consts, etc. | |
| ELE_CLASS_ENUM (Result, kFinished, kMoreSteps, kNotInTable, kMismatch) | |
| Result codes after a parsing step. | |
| using | TransfTokenId = std::function< void(Token &) > |
| Transformation of TokenId into CFGrammar::CodeElement. More... | |
|
inherited |
Transformation of TokenId into CFGrammar::CodeElement.
This comes handy to change the lexer token ids into grammar code elements, in case that the lexers do not work with the latter but with the former.
|
inline |
Constructor for a grammar.
This takes references to GR and to TABLE and store them internally, thus they must exist beyond this parser, since the parser does not take their ownership. The integrity of GR and its correspondence to TABLE are not checked.
Definition at line 63 of file ll1parsing.h.
|
virtual |
Do a parsing step.
This method calls getToken() from the lexer when needed. If the lexer produces a null token, do as if it would produced kCodeEnd; otherwise, call transftid() for transforming the code of the token into the grammar code needed.
Implements elementa::parsing::Parser.
|
virtual |
Must prepare to begin a new parsing (not needed after construction).
Implements elementa::parsing::Parser.
|
virtual |
Must serialize current status in text format through CHOUT, for debug.
Implements elementa::parsing::Parser.
|
inlinenoexceptinherited |
|
inlinenoexceptinherited |
|
inherited |
Parse the input until a complete sentence of the language is read.
The resulting top-down sequence of rules is passed sequentially to the observer methods in OBS.