Fix error in parsing int constants.

master
Rohan Jacob-Rao 10 years ago
parent 66aecca31f
commit e1d071fb1f

@ -68,11 +68,11 @@ rule token = parse
| "label" { LABEL } | "label" { LABEL }
| "metadata" { METADATA } | "metadata" { METADATA }
| pos_int as size { SIZE (int_of_string size) } | pos_int as size { CONSTANT_INT (int_of_string size) }
(* CONSTANTS *) (* CONSTANTS *)
| "true" { CONSTINT 1 } | "true" { CONSTANT_INT 1 }
| "false" { CONSTINT 0 } | "false" { CONSTANT_INT 0 }
| intlit as i { CONSTINT (int_of_string i) } | intlit as i { CONSTANT_INT (int_of_string i) }
(* floating point constants *) (* floating point constants *)
| "null" { NULL } | "null" { NULL }

@ -42,9 +42,8 @@
%token LABEL %token LABEL
%token METADATA %token METADATA
%token <int> SIZE
(* CONSTANTS *) (* CONSTANTS *)
%token <int> CONSTINT %token <int> CONSTANT_INT
%token NULL %token NULL
(* INSTRUCTIONS *) (* INSTRUCTIONS *)
@ -162,13 +161,13 @@ typ:
| tp = element_typ { tp } | tp = element_typ { tp }
(*| X86_MMX { () }*) (*| X86_MMX { () }*)
| tp = vector_typ { tp } | tp = vector_typ { tp }
| LSQBRACK sz = SIZE X tp = element_typ RSQBRACK { Tarray (sz, tp) } (* array type *) | LSQBRACK sz = CONSTANT_INT X tp = element_typ RSQBRACK { Tarray (sz, tp) } (* array type *)
| LABEL { Tlabel } | LABEL { Tlabel }
| METADATA { Tmetadata } | METADATA { Tmetadata }
(* TODO structs *) (* TODO structs *)
vector_typ: vector_typ:
| LANGLE sz = SIZE X tp = element_typ RANGLE { Tvector (sz, tp) } | LANGLE sz = CONSTANT_INT X tp = element_typ RANGLE { Tvector (sz, tp) }
element_typ: element_typ:
| width = INT { Tint width } | width = INT { Tint width }
@ -196,7 +195,7 @@ instr:
| BR LABEL lbl=variable { UncondBranch lbl } | BR LABEL lbl=variable { UncondBranch lbl }
| BR BIT op=operand COMMA LABEL lbl1=variable COMMA LABEL lbl2=variable { CondBranch (op, lbl1, lbl2) } | BR BIT op=operand COMMA LABEL lbl1=variable COMMA LABEL lbl2=variable { CondBranch (op, lbl1, lbl2) }
(* Memory access operations *) (* Memory access operations *)
| var=variable EQUALS ALLOCA tp=typ (*COMMA ALIGN sz=SIZE*) { Alloc (var, tp, 1, 1) } | var=variable EQUALS ALLOCA tp=typ (*COMMA ALIGN sz=CONSTANT_INT*) { Alloc (var, tp, 1, 1) }
| var = variable EQUALS LOAD tp = ptr_typ ptr = variable { Load (var, tp, ptr) } | var = variable EQUALS LOAD tp = ptr_typ ptr = variable { Load (var, tp, ptr) }
| STORE val_tp = typ value = operand COMMA ptr_tp = ptr_typ var = variable { Store (value, val_tp, var) } | STORE val_tp = typ value = operand COMMA ptr_tp = ptr_typ var = variable { Store (value, val_tp, var) }
(* don't yet know why val_tp and ptr_tp would be different *) (* don't yet know why val_tp and ptr_tp would be different *)
@ -248,5 +247,5 @@ variable:
| num = NUMBERED_LOCAL { Local (Number num) } | num = NUMBERED_LOCAL { Local (Number num) }
constant: constant:
| i = CONSTINT { Cint i } | i = CONSTANT_INT { Cint i }
| NULL { Cnull } | NULL { Cnull }

Loading…
Cancel
Save