Commit d743db73cd6a159b270847ab42f6384d3090a2f7

  • avatar
  • Antti-Juhani Kaijanaho <antti-juhani @kaij…aho.fi> (Committer)
  • Tue Nov 13 18:04:31 EET 2012
  • avatar
  • Antti-Juhani Kaijanaho <antti-juhani @kaij…aho.fi> (Author)
  • Tue Nov 13 18:04:31 EET 2012
Fix let (parser scoped it as letrec).

Signed-off-by: Antti-Juhani Kaijanaho <antti-juhani@kaijanaho.fi>
hm.y
(36 / 8)
  
131131 struct typed_term *tt;
132132};
133133
134struct let_binding {
135 struct binding b; // shadowed binding
136 struct term *def;
137 struct srcloc start, end;
138};
139
134140%}
135141
136142%union {
144144 struct str_with_loc str;
145145 struct term *term;
146146 struct binding binding;
147
147 struct let_binding let_binding;
148148}
149149
150150/**************************************************************************
158158%type<term> term apterm pterm
159159
160160%type<binding> id_def
161%type<let_binding> let
161162
162163%%
163164
224224 $$->end = $4->end;
225225 free(tt);
226226}
227| LET id_def '=' term IN term
227| let IN term
228228{
229 struct typed_term *tt = define_symbol($2.s, $2.tt);
229 struct typed_term *tt = define_symbol($1.b.s, $1.b.tt);
230230 NEW($$);
231231 $$->kind = TE_LET;
232 $$->var = $2.s;
232 $$->var = $1.b.s;
233233 $$->sub[0] = tt->te;
234 $$->sub[1] = $4;
235 $$->sub[2] = $6;
236 $$->start = $1;
237 $$->end = $6->end;
234 $$->sub[1] = $1.def;
235 $$->sub[2] = $3;
236 $$->start = $1.start;
237 $$->end = $3->end;
238238 free(tt);
239239}
240240;
241
242let :
243 LET ID '=' term
244{
245 struct typed_term *tt;
246 NEW(tt);
247 NEW(tt->te);
248 tt->te->kind = TE_VAR;
249 tt->te->var = $2.str;
250 tt->te->sub[0] = 0;
251 tt->te->sub[1] = 0;
252 tt->te->sub[2] = 0;
253 tt->te->start = $2.loc;
254 tt->te->end = $2.loc;
255 tt->ty = 0;
256 $$.b.s = $2.str;
257 $$.b.tt = define_symbol($2.str, tt);
258 $$.def = $4;
259 $$.start = $1;
260 $$.end = $4->end;
261}
241262
242263/* id_def's semantic value is the shadowed binding */
243264id_def :