Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Bootstrapping

Christophe VG edited this page Mar 6, 2017 · 1 revision

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:

Grammar Model

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.

Generator

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:

Parser Model

Being Self Hosting

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:

Bootstrapping HPG

  1. Human encoding of EBNF to loadable C# code
  2. Importing of the Grammar and transformation to a Parser model
  3. Emission of Generation 1 EBNF Parser
  4. Using Generation 1 Parser, parsing of EBNF definition into Grammar parse tree
  5. Importing of the Grammar and transformation to a Parser model
  6. Emission of Generation 2 EBNF Parser
  7. Using Generation 2 Parser, parsing of Pascal definition into Grammar parse tree
  8. Importing of the Grammar and transformation to a Parser model
  9. Emission of Pascal Parser
Clone this wiki locally