Extensible Parser
From Gallium
Contents |
[edit]
General Concepts:
- Topdown parser LL(1+epsilon).
- The parsing is done by evaluating the grammar.
- The underlying parsing system is done with Stream Parsers.
[edit]
Limitations
x | ::= | y | z |
y | ::= | A B | ... |
z | ::= | A C | ... |
How to make it work:
x | ::= | A B | A C |
This way, the two rules are factorized into something like: A x_rule_remaining, with x_rule_remaining ::= B | C
[edit]
The language of specifications:
The language specification is done by extending a grammar using the EXTEND syntax.
- The structure of grammars in short:
This is just to indicate the nested structure of Camlp4 grammars.
Grammars->Entries->Levels->Rules->Symbols
- An example: Arithmetic Example
[edit]
Static/Dynamic
There is one grammar instance per module in the static setting.
The dynamic setting is for a very advanced usage and will not be detailed here.
[edit]
Involved Modules
Sig.Grammar.{Static,Dynamic}
open Camlp4.PreCast;; module Gram = MakeGram(Lexer);;
EXTEND Gram (* Gram : Sig.Grammar.Static *) ... END
[edit]
Rules
LIST1, LIST0
i = INT ~~> Will call Token.extract_string
[edit]
What's changed in 3.10
- abstract lexer + predefined implementation
- abstract token + predefined implementation
- abstract locations + predefined implementation
- functorized (see grammar)