Skip to content

Commit 37e7bd7

Browse files
committed
[spectec] Specify IL subsets
1 parent f9c743a commit 37e7bd7

2 files changed

Lines changed: 44 additions & 28 deletions

File tree

spectec/doc/semantics/il/1-syntax.spectec

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
;; IL Subsets
2+
3+
def $with_higher_order : bool
4+
def $with_polymorphic_types : bool
5+
def $with_dependent_types : bool
6+
def $with_family_types : bool
7+
def $with_grammars : bool
8+
def $with_noncomputational : bool ;; semantic restriction
9+
10+
111
;; Identifiers
212

313
syntax id = text
@@ -23,7 +33,10 @@ syntax typ =
2333
| TUP typbind* ;; (id : typ , ... , id : typ)
2434
| ITER typ iter ;; typ iter
2535
| VAR id arg* ;; typid(arg*)
36+
-- if arg* = eps \/ $with_polymorphic_types \/ $with_dependent_types
2637
| MATCH id arg* WITH inst* ;; `match` typid(arg*) `with` inst*
38+
-- if arg* = eps \/ $with_polymorphic_types \/ $with_dependent_types
39+
-- if |inst*| <= 1 \/ $with_family_types
2740

2841
syntax deftyp =
2942
| ALIAS typ
@@ -132,62 +145,65 @@ syntax expfield = atom `= exp
132145
syntax exppull = id `: typ `<- exp
133146

134147
syntax path =
135-
| ROOT ;;
136-
| THE path ;; path!
137-
| IDX path exp ;; path[ exp ]
138-
| SLICE path exp exp ;; path[ exp : exp ]
139-
| DOT path atom ;; path.atom
140-
| PROJ path mixop ;; path!mixop
148+
| ROOT ;;
149+
| THE path ;; path!
150+
| IDX path exp ;; path[ exp ]
151+
| SLICE path exp exp ;; path[ exp : exp ]
152+
| DOT path atom ;; path.atom
153+
| PROJ path mixop ;; path!mixop
141154

142155

143156
;; Grammars
144157

145-
syntax sym =
146-
| VAR id arg* ;; gramid( arg* )
147-
| NUM nat ;; num
148-
| TEXT text ;; text
149-
| SEQ sym* ;; sym*
150-
| ALT sym* ;; sym `|` sym
151-
| RANGE sym sym ;; sym `|` `...` `|` sym
152-
| ITER sym iter exppull* ;; sym iter{ exppull* }
153-
| ATTR exp sym ;; exp `:` sym
158+
syntax sym = ;; only used if $with_grammars
159+
| VAR id arg* ;; gramid( arg* )
160+
-- if arg* = eps \/ $with_polymorphic_types \/ $with_dependent_types
161+
| NUM nat ;; num
162+
| TEXT text ;; text
163+
| SEQ sym* ;; sym*
164+
| ALT sym* ;; sym `|` sym
165+
| RANGE sym sym ;; sym `|` `...` `|` sym
166+
| ITER sym iter exppull* ;; sym iter{ exppull* }
167+
| ATTR exp sym ;; exp `:` sym
154168

155169

156170
;; Definitions
157171

158172
syntax arg =
159-
| TYP typ
173+
| TYP typ -- if $with_polymorphic_types
160174
| EXP exp
161-
| FUN id
162-
| GRAM sym
175+
| FUN id -- if $with_higher_order
176+
| GRAM sym -- if $with_grammars
163177

164178
syntax param =
165-
| TYP id
179+
| TYP id -- if $with_polymorphic_types
166180
| EXP id `: typ
167-
| FUN id `: param* `-> typ
168-
| GRAM id `: param* `-> typ
181+
| FUN id `: param* `-> typ -- if $with_higher_order
182+
| GRAM id `: param* `-> typ -- if $with_grammars
169183

170184
syntax quant = param
171185

172186
syntax prem =
173-
| REL id arg* `: exp
187+
| REL id arg* `: exp -- if $with_noncomputational
174188
| IF exp
175189
| ELSE
176190
| NOT prem
177-
| LET exp `= exp ;; TODO: variables/quantifiers?
191+
| LET exp `= exp ;; TODO: variables/quantifiers?
178192
| ITER prem iter exppull*
179193

180194
syntax dec =
181-
| TYP id param* `= inst*
195+
| TYP id param* `= inst* -- if |inst*| <= 1 \/ $with_family_types
182196
| REL id param* `: typ `= rul*
183197
| FUN id param* `: typ `= clause*
184-
| GRAM id param* `: typ `= prod*
198+
| GRAM id param* `: typ `= prod* -- if $with_grammars
185199
| REC dec*
186200

187201
syntax inst = INST `{quant*} arg* `=> deftyp
202+
-- if arg* = (TYP typ)* \/ $with_dependent_types
188203
syntax rul = RULE `{quant*} exp `- prem*
189204
syntax clause = CLAUSE `{quant*} arg* `=> exp `- prem*
190-
syntax prod = PROD `{quant*} sym `=> exp `- prem*
205+
syntax prod = PROD `{quant*} sym `=> exp `- prem*
206+
-- if $with_grammars
191207

192208

193209
;; Scripts

spectec/doc/semantics/il/5-reduction.spectec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ rule Step_exp/MATCH-guess:
457457
S |- MATCH a* WITH (CLAUSE `{q*} a'* `=> e `- pr*) clause* ~>
458458
MATCH a* WITH (CLAUSE `{} $subst_arg(s, a')* `=> e `- pr*) clause*
459459
-- Ok_subst: $storeenv(S) |- s : q*
460-
;; Note: non-computational rule
460+
-- if $with_noncomputational
461461

462462
rule Step_exp/MATCH-true:
463463
S |- MATCH eps WITH (CLAUSE `{} eps `=> e `- eps) clause* ~> e
@@ -812,7 +812,7 @@ rule Step_prems/REL:
812812
-- if (x, p* `-> t `= rul*) <- S.REL
813813
-- if (RULE `{q*} e' `- pr*) <- $subst_rule($args_for_params(a*, p*), rul)*
814814
-- Ok_subst: $storeenv(S) |- s : q*
815-
;; Note: non-computational rule
815+
-- if $with_noncomputational
816816

817817
rule Step_prems/IF-ctx:
818818
S |- IF e ~> IF e'

0 commit comments

Comments
 (0)