Commit 0178ac11 authored by POTTIER Francois's avatar POTTIER Francois

Added the generation of the symbol GADT.

parent f3f7a1cc
......@@ -69,6 +69,16 @@ let nonterminalgadtdef grammar =
IITypeDecls [def]
]
let symbolgadtdef grammar =
let defs = SymbolType.symbolgadtdef grammar in
match defs with
| [] ->
[]
| def :: _ ->
[ IIComment "The indexed type of (terminal and nonterminal) symbols.";
IITypeDecls [def]
]
(* This is the interface of the generated parser -- only the part
that is specific of the table back-end. *)
......@@ -97,7 +107,8 @@ let table_interface grammar =
let interface grammar = [
IIFunctor (grammar.parameters,
tokentypedefs grammar @
nonterminalgadtdef grammar @ [
nonterminalgadtdef grammar @
symbolgadtdef grammar @ [
IIComment "This exception is raised by the monolithic API functions.";
IIExcDecls [ excdef ];
IIComment "The monolithic API.";
......
open IL
(* The symbol GADT is the union of the terminal and nonterminal GADTs. *)
(* The conventional name of the symbol GADT. *)
let tcsymbolgadt =
"symbol"
let tsymbolgadt a =
TypApp (tcsymbolgadt, [ a ])
(* The conventional name of the data constructors. *)
let dataT =
"T"
let dataN =
"N"
(* The definition of the symbol GADT. *)
let symbolgadtdef grammar =
(* This definition can be produced only if we are successfully able
to construct the nonterminal GADT. *)
match NonterminalType.nonterminalgadtdef grammar with
| [] ->
[]
| _ :: _ ->
let a = "a" in
let datadefs =
{
dataname = dataT;
datavalparams = [ TokenType.ttokengadt (TypVar a) ];
datatypeparams = Some [ TypVar a ]
} ::
{
dataname = dataN;
datavalparams = [ NonterminalType.tnonterminalgadt (TypVar a) ];
datatypeparams = Some [ TypVar a ]
} ::
[]
in
[{
typename = tcsymbolgadt;
typeparams = [ a ];
typerhs = TDefSum datadefs;
typeconstraint = None
}]
(* The symbol GADT is the union of the terminal and nonterminal GADTs. *)
val tsymbolgadt: IL.typ -> IL.typ
(* The definition of the symbol GADT. This definition can be produced only if
we are successfully able to construct the nonterminal GADT first. *)
val symbolgadtdef: UnparameterizedSyntax.grammar -> IL.typedef list
......@@ -5,6 +5,7 @@ open Interface
open Printf
open TokenType
open NonterminalType
open SymbolType
open CodePieces
module Run (T : sig end) = struct
......@@ -747,20 +748,24 @@ let api : IL.valdef list =
(* Let's put everything together. *)
let grammar =
Front.grammar
let program = {
paramdefs =
Front.grammar.UnparameterizedSyntax.parameters;
grammar.UnparameterizedSyntax.parameters;
prologue =
Front.grammar.UnparameterizedSyntax.preludes;
grammar.UnparameterizedSyntax.preludes;
excdefs =
[ excdef ];
typedefs =
tokentypedefs Front.grammar @
nonterminalgadtdef Front.grammar @
tokentypedefs grammar @
nonterminalgadtdef grammar @
symbolgadtdef grammar @
[ tokendef1 ];
nonrecvaldefs =
......@@ -773,7 +778,7 @@ let program = {
api;
postlogue =
Front.grammar.UnparameterizedSyntax.postludes
grammar.UnparameterizedSyntax.postludes
}
......
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