[antlr-interest] parameterized maps as arguments to rules??
David A Weiser
DWEISER at uwyo.edu
Mon Jun 18 10:28:24 PDT 2007
Hey all,
I have the beginning of a rule:
formalParameterDecls returns [HashMap<String,String> params].
But I get a compilation error because of:
public static class formalParameters_return extends
ParserRuleReturnScope {
public HashMap<String;
public String> params;
};
In the java file for the grammar parser. Am I to assume that java 1.5
features aren't supported, or am I just going about this wrong?
Thanks,
dave
-----Original Message-----
From: antlr-interest-request at antlr.org
[mailto:antlr-interest-request at antlr.org]
Sent: Saturday, June 16, 2007 1:00 PM
To: antlr-interest at antlr.org
Subject: antlr-interest Digest, Vol 31, Issue 63
Send antlr-interest mailing list submissions to
antlr-interest at antlr.org
To subscribe or unsubscribe via the World Wide Web, visit
http://www.antlr.org/mailman/listinfo/antlr-interest
or, via email, send a message with subject or body 'help' to
antlr-interest-request at antlr.org
You can reach the person managing the list at
antlr-interest-owner at antlr.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of antlr-interest digest..."
Today's Topics:
1. Re: Debugging Tree Parser grammar using ANTLRWorks (Terence Parr)
2. Re: Debugging Tree Parser grammar using ANTLRWorks (Terence Parr)
3. Re: Debugging Tree Parser grammar using ANTLRWorks (Terence Parr)
4. Re: Turning off harmless warnings (Kay Roepke)
5. Re: Java string array issue in v3. (Kay Roepke)
6. Re: Patch for filter mode (+1 Vote!) (Kay Roepke)
7. Re: Bug using rule action? (Kay Roepke)
8. Imaginary nodes in Antlr 3 (geoff)
9. Re: Imaginary nodes in Antlr 3 (Kay Roepke)
10. Re: Java string array issue in v3. (Kay Roepke)
----------------------------------------------------------------------
Message: 1
Date: Sat, 16 Jun 2007 15:51:02 +1000
From: Terence Parr <parrt at cs.usfca.edu>
Subject: Re: [antlr-interest] Debugging Tree Parser grammar using
ANTLRWorks
To: ANTLR Interest <antlr-interest at antlr.org>
Cc: Jean Bovet <jean_bovet at mac.com>
Message-ID: <96C2D442-710C-4EE7-B39D-C2FB242BC976 at cs.usfca.edu>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
Well, it works; i asked Jean to change the message. It just has to
"debug remote..." not "debug". He just doesn't have the test rig set
up. You can start up a tree parser from command line and have AW
connect to it.
Ter
On Jun 15, 2007, at 9:13 PM, Chaudhari, Pranita, OPEE14 wrote:
> I am new to ANTLRWorks need help !
>
> When I am trying to debug Tree Parser Grammar, window pops up
> saying "ANTLRWorks does not support debugging tree Parser Grammar".
> Does AntlrWorks 1.0.2 supports it?
>
> -Pranita
------------------------------
Message: 2
Date: Sat, 16 Jun 2007 16:01:06 +1000
From: Terence Parr <parrt at cs.usfca.edu>
Subject: Re: [antlr-interest] Debugging Tree Parser grammar using
ANTLRWorks
To: ANTLR Interest <antlr-interest at antlr.org>
Message-ID: <7F15F5AD-D78D-4C83-91DA-1110172E672A at cs.usfca.edu>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
On Jun 16, 2007, at 4:38 AM, Diehl, Matthew J wrote:
> Debugging tree parsers has not been implemented in ANTLRWorks yet.
Hi :) Contrary to the message, it works...just not at click of
button from AW.
Ter
------------------------------
Message: 3
Date: Sat, 16 Jun 2007 16:11:31 +1000
From: Terence Parr <parrt at cs.usfca.edu>
Subject: Re: [antlr-interest] Debugging Tree Parser grammar using
ANTLRWorks
To: ANTLR Interest <antlr-interest at antlr.org>
Message-ID: <50EAA69C-B944-4648-8AB8-DD5204D3EC35 at cs.usfca.edu>
Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
On Jun 16, 2007, at 9:51 AM, Gavin Lambert wrote:
> At 23:13 15/06/2007, Chaudhari, Pranita, OPEE14 wrote:
>> I am new to ANTLRWorks need help !
>>
>> When I am trying to debug Tree Parser Grammar, window pops up
>> saying "ANTLRWorks does not support debugging tree Parser
>> Grammar". Does AntlrWorks 1.0.2 supports it?
>
> While on the subject of debugging wishlists, it'd be nice if AW
> could debug through lexers as well. That'd save having to write a
> throwaway program to step through the generated lexer code :)
I think we could add debug event triggers to the lexers w/o much
effort. ANTLRWorks would just...work. :) Well, assuming we treated
chars as tokens.
Ter
------------------------------
Message: 4
Date: Sat, 16 Jun 2007 13:59:27 +0200
From: Kay Roepke <kroepke at classdump.org>
Subject: Re: [antlr-interest] Turning off harmless warnings
To: Wincent Colaiuta <win at wincent.com>
Cc: ANTLR mail-list <antlr-interest at antlr.org>
Message-ID: <6EE02E3E-5BEA-4EC9-AC9E-65BD0C117E8B at classdump.org>
Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed
On Jun 15, 2007, at 11:29 AM, Wincent Colaiuta wrote:
> So like I said, it would be good if someone with write access could
> get this into the tracker, as it is not always possible to rewrite
> the rules in such a way as to eliminate all such warnings!
Thanks for the pointer, just added: <http://www.antlr.org:8888/browse/
ANTLR-139>
cheers,
-k
--
Kay R?pke
http://classdump.org/
------------------------------
Message: 5
Date: Sat, 16 Jun 2007 14:39:17 +0200
From: Kay Roepke <kroepke at classdump.org>
Subject: Re: [antlr-interest] Java string array issue in v3.
To: Ted Villalba <ted.villalba at gmail.com>
Cc: ANTLR mail-list <antlr-interest at antlr.org>
Message-ID: <E1B1F737-15F0-4A2F-957B-B1CFCC28D47B at classdump.org>
Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed
Hi!
On Jun 15, 2007, at 11:35 PM, Johannes Luber wrote:
> Ted Villalba wrote:
>> Hi.
>> Not sure, I might be doing something wrong here, but this seems
>> like a bug.
>> I'm trying to pass a string array to the start of my tree, but when I
>> compile my tree grammar the String array gets compiled
>> into a String.
>> So in treeGrammar.g my start symbol is rule "start"
>>
>> start[HashMap fieldMap, String[] fqls]
>> @init{
>> etc etc...
>> }
>
> IIRC, the problem is that arrays rely on "[]" which are part of the
> ANTLR grammar and that this is falsely attributed to be a parameter
> for
> a rule. As far as I know there is no way to prevent this behaviour
> right
> now. A workaround would be to declare flqs as object and cast it in
> Java
> to a String array.
Yes, that's correct. As it stands it is not possible to escape the []
chars.
I just had a look at the grammar and have a simple fix for this case,
i.e.
it should treat a bare '[]' as just that token without trying to
match an argument.
I'm not, however, certain that this actually is a good idea, because I'm
unsure whether or not it breaks other things.
We should ask Ter if he's alright with it, after that I could push
the fix.
In the meantime I added a bug and will attach the diff over at
<http://www.antlr.org:8888/browse/ANTLR-140>
Thanks for reporting this!
cheers,
-k
--
Kay R?pke
http://classdump.org/
------------------------------
Message: 6
Date: Sat, 16 Jun 2007 14:52:32 +0200
From: Kay Roepke <kroepke at classdump.org>
Subject: Re: [antlr-interest] Patch for filter mode (+1 Vote!)
To: Wincent Colaiuta <win at wincent.com>
Cc: Mark Venbrux <mark.venbrux at gmail.com>, antlr-interest at antlr.org
Message-ID: <993ABC8B-CFE5-4050-B8CC-38B5D26114B3 at classdump.org>
Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed
On Jun 15, 2007, at 2:04 AM, Wincent Colaiuta wrote:
> Terence is off to Sydney, as you probably know... he sent me a
> message to say, "remind me of this when I get back in a couple of
> weeks". So I think you'll see the issue addressed in one way or
> another then....
I added this at <http://www.antlr.org:8888/browse/ANTLR-141> so we
don't lose this one.
thanks again,
-k
--
Kay R?pke
http://classdump.org/
------------------------------
Message: 7
Date: Sat, 16 Jun 2007 15:34:44 +0200
From: Kay Roepke <kroepke at classdump.org>
Subject: Re: [antlr-interest] Bug using rule action?
To: Cameron Esfahani <dirty at apple.com>
Cc: antlr-interest at antlr.org
Message-ID: <D9F01011-2E89-4FFA-8132-70D5F0A2348A at classdump.org>
Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed
Hi Cameron!
On Jun 14, 2007, at 1:19 AM, Cameron Esfahani wrote:
> I'm trying to add an action to one of my rules and I'm seeing some
> strange behavior:
>
> grammar Test;
> [...]
> number_size
> : num = NUMBER size = size_qualifier {
> // Validate that NUMBER fits within the size
qualifier.
> System.out.printf( "!\%s, !\%s\n",
$num.toString(), $size.getTree
> ().toString() );
> } -> size_qualifier NUMBER
> ;
> If I try to run this through ANTLR, I get an error:
>
> error(116): Test.g:30:39: unknown attribute for rule
> size_qualifier: getTree
>
> When I examine TestParser.java, I see that "$size" is still there.
> If I change the action, to remove the $ character, then it works:
>
> System.out.printf( "!\%s, !\%s\n",
$num.toString(), size.getTree
> ().toString() );
>
> Why do I have to do this? How come $num correctly causes a local
> variable named num to be created, but not $size?
Don't remove the $ char, as this defeats any checking ANTLR can do on
rule attributes. When doing that you rely on the internal naming
scheme ANTLR uses for the generated code. In the Objective-C target,
for instance, this would break your code as I'm prefixing every local
variable
with an _ character to avoid name clashes.
The reason for the behavior you are seeing is that ANTLR checks
whether attributes on labels are valid. When it sees $size.getTree()
it thinks you want to access the getTree field of whatever
size_qualifier returns and discovers that size_qualifier doesn't
declare any attribute with that name. Consequently it flags it as an
error. It's a bit unfortuntate because it doesn't know about methods
in the size_return class, even though it has generated that method
itself.
When you use $size.tree.toString() it will work because the tree
attribute is a "predefined attribute" of rules. The code generated
would look like:
// Validate that NUMBER fits within the size qualifier.
System.out.printf( "!%s, !%s\n", num.toString(), ((CommonTree)
size.tree).toString() );
The reason that $num.toString works is that $num refers to a Token
and not a rule. It is allowed to reference a token or token label in
a "stand-alone" manner, while this is not permitted for rule references.
Note that you can do without any labels in your example:
number_size
: NUMBER size_qualifier {
// Validate that NUMBER fits within the size
qualifier.
System.out.printf( "!\%s, !\%s\n",
$NUMBER.toString(),
$size_qualifier.tree.toString() );
} -> size_qualifier NUMBER
;
generates your action as:
// Validate that NUMBER fits within the size qualifier.
System.out.printf( "!%s, !%s\n", NUMBER4.toString(),
((CommonTree)
size_qualifier5.tree).toString() );
Labels are only necessary to disambiguate between multiple references
to the same rule or token. This also nicely illustrates that you
shouldn't rely on any naming scheme for rule returns because they
will highly depend on the input grammar.
By using the predefined rule attributes we can ensure that we
generate better code and are more flexible with future changes.
HTH,
-k
--
Kay R?pke
http://classdump.org/
------------------------------
Message: 8
Date: Sat, 16 Jun 2007 14:38:49 +0100
From: geoff <ot0006 at 0x29a.org.uk>
Subject: [antlr-interest] Imaginary nodes in Antlr 3
To: antlr-interest at antlr.org
Message-ID: <mmo773h4oq7lcr77ib0rm53ee0l9hs7o28 at 4ax.com>
Content-Type: text/plain; charset=us-ascii
Hallo there,
I'm running AntlrWorks 1.0.2, Antlr 3.0, StringTemplate 3.1b1 on XP.
I have The Definitive Antlr Reference open next to me.
I'm adding an AST to the Expr.g first example. I want to make the
assignment operator an
imaginary node:
stat: expr NEWLINE! {System.out.println($expr.value);}
| ID '=' expr NEWLINE -> ^(ASSIGN ID expr)
| NEWLINE!
;
On p166 Adding Imaginary Nodes the book says "simply refer to its token
type and, and
Antlr will create a Token object with that token type", which is what I
expected to happen
to ASSIGN.
But, this does not work, and I get
(135) ... Reference to undefined token in rewrite rules: ASSIGN
as well as red wavy underlining in AntlrWorks.
On a guess I then tried adding the token to the grammar
ASSIGN : ;
and everything compiled and ran as expected, tree built perfectly.
Is there something I'm missing on automatic creation of imaginary
tokens? Clues welcome.
--
best,
geoff stevens
regrettably the email address above will bounce
------------------------------
Message: 9
Date: Sat, 16 Jun 2007 16:26:12 +0200
From: Kay Roepke <kroepke at classdump.org>
Subject: Re: [antlr-interest] Imaginary nodes in Antlr 3
To: ot0006 at 0x29a.org.uk
Cc: antlr-interest at antlr.org
Message-ID: <B82EEBD6-5D46-4D92-ACAA-04118E6678C3 at classdump.org>
Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed
Hi geoff!
On Jun 16, 2007, at 3:38 PM, geoff wrote:
> stat: expr NEWLINE! {System.out.println($expr.value);}
> | ID '=' expr NEWLINE -> ^(ASSIGN ID expr)
> | NEWLINE!
> ;
>
> On p166 Adding Imaginary Nodes the book says "simply refer to its
> token type and, and
> Antlr will create a Token object with that token type", which is
> what I expected to happen
> to ASSIGN.
>
> But, this does not work, and I get
> (135) ... Reference to undefined token in rewrite rules: ASSIGN
> as well as red wavy underlining in AntlrWorks.
>
> On a guess I then tried adding the token to the grammar
>
> ASSIGN : ;
>
> and everything compiled and ran as expected, tree built perfectly.
>
> Is there something I'm missing on automatic creation of imaginary
> tokens? Clues welcome.
ANTLR won't generate the token in the grammar. The text refers to the
Token object. You still need to tell ANTLR about the token in the
grammar, either by declaring a lexer rule or, if you want to have
imaginary tokens, via the tokens {} section in your grammar.
Refer to page 99 in the book.
HTH,
-k
--
Kay R?pke
http://classdump.org/
------------------------------
Message: 10
Date: Sat, 16 Jun 2007 20:38:45 +0200
From: Kay Roepke <kroepke at classdump.org>
Subject: Re: [antlr-interest] Java string array issue in v3.
To: Ted Villalba <ted.villalba at gmail.com>
Cc: ANTLR mail-list <antlr-interest at antlr.org>
Message-ID: <CF71D177-4FC9-48F2-83FF-A9B786DAFF77 at classdump.org>
Content-Type: text/plain; charset=ISO-8859-1; delsp=yes; format=flowed
On Jun 16, 2007, at 2:39 PM, Kay Roepke wrote:
> We should ask Ter if he's alright with it, after that I could push
> the fix.
> In the meantime I added a bug and will attach the diff over at
> <http://www.antlr.org:8888/browse/ANTLR-140>
FYI, the above URL has a comment describing the fix. When (and if)
that goes through, you will be able to escape '[' and ']' characters
in rule arguments, thus allowing things like String[] strArray as
parameters.
It shouldn't affect anything else, as far as I can see.
cheers,
-k
--
Kay R?pke
http://classdump.org/
------------------------------
_______________________________________________
antlr-interest mailing list
antlr-interest at antlr.org
http://www.antlr.org/mailman/listinfo/antlr-interest
End of antlr-interest Digest, Vol 31, Issue 63
**********************************************
More information about the antlr-interest
mailing list