#pragma once #ifndef PARSODUS_PARSER_{{name}}_H #define PARSODUS_PARSER_{{name}}_H #include template class {{name}} { public: {{name}}() {} virtual ~{{name}}() {} /** * Parse it */ Value parse(); protected: /** * Represents the type of the symbol (both terminals and nonterminals) */ enum Symbol { {{#symbols}} {{symbol}}, {{/symbols}} } /** * A token, consisting of a Symbol type (should be a terminal) and a Value */ struct Token { Symbol symbol, Value value }; /****************************************** * Functions to be supplied by the user * ******************************************/ /** * Get the next token from the lexer */ virtual Token lex() = 0; /** * Apply a reduction (a grammar rule in reverse) */ {{#rules}} {{#name}}virtual Value reduce_{{name}}(const std::deque& subparts) = 0;{{/name}} {{^name}}virtual Value reduce_{{index}}(const std::deque& subparts) = 0;{{/name}} {{/rules}} private: }; // Not a static member because the table should not be replicated for different instantiations of the parser extern const std::uint64_t {{name}}___Table[%(num_states)][%(num_symbols)]; /*************************** * Parser implementation * ***************************/ template Value {{name}}::parse() { //TODO } #endif /* PARSODUS_PARSER_{{name}}_H */