| 1 |
(* llk-spec.sml |
| 2 |
* |
| 3 |
* COPYRIGHT (c) 2006 |
| 4 |
* John Reppy (http://www.cs.uchicago.edu/~jhr) |
| 5 |
* Aaron Turon (http://www.cs.uchicago.edu/~adrassi) |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Datatypes for grammar specification. |
| 9 |
* NOTE: individual modules are available that |
| 10 |
* manipulate the datatypes described in |
| 11 |
* this module. |
| 12 |
*) |
| 13 |
|
| 14 |
structure LLKSpec = |
| 15 |
struct |
| 16 |
|
| 17 |
type ty = string |
| 18 |
type span = Err.span |
| 19 |
|
| 20 |
type 'a info = { |
| 21 |
data : 'a |
| 22 |
} |
| 23 |
|
| 24 |
datatype token = T of { |
| 25 |
id : Int.int, (* globally unique ID *) |
| 26 |
name : Atom.atom, |
| 27 |
loc : span, |
| 28 |
ty : ty option, |
| 29 |
abbrev : Atom.atom option, |
| 30 |
keyword : bool, (* true if marked as a %keyword *) |
| 31 |
default : string option (* optional default argument for error repair *) |
| 32 |
} |
| 33 |
|
| 34 |
and nonterm = NT of { |
| 35 |
id : Int.int, (* globally unique ID *) |
| 36 |
name : Atom.atom, |
| 37 |
loc : span option ref, |
| 38 |
binding : nt_binding, |
| 39 |
prods : prod list ref, |
| 40 |
formals : Atom.atom list ref, |
| 41 |
isEBNF : bool, |
| 42 |
ty : ty option ref |
| 43 |
} |
| 44 |
|
| 45 |
and nt_binding = TOP | WITHIN of prod |
| 46 |
|
| 47 |
and prod = PROD of { |
| 48 |
id : Int.int, (* globally unique ID *) |
| 49 |
name : string, |
| 50 |
try : bool, |
| 51 |
lhs : nonterm, |
| 52 |
rhs : item list ref, (* ref for tying recursive knot: |
| 53 |
* subrules refer to their containing prod |
| 54 |
*) |
| 55 |
rhsBindings : (string * bool) list, |
| 56 |
pred : Action.action option, |
| 57 |
action : Action.action option, |
| 58 |
loc : span |
| 59 |
} |
| 60 |
|
| 61 |
and preitem |
| 62 |
= TOK of token |
| 63 |
(* nonterm * optional actual args *) |
| 64 |
| NONTERM of (nonterm * Action.action option) |
| 65 |
| CLOS of nonterm (* ( ... )* *) |
| 66 |
| POSCLOS of nonterm (* ( ... )+ *) |
| 67 |
| OPT of nonterm (* ( ... )? *) |
| 68 |
|
| 69 |
and item = ITEM of { |
| 70 |
id : Int.int, (* globally unique ID *) |
| 71 |
loc : span, |
| 72 |
sym : preitem |
| 73 |
} |
| 74 |
|
| 75 |
withtype sem_pred = Action.action |
| 76 |
|
| 77 |
datatype refcell |
| 78 |
= REFCELL of { |
| 79 |
name : string, |
| 80 |
ty : ty, |
| 81 |
initCode : Action.action, |
| 82 |
loc : span |
| 83 |
} |
| 84 |
|
| 85 |
datatype grammar = Grammar of { |
| 86 |
name : string, |
| 87 |
header : string option, |
| 88 |
defs : Action.action, (* user definitions (code) *) |
| 89 |
toks : token list, |
| 90 |
toksImport : Action.action option, (* optional token datatype *) |
| 91 |
changes : (token list * token list) list, |
| 92 |
nterms : nonterm list, |
| 93 |
prods : prod list, |
| 94 |
eof : token, |
| 95 |
sortedTops : nonterm list list, (* topologically sorted nonterms *) |
| 96 |
startnt : nonterm, |
| 97 |
entryPoints : nonterm list, |
| 98 |
refcells : refcell list |
| 99 |
} |
| 100 |
|
| 101 |
end |