Project

General

Profile

Revision 6affc9f5 src/parser_lustre.mly

View differences:

src/parser_lustre.mly
42 42
let mkdim_appl f args = mkdim_appl (Location.symbol_rloc ()) f args
43 43
let mkdim_ite i t e = mkdim_ite (Location.symbol_rloc ()) i t e
44 44

  
45
let add_symbol msg hashtbl name value =
46
 if Hashtbl.mem hashtbl name
47
 then raise (Corelang.Error (Corelang.Already_bound_symbol msg, Location.symbol_rloc ()))
48
 else Hashtbl.add hashtbl name value
49

  
50
let check_symbol msg hashtbl name =
51
 if not (Hashtbl.mem hashtbl name)
52
 then raise (Corelang.Error (Corelang.Unbound_symbol msg, Location.symbol_rloc ()))
53
 else ()
54

  
45 55
%}
46 56

  
47 57
%token <int> INT
......
130 140
			     nodei_stateless = $12;
131 141
			     nodei_spec = None})
132 142
    in
133
    Hashtbl.add node_table $2 nd; nd}
143
    add_symbol ("node " ^ $2) node_table $2 nd; nd}
134 144

  
135 145
| nodespec_list NODE IDENT LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR stateless_opt SCOL
136 146
    {let nd = mktop_decl (ImportedNode
......
142 152
			     nodei_stateless = $13;
143 153
			     nodei_spec = Some $1})
144 154
    in
145
    Hashtbl.add node_table $3 nd; nd}
155
    add_symbol ("node " ^ $3) node_table $3 nd; nd}
146 156

  
147 157
| FUNCTION IDENT LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL
148 158
    {let nd = mktop_decl (ImportedNode
......
154 164
			     nodei_stateless = true;
155 165
			     nodei_spec = None})
156 166
     in
157
     Hashtbl.add node_table $2 nd; nd}
167
     add_symbol ("function " ^ $2) node_table $2 nd; nd}
158 168

  
159 169
| nodespec_list FUNCTION IDENT LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL
160 170
    {let nd = mktop_decl (ImportedNode
......
166 176
			     nodei_stateless = true;
167 177
			     nodei_spec = Some $1})
168 178
     in
169
    Hashtbl.add node_table $3 nd; nd}
179
    add_symbol ("function " ^ $3) node_table $3 nd; nd}
170 180

  
171 181
top_decl:
172 182
| CONST cdecl_list { mktop_decl (Consts (List.rev $2)) }
......
187 197
			     node_spec = None;
188 198
			     node_annot = match annots with [] -> None | _ -> Some annots})
189 199
    in
190
    Hashtbl.add node_table $2 nd; nd}
200
    add_symbol ("node " ^ $2) node_table $2 nd; nd}
191 201

  
192 202
| nodespec_list NODE IDENT LPAR vdecl_list SCOL_opt RPAR RETURNS LPAR vdecl_list SCOL_opt RPAR SCOL_opt locals LET eq_list TEL 
193 203
    {let eqs, asserts, annots = $16 in
......
205 215
			     node_spec = Some $1;
206 216
			     node_annot = match annots with [] -> None | _ -> Some annots})
207 217
    in
208
    Hashtbl.add node_table $3 nd; nd}
218
    add_symbol ("node " ^ $3) node_table $3 nd; nd}
209 219

  
210 220
nodespec_list:
211 221
NODESPEC { $1 }
......
222 232
typ_def:
223 233
  TYPE IDENT EQ typeconst {
224 234
    try
225
      Hashtbl.add type_table (Tydec_const $2) (Corelang.get_repr_type $4)
226
    with Not_found-> raise (Corelang.Unbound_type ($4, Location.symbol_rloc())) }
235
      add_symbol ("type " ^ $2) type_table (Tydec_const $2) (Corelang.get_repr_type $4)
236
    with Not_found-> assert false }
227 237
| TYPE IDENT EQ ENUM LCUR tag_list RCUR { Hashtbl.add type_table (Tydec_const $2) (Tydec_enum ($6 (Tydec_const $2))) }
228 238
| TYPE IDENT EQ STRUCT LCUR field_list RCUR { Hashtbl.add type_table (Tydec_const $2) (Tydec_struct ($6 (Tydec_const $2))) }
229 239

  
......
236 246
| TBOOL array_typ_decl { $2 Tydec_bool  }
237 247
| TREAL array_typ_decl { $2 Tydec_real  }
238 248
| TFLOAT array_typ_decl { $2 Tydec_float }
239
| IDENT array_typ_decl { $2 (Tydec_const $1) }
249
| IDENT array_typ_decl { check_symbol ("type " ^ $1) type_table (Tydec_const $1); $2 (Tydec_const $1) }
240 250
| TBOOL TCLOCK  { Tydec_clock Tydec_bool }
241 251
| IDENT TCLOCK  { Tydec_clock (Tydec_const $1) }
242 252

  
243 253
tag_list:
244 254
  IDENT
245
  { (fun t -> if Hashtbl.mem tag_table $1
246
              then raise (Corelang.Already_bound_label ($1, t, Location.symbol_rloc ()))
247
              else (Hashtbl.add tag_table $1 t; $1 :: [])) }
255
  { (fun t -> add_symbol ("tag " ^ $1) tag_table $1 t; $1 :: []) }
248 256
| tag_list COMMA IDENT
249
  { (fun t -> if Hashtbl.mem tag_table $3
250
              then raise (Corelang.Already_bound_label ($3, t, Location.symbol_rloc ()))
251
              else (Hashtbl.add tag_table $3 t; $3 :: ($1 t))) }
257
  { (fun t -> add_symbol ("tag " ^ $3)tag_table $3 t; $3 :: ($1 t)) }
252 258

  
253 259
field_list:
254 260
  { (fun t -> []) }
255 261
| field_list IDENT COL typeconst SCOL
256
  { (fun t -> if Hashtbl.mem field_table $2
257
              then raise (Corelang.Already_bound_label ($2, t, Location.symbol_rloc ()))
258
              else (Hashtbl.add field_table $2 t; ($1 t) @ [ ($2, $4) ])) }
262
  { (fun t -> add_symbol ("field " ^ $2) field_table $2 t; ($1 t) @ [ ($2, $4) ]) }
259 263

  
260 264
eq_list:
261 265
  { [], [], [] }

Also available in: Unified diff