Extensible Parser

From Gallium

Jump to: navigation, search

Contents

General Concepts:

  • Topdown parser LL(1+epsilon).
  • The parsing is done by evaluating the grammar.
  • The underlying parsing system is done with Stream Parsers.

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

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


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.

Involved Modules

 Sig.Grammar.{Static,Dynamic}
 open Camlp4.PreCast;;
 module Gram = MakeGram(Lexer);;
 EXTEND Gram  (* Gram : Sig.Grammar.Static *)
 ...
 END

Rules

 LIST1, LIST0
 i = INT ~~> Will call Token.extract_string 


What's changed in 3.10

  • abstract lexer + predefined implementation
  • abstract token + predefined implementation
  • abstract locations + predefined implementation
  • functorized (see grammar)
Personal tools
Espace privé