Re: Having trouble converting composite variables to intermediate form

noitalmost <noitalmost@cox.net>
Mon, 10 Mar 2014 15:18:43 -0400

          From comp.compilers

Related articles
Having trouble converting composite variables to intermediate form noitalmost@cox.net (noitalmost) (2014-02-22)
Re: Having trouble converting composite variables to intermediate form momchil.velikov@gmail.com (Momchil Velikov) (2014-02-28)
Re: Having trouble converting composite variables to intermediate form noitalmost@cox.net (noitalmost) (2014-03-10)
| List of all articles for this month |
From: noitalmost <noitalmost@cox.net>
Newsgroups: comp.compilers
Date: Mon, 10 Mar 2014 15:18:43 -0400
Organization: Compilers Central
References: 14-02-029 <YJYW1n00f1AptjU01JYXKV>
Keywords: code
Posted-Date: 10 Mar 2014 18:57:27 EDT

On Friday, February 28, 2014 11:27:00 AM Momchil Velikov wrote:
> On Saturday, February 22, 2014 7:32:01 PM UTC+2, noitalmost wrote:
> > x := r.a[2] + 5;
> >
> >
> > After parsing, the Wirl AST fragment looks like:
> >
> > Assign
> >
> > Ident x
> > Op +
> >
> > RecAccess
> >
> > Ident r
> > ArrAccess
> >
> > Ident a
> > Num 2
>
> You have currently
>
> RecAccess(r, ArrAccess(Ident(a), Num(2)))
>
> Note, however, that the array is not `a`, it's `r.a`. The subtree
> `ArrAccess(Ident(a), Num(2)) `is incorrect, because you don't have in fact
> a variable named `a` of an array type.
>
> Here the record access should take precedence over array access, i.e.
> the AST should look like:
>
> ArrAccess(RecAccess(r, Ident(a)), Num(2))


Thanks. I eventually figured it out independently by working backward from the
C code I wanted to generate. The compiler can now handle arbitrary
combinations of records, arrays, and pointers. I spent a week jumping up and
down and dancing. Wirl has now graduated from toy to fun toy :)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.