Skip to content

Commit

Permalink
Update examples and other cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jun 13, 2020
1 parent 2f48972 commit c4a9ca4
Show file tree
Hide file tree
Showing 15 changed files with 1,570 additions and 853 deletions.
4 changes: 2 additions & 2 deletions examples/ebnf-ll1-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ This example uses the EBNF grammar from {file:/etc/ebnf.ebnf} to generate {file:

The first step is defining regular expressions for terminals used within the grammar. The table generation process in {EBNF::LL1#build_tables} is not yet capable of automatically generating regular expressions for terminal productions, so they must be defined by hand. For the EBNF grammar, this is done in {file:terminals}.

The {file:parser} is implemented using the {EBNFLL1Parser} class, which includes {EBNF::LL1::Parser}, {EBNFParserMeta} and {EBNFLL1ParserTerminals}.
The {file:parser} is implemented using the {EBNFLL1Parser} class, which includes {EBNF::LL1::Parser} and {EBNFParserMeta}.

### Parser basics
The parser operates using the `BRANCH`, `FIRST`, `FOLLOW`, `START`, and `PASS` definitions from {file:meta}. Basically, the starting production has identified a possible set of starting tokens and it branches to different non-terminal productions when it finds a matching token. Tokens are derived from terminal rules defined in the grammar or contained inline through non-terminal rule definitions. Tokens are either strings, which must be matched exactly, or symbols, which identify a regular expression used to match the terminal and yield a token. The association between terminal symbols and their regular expressions along with processing rules to invoke when they are identified are described in [Terminal definitions](#Terminal_definitions).
Expand All @@ -100,7 +100,7 @@ The {file:parser} uses a DSL to specify `terminals` and `productions` associated
input[:terminal] = token.value.to_sym
end

In this terminal definition, the SYMBOL terminal is recognized using the `SYMBOL` regular expression from {EBNFParserTerminals::SYMBOL}. When found, the value of the symbol is added to the `input` stack for use by non-terminal productions which include it.
In this terminal definition, the SYMBOL terminal is recognized using the `SYMBOL` regular expression from {EBNF::Terminals::SYMBOL}. When found, the value of the symbol is added to the `input` stack for use by non-terminal productions which include it.

### Production definitions
During parsing, when a non-terminal production is identified, it attempts to invoke an associated `start_production` block. Typically there is nothing to do at the start of a production, so these are often left out. However, at times, it is necessary to prepare the production stack with information. For example, consider the _start production_ for `_alt_1` (a sub-production of `alt`).
Expand Down
4 changes: 2 additions & 2 deletions examples/ebnf-ll1-parser/Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
task default: [:meta, :doc]

desc 'Build first, follow and branch tables'
task meta: "meta.rb"

task default: :meta

file "meta.rb" => "../../etc/ebnf.ebnf" do |t|
sh %{
ebnf --ll1 ebnf --format rb \
Expand Down

0 comments on commit c4a9ca4

Please sign in to comment.