-
Notifications
You must be signed in to change notification settings - Fork 9
Bootstrapping
The EBNF-like grammar parser of the Human Parser Generator (HPG), is generated by the HPG itself. To bootstrap this process and allow it to generate this parser, a grammar modelled by hand is used. It is located in generator/grammar.cs
in the AsModel
class, retrievable via the BNF
property.
This grammar is a direct implementation of the [EBNF-like syntax](HPG Grammar) in object-oriented structures and looks like this:
Not shown in the model are identifier
, string
and pattern
. These lowest-level, extracting entities (aka extractors), are not generated as classes, but as (static) prepared regular expressions, and used when needed.
The generator accepts a Grammar Model, which is basically an Abstract Syntax Tree (AST), and first transforms this, to a Parser Model. This model is a rewritten version of the Grammar Model and is designed to facilitate the emission of the actual Parser code.
The structure of the Generator (currently) looks like this:
An important aspect of this project is being self hosting and parsing the EBNF-like grammars with a parser that is generated by the parser generator itself. The following diagram shows what I mean by this; it shows the 9 steps to get from no parser to a fully generated second generation EBNF-like parser, that can be used to generate a parser for a different language, e.g. Pascal:
- Human encoding of EBNF to loadable C# code
- Importing of the Grammar and transformation to a Parser model
- Emission of Generation 1 EBNF Parser
- Using Generation 1 Parser, parsing of EBNF definition into Grammar parse tree
- Importing of the Grammar and transformation to a Parser model
- Emission of Generation 2 EBNF Parser
- Using Generation 2 Parser, parsing of Pascal definition into Grammar parse tree
- Importing of the Grammar and transformation to a Parser model
- Emission of Pascal Parser