Commit c2c54afd authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Produce the function [terminal], which maps an integer code for a terminal

symbol to an [xsymbol].
parent 538a51d6
* Possibly re-implement the function [symbol] using a packed
int array (going through [terminal] or [nonterminal] later).
Re-implement [production_defs], etc.
* Generate default printers for terminal and nonterminal. * Generate default printers for terminal and nonterminal.
Define printers for productions and items, parameterized Define printers for productions and items, parameterized
over printers for terminal and nonterminal. over printers for terminal and nonterminal.
......
...@@ -746,6 +746,38 @@ let esymbol (symbol : Symbol.t) : expr = ...@@ -746,6 +746,38 @@ let esymbol (symbol : Symbol.t) : expr =
let xsymbol (symbol : Symbol.t) : expr = let xsymbol (symbol : Symbol.t) : expr =
EData (dataX, [ esymbol symbol ]) EData (dataX, [ esymbol symbol ])
(* ------------------------------------------------------------------------ *)
(* Produce a function that maps a terminal (represented as an integer code)
to its representation as an [xsymbol]. Include [error] but not [#], i.e.,
include all of the symbols which can appear in a production. *)
let terminal () =
assert Settings.inspection;
let t = "t" in
define (
"terminal",
EAnnot (
EFun ([ PVar t ],
EMatch (EVar t,
Terminal.mapx (fun tok ->
{ branchpat = pint (Terminal.t2i tok);
branchbody = xsymbol (Symbol.T tok) }
) @ [
{ branchpat = PWildcard;
branchbody =
EComment ("This terminal symbol does not exist.",
EApp (EVar "assert", [ efalse ])
) }
]
)
),
type2scheme (arrow tint txsymbol)
)
)
(* ------------------------------------------------------------------------ *)
(* Produce a function [symbol] that maps a state of type ['a lr1state] (* Produce a function [symbol] that maps a state of type ['a lr1state]
(represented as an integer value) to a value of type ['a symbol]. *) (represented as an integer value) to a value of type ['a symbol]. *)
...@@ -955,6 +987,10 @@ let program = ...@@ -955,6 +987,10 @@ let program =
lr1state_redef; lr1state_redef;
] @ ] @
SIInclude (MVar tables) :: (* only for [lhs] *) SIInclude (MVar tables) :: (* only for [lhs] *)
SIValDefs (false,
terminal() ::
[]
) ::
SIValDefs (false, SIValDefs (false,
incoming_symbol_def() :: incoming_symbol_def() ::
production_defs() :: production_defs() ::
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment