[antlr-interest] ANTLRWorks 1.4.2: Simple grammar doesn't work

Udo Weik WeikEngOff at aol.com
Tue Jul 19 12:00:31 PDT 2011


Hello Jim,

many thanks for your answer. But Objection, Your Honour...

> Your lexer rules are fragments only, so there are no real lexer rules to
> match anything, then you try and construct parser rules from the fragment
> rules.

Of course that grammar is an excerpt from a more complex one. And the reason
that I use fragments is that I needed fragment lexer rules for that complex
grammar.

> Hence ANTLRWorks has no idea what you are doing because your grammar is so
> broken. It also sounds like you were debugging a prior version, then
> changed to this version (which will hang as the lexer consumes nothing),
> then after a restart, managed to rebuild the whole thing and saw that the
> generated code points out that you have no visible lexer rules. So, it is
> not the tool, but the workman.

No, not the workman. It's an issue of the tool, which the workman must
learn to handle. And in the above context I would expect an error message.
Check Grammar was successful, too.

> Make sure however, to regenerate the whole
> of your grammar for debug as ANTLRWorks can sometimes miss that the
> compilation failed and try to run something that was not compiled.

Thanks for that hint. I will investigate that further, have a sneaking
suspicion.

> The fragment rules are goof for readability in complex formulations, but
> in simple ranges, you are creating lots of method calls and hoping that
> the JIT will inline them. It is just as simple to do this:
>
> ID : ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9')* ;

That was my starting point.

> Which is what you are trying to do. Remember that Lexer rules start with
> an UPPER case letter and parser rules with a lower case letter (ironic
> given your rules right?); and that fragment rules are not visible to the
> parser and do not create tokens.
>
> Perhaps you should run through the 10 minute tutorials and perhaps load an
> existing working grammar in to ANTLRWorks before attempting your own.
> Also, always compare what you are trying to achieve with an existing
> grammar, and you may find you can steal the technique.

I can spent weeks with examples, when the simplest own creations don't
work. Did I do anything forbidden in my grammar below apart from using
fragment? I removed it and now the grammar is working - at the moment
the Debugger works correctly, too.


Greetings
Udo

>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
>> bounces at antlr.org] On Behalf Of Udo Weik
>> Sent: Tuesday, July 19, 2011 8:40 AM
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] ANTLRWorks 1.4.2: Simple grammar doesn't work
>>
>> Hello,
>>
>> what's wrong with the following grammar, tested with: abcd
>>
>>
>> grammar Problem1b ;
>>
>> fragment
>> Cl :  'a'..'z' ;
>> fragment
>> Cu :  'A'..'Z' ;
>> fragment
>> INT : '0'..'9' ;
>>
>> id_Chars :               Cl | Cu ;
>> id_NumbersChars  : INT | Cl | Cu ;
>>
>> test : id_Chars ( id_NumbersChars )* ;
>>
>>
>> My main problem is that every time I'm working with ANTLRWorks 1.4.2
>> its behaviour is different. Now I restartet ANTLRWorks and I got an
>> error [17:35:45]
>> F:\ProgLang\Parsers\ANTLR3\Projects\Tutorial\Test\IntegerZero\output\__
>> Test__.java:14: cannot find symbol [17:35:45] symbol  : method Cl()
>> [17:35:45] location: class Problem1bParser
>> [17:35:45]             g.Cl();
>> [17:35:45]              ^
>> [17:35:45] 1 error
>>
>> Some minutes ago the debugger blocked, before only 'a' was recognized.
>>
>>
>> Many thanks and greetings
>> Udo
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
>> email-address
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list