Skip to content

Commit 3760add

Browse files
committed
[interpreter] Remove duplicated token declarations.
This patch tidies up the `parser.mly` module by removing two instances of `%prec` that were never useful. More importantly, this patch also removes duplicated token declarations as `menhir` considers such an error in debug mode. Consequently, it is now possible to debug the grammar using `menhir --explain` or similar.
1 parent f2b7c60 commit 3760add

File tree

1 file changed

+20
-50
lines changed

1 file changed

+20
-50
lines changed

interpreter/text/parser.mly

Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -205,70 +205,40 @@ let inline_type_explicit (c : context) x ft at =
205205
%}
206206

207207
%token LPAR RPAR
208-
%token NAT INT FLOAT STRING VAR
209-
%token NUM_TYPE VEC_TYPE VEC_SHAPE FUNCREF EXTERNREF EXTERN MUT
208+
%token<string> NAT INT FLOAT STRING VAR
209+
%token<Types.num_type> NUM_TYPE
210+
%token<Types.vec_type> VEC_TYPE
211+
%token<V128.shape> VEC_SHAPE
212+
%token FUNCREF EXTERNREF EXTERN MUT
210213
%token UNREACHABLE NOP DROP SELECT
211214
%token BLOCK END IF THEN ELSE LOOP BR BR_IF BR_TABLE
212215
%token CALL CALL_INDIRECT RETURN
213216
%token LOCAL_GET LOCAL_SET LOCAL_TEE GLOBAL_GET GLOBAL_SET
214217
%token TABLE_GET TABLE_SET
215218
%token TABLE_SIZE TABLE_GROW TABLE_FILL TABLE_COPY TABLE_INIT ELEM_DROP
216219
%token MEMORY_SIZE MEMORY_GROW MEMORY_FILL MEMORY_COPY MEMORY_INIT DATA_DROP
217-
%token LOAD STORE OFFSET_EQ_NAT ALIGN_EQ_NAT
218-
%token CONST UNARY BINARY TEST COMPARE CONVERT
220+
%token<int option -> Memory.offset -> Ast.instr'> LOAD STORE
221+
%token<string> OFFSET_EQ_NAT ALIGN_EQ_NAT
222+
%token<string Source.phrase -> Ast.instr' * Values.num> CONST
223+
%token<Ast.instr'> UNARY BINARY TEST COMPARE CONVERT
219224
%token REF_NULL REF_FUNC REF_EXTERN REF_IS_NULL
220-
%token VEC_LOAD VEC_STORE VEC_LOAD_LANE VEC_STORE_LANE
221-
%token VEC_CONST VEC_UNARY VEC_BINARY VEC_TERNARY VEC_TEST
222-
%token VEC_SHIFT VEC_BITMASK VEC_SHUFFLE
223-
%token VEC_EXTRACT VEC_REPLACE
225+
%token<int option -> Memory.offset -> Ast.instr'> VEC_LOAD VEC_STORE
226+
%token<int option -> Memory.offset -> int -> Ast.instr'> VEC_LOAD_LANE VEC_STORE_LANE
227+
%token<V128.shape -> string Source.phrase list -> Source.region -> Ast.instr' * Values.vec> VEC_CONST
228+
%token<Ast.instr'> VEC_UNARY VEC_BINARY VEC_TERNARY VEC_TEST
229+
%token<Ast.instr'> VEC_SHIFT VEC_BITMASK VEC_SPLAT
230+
%token VEC_SHUFFLE
231+
%token<int -> Ast.instr'> VEC_EXTRACT VEC_REPLACE
224232
%token FUNC START TYPE PARAM RESULT LOCAL GLOBAL
225233
%token TABLE ELEM MEMORY DATA DECLARE OFFSET ITEM IMPORT EXPORT
226234
%token MODULE BIN QUOTE
227235
%token SCRIPT REGISTER INVOKE GET
228-
%token ASSERT_MALFORMED ASSERT_INVALID ASSERT_SOFT_INVALID ASSERT_UNLINKABLE
236+
%token ASSERT_MALFORMED ASSERT_INVALID ASSERT_UNLINKABLE
229237
%token ASSERT_RETURN ASSERT_TRAP ASSERT_EXHAUSTION
230-
%token NAN
238+
%token<Script.nan> NAN
231239
%token INPUT OUTPUT
232240
%token EOF
233241

234-
%token<string> NAT
235-
%token<string> INT
236-
%token<string> FLOAT
237-
%token<string> STRING
238-
%token<string> VAR
239-
%token<Types.num_type> NUM_TYPE
240-
%token<Types.vec_type> VEC_TYPE
241-
%token<string Source.phrase -> Ast.instr' * Values.num> CONST
242-
%token<V128.shape -> string Source.phrase list -> Source.region -> Ast.instr' * Values.vec> VEC_CONST
243-
%token<Ast.instr'> UNARY
244-
%token<Ast.instr'> BINARY
245-
%token<Ast.instr'> TEST
246-
%token<Ast.instr'> COMPARE
247-
%token<Ast.instr'> CONVERT
248-
%token<int option -> Memory.offset -> Ast.instr'> LOAD
249-
%token<int option -> Memory.offset -> Ast.instr'> STORE
250-
%token<int option -> Memory.offset -> Ast.instr'> VEC_LOAD
251-
%token<int option -> Memory.offset -> Ast.instr'> VEC_STORE
252-
%token<int option -> Memory.offset -> int -> Ast.instr'> VEC_LOAD_LANE
253-
%token<int option -> Memory.offset -> int -> Ast.instr'> VEC_STORE_LANE
254-
%token<Ast.instr'> VEC_UNARY
255-
%token<Ast.instr'> VEC_BINARY
256-
%token<Ast.instr'> VEC_TERNARY
257-
%token<Ast.instr'> VEC_TEST
258-
%token<Ast.instr'> VEC_SHIFT
259-
%token<Ast.instr'> VEC_BITMASK
260-
%token<Ast.instr'> VEC_SPLAT
261-
%token<int -> Ast.instr'> VEC_EXTRACT
262-
%token<int -> Ast.instr'> VEC_REPLACE
263-
%token<string> OFFSET_EQ_NAT
264-
%token<string> ALIGN_EQ_NAT
265-
%token<V128.shape> VEC_SHAPE
266-
267-
%token<Script.nan> NAN
268-
269-
%nonassoc LOW
270-
%nonassoc VAR
271-
272242
%start script script1 module1
273243
%type<Script.script> script
274244
%type<Script.script> script1
@@ -367,7 +337,7 @@ bind_var :
367337
| VAR { $1 @@ at () }
368338

369339
labeling_opt :
370-
| /* empty */ %prec LOW
340+
| /* empty */
371341
{ fun c xs ->
372342
List.iter (fun x -> error x.at "mismatching label") xs;
373343
anon_label c }
@@ -378,7 +348,7 @@ labeling_opt :
378348
bind_label c $1 }
379349

380350
labeling_end_opt :
381-
| /* empty */ %prec LOW { [] }
351+
| /* empty */ { [] }
382352
| bind_var { [$1] }
383353

384354
offset_opt :

0 commit comments

Comments
 (0)