[antlr-interest] How to use String Attributes in ANTLR3

Kirk Woods woods.kirk at gmail.com
Tue Dec 12 13:28:05 PST 2006


I am very new to this, so I will start with what I know and then move on to
my guesses.  For AntlrWorks, I have found that I have to save, check
grammar, and then generate code (Ctrl-S, Ctrl-R, Ctrl-F10).
As for the $text problem, try changing your returns attribute from text to
txt and see if that makes a difference.

On 12/12/06, Foolish Ewe <foolishewe at hotmail.com> wrote:
>
> Hello All:
>
> I'm trying to add backend support to my grammar and for my convenience,  I
> would like to have
> Java Strings "synthetic attributes" passed from the bottom up in the
> grammar
> (so that I can
> access them in non terminal productions).  I tried following the approach
> that appears to
> be suggested in the expression evaluator in the wiki, at:
> http://www.antlr.org/wiki/display/ANTLR3/Expression+evaluator
>
> However, something like:
>
> testCommandSuffix returns [String text]
>         :
>                 ACTION {$text = $ACTION.text;}
>         ;
>
> generates errors reported in the console reading:
>
> [15:55:48] error(151): C:\temp\TestGrammar.g:111:10: cannot write to read
> only attribute: $text.
> [15:55:49] error(10):  internal error:
> org.antlr.tool.Message.toString(Message.java:124): Assertion failed!
> Message
> ID 151 created but is not present in errorMsgIDs or warningMsgIDs.
>
> Have I made an error here, if so, how can I fix it?  Otherwise, how does
> one
> specify a
> synthetic attribute in ANTLR?
>
> I have also noticed that in ANTLRworks 1.0b8, when trying to generate
> grammars, sometimes if I get
> an error, I will get a popup window reading:
> "Grammar Check failed:
>   null
>   Check Console for more Information"
>
> and if I try to edit the grammar or regenerate it, the console window does
> not get any new
> diagnostic messages routed to it.  Does anyone else get this?
>
> Thanks:
>
> Bill M.
>
> _________________________________________________________________
> Visit MSN Holiday Challenge for your chance to win up to $50,000 in
> Holiday
> cash from MSN today!
> http://www.msnholidaychallenge.com/index.aspx?ocid=tagline&locale=en-us
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20061212/90ae0217/attachment.html 


More information about the antlr-interest mailing list