[antlr-interest] tree grammar error (newbie)- missing attribute access
Jim Idle
jimi at temporal-wave.com
Tue Feb 10 08:13:13 PST 2009
Carter Cheng wrote:
> Hello,
>
> I am getting a missing attribute access error on a number of rules which I do not quite understand and was hoping I might be able to get some help fixing them. The errors point to the following rules in the tree grammar.
>
>
> varDecls[std::list<std::string> & err] returns [std::map<Symbol,Type*> vars]
> : (v=varDecl { $vars.insert($v); } )+
> ;
>
> formalList returns [pair< std::list<Type*>, bool > p]
> : { $p.second = false; } (t=formal { $p.first.push_back($t); } )* (ELLIPSIS { $p.second = true; } )?
> ;
>
> with
>
> varDecl returns [pair<Symbol,Type*> var]
> : t=type (s=STAR)? i=IDENT { $var = pair<Symbol,Type*>($i.text, $t); }
> ;
>
> formal returns [Type* type]
> : ^(FORMAL t=formalType (s=STAR)? IDENT) { $type = $t; }
> ;
>
> I was searching through the archive on this but couldnt find a solution that seemed to work. i.e. changing $v --> $v.value gives an unknown attribute type error. Any help would be appreciated.
>
> Thanks in advance,
>
> Carter.
>
Internally, your $v refers to a struct representing the return type of
varDecl and you cannot reference it alone. At some point I think we
became a little over-zealous on this checking and I mean to review it.
However, in your case, assuming that ANTLR will correctly parser your
template and say that var is of that type (and it may not, you might
have typedef it, and it might need to be a pointer) then you will want
to use $v.var.
Jim
More information about the antlr-interest
mailing list