[il-antlr-interest: 30273] Re: [antlr-interest] How to force error recovery?

2010-10-05 Thread Junkman
Just wanted to echo the note of thanks for writing the wiki article. :-) J On 10/5/2010 8:43 AM, Jim Idle wrote: > Please read the article in the wiki on error recovery methods. You can see > there how to keep a parse loop going instead of it breaking out. You can > also see a real world example

[il-antlr-interest: 30262] Re: [antlr-interest] How to force error recovery?

2010-10-04 Thread Junkman
und this: > > http://www.antlr.org/wiki/display/ANTLR3/Custom+Syntax+Error+Recovery > >I am trying to check if it works for my case. Otherwise I will try > your approach. > > Edson > > 2010/10/4 Junkman : >> Greetings, >> >> I ran into th

[il-antlr-interest: 30260] Re: [antlr-interest] How to force error recovery?

2010-10-04 Thread Junkman
Greetings, I ran into the same issue, and you probably noticed that, when the lookahead doesn't match a statement, it breaks out of * loop and tries to match EOF. I resorted to calling statement() in a loop to force continuation of parsing regardless of error, instead of calling compilationUnit()

[il-antlr-interest: 30152] Re: [antlr-interest] Literal - ID clash resolution

2010-09-14 Thread Junkman
I'd guess the common first stab would be to have '=' as a distinct token and elevate ID into a parsing symbol: EQUAL: '='; id: (ID | EQUAL) ; option: optionName=id EQUAL STRING ; It might become bit more interesting if you also need to make optionName optional. But maybe you could rewind the sta

[il-antlr-interest: 30120] Re: [antlr-interest] Composite grammars and ANTLRWorks

2010-09-09 Thread Junkman
On 9/9/2010 1:58 AM, rh...@rationalcommerce.com wrote: > I continue to struggle with a composite grammar. > > Until a couple of days ago I hadn't even heard of composite grammars. > I need to rescue my grammar that has become too big to compile. > > Am I making a rod for my own back by trying to

[il-antlr-interest: 30068] [antlr-interest] Issue ANTLR-397 - CommonTreeNodeStream.index()

2010-09-02 Thread Junkman
Greetings, I've encountered the issue noted in the subject - CommonTreeNodeStream.index() does not return the correct current index into the stream. Just reporting to give it any extra visibility it may so that its fix is incorporated into the next release. It was an entertaining bug in my case,

[il-antlr-interest: 30018] Re: [antlr-interest] Tree grammar confusion

2010-08-25 Thread Junkman
Piper, Martin wrote: > Greetings, > ... > > My main confusion is that when generating a tree > > ^(rule_1 A B) > rule_1: TOKEN C D->^(TOKEN C D) > produces a tree (TOKEN C D A B) > > but the same when walking the tree seems to expect to find ((TOKEN C D) A B) > Hi Martin, You ran into th

[il-antlr-interest: 29905] Re: [antlr-interest] Antlr 3.2 issues: code too large and "no such attribute: description"

2010-08-18 Thread Junkman
Hi Edson, Just curious. How big is the grammar file? Jay Edson Tirelli wrote: >Hi Jim, > >Thank you a lot for your tips. It was very helpful. > >A few comments: > ... > > 3. Thanks. As now I am getting code too large on the command line as well > when generating the grammar with

[il-antlr-interest: 29778] Re: [antlr-interest] Doubt About rewrite rulse

2010-08-10 Thread Junkman
Hi Victor, Victor Giordano wrote: > Hi, i am a newbie. Trying to figure out how to work with AST tree and > > ... > > bu if i want to use rewrite rules... how do i thread the > repetion EBNF operator like * or +. > > expr : term (('+'|'-') term)* -> term ^(('+'|'-') term)* ; > try thi

[il-antlr-interest: 29727] Re: [antlr-interest] Filtering Java expressions

2010-08-07 Thread Junkman
Hi Bill, Just throwing up a suggestion here (haven't thought it through). Lex the input, ignore comments and parse the rest into statements (ending with ';') and blocks (ending with {} block) containing statements, and then try to parse each statement as variable declarations. Would you need to

[il-antlr-interest: 29726] Re: [antlr-interest] Building a tree grammar expression to recognize arithmetic expressions

2010-08-07 Thread Junkman
Hi Alex, Alex Storkey wrote: > Hi, it's my first time posting in a mailing list like this so go easy on me > if I'm breaking some etiquette or anything :) > > I'm trying to construct an expression in my tree grammar to recognize an AST > of simple mathematical expressions like 1+(-(a-b)) in tree

[il-antlr-interest: 29718] Re: [antlr-interest] Need some help with AST creation

2010-08-06 Thread Junkman
Jim Idle wrote: > You can just do this: > > > ddd: a=TOKEN^ B C D { $a.type = INDEX; } ; > > Jim > Typical C programmer mentality. :-) Best, J List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address --

[il-antlr-interest: 29713] Re: [antlr-interest] Need some help with AST creation

2010-08-06 Thread Junkman
Hi Luis, You can try this: tokens { // Semantic tokens FIELD; INDEX; } ... fieldExpr: (atom -> atom) ( '.' identifier -> ^(FIELD $fieldExpr identifier) | '[' expr ']' -> ^(INDEX $fieldExpr expr) )* ; If you need the semantic tokens to have the input stream context d

[il-antlr-interest: 29694] Re: [antlr-interest] Tree parser eats up DOWN node when navigating optional child node

2010-08-05 Thread Junkman
Gerald Rosenberg wrote: > -- Original Message (Wednesday, August 04, 2010 5:21:33 PM) From: > Junkman -- > Subject: Re: [antlr-interest] Tree parser eats up DOWN node when navigating > optional child node >> >> You wrote "AST ^( ^( PARENT A ) B )"

[il-antlr-interest: 29671] Re: [antlr-interest] Tree parser eats up DOWN node when navigating optional child node

2010-08-04 Thread Junkman
Gerald Rosenberg wrote: > As best I understand your questions, the answers are no, no, and no . . . > > Given an input "PAB", your given parser will construct an AST ^( ^( > PARENT A ) B ) and your given tree grammar will likewise match that. > Actually, I don't think I understood you. You wr

[il-antlr-interest: 29668] Re: [antlr-interest] Tree parser eats up DOWN node when navigating optional child node

2010-08-04 Thread Junkman
Thanks for the replies, Jim & Gerald. Your responses and some more testing suggests the following to me: 1. I cannot nest a tree parser rule ("inner rule") in another rule ("outer rule"), and try to have the outer rule match additional nodes in the subtree matched by the inner rule. 2. Consequen

[il-antlr-interest: 29657] [antlr-interest] Tree parser eats up DOWN node when navigating optional child node

2010-08-03 Thread Junkman
Greetings, I am seeing an interesting behavior in generated tree parsers. This is an example grammar fragment: tree grammar TTreeParser; ... parent: ^(parent_a B?) ; parent_a: ^(PARENT A?) ; The intent i

[il-antlr-interest: 29454] Re: [antlr-interest] Custom AST node type - guidance needed

2010-07-19 Thread Junkman
Hi Bill, You have import antlr.*; instead of import org.antlr.runtime.*; Maybe that's the problem? org.antlr.runtime.CommonToken implements org.antlr.runtime.Token, so explicit casting seems out of wack. Jay Bill Andersen wrote: > Thanks John > > Below is my class def.. Eclipse tells me

[il-antlr-interest: 29211] [antlr-interest] Antlrworks with Python-like grammar

2010-06-18 Thread Junkman
Hello, I have a parser grammar that relies on a custom TokenStream - quite like the Python grammar posted on the Antlr website that relies on PythonTokenStream.java. I am wondering if there is a way to run/debug the parser in AntlrWorks - it would be nice if I can make use of AntlrWorks' debugger

[il-antlr-interest: 29159] Re: [antlr-interest] Multiple lexer tokens per rule

2010-06-08 Thread Junkman
In case anyone reads this thread again, Antlr wiki has a better example for emitting multiple tokens: http://www.antlr.org/wiki/pages/viewpage.action?pageId=3604497 Cheers. Junkman wrote: > Ken Williams wrote: >> >> On 6/4/10 4:16 PM, "Junkman" wrote: >>> Th

[il-antlr-interest: 29133] Re: [antlr-interest] Parsing whole-line comments?

2010-06-06 Thread Junkman
Christian Convey wrote: >> >> /* Tokens */ >> NEWLINE: '\n' ; >> E: 'E'; >> C: 'C'; >> CALL: 'CALL'; >> // default greediness ensures "CALL" is matched as CALL instead of C. > > Thanks, but 'C' can also be the name of a variable, as long as it's > not in the first column. So I

[il-antlr-interest: 29131] Re: [antlr-interest] Parsing whole-line comments?

2010-06-06 Thread Junkman
It's probably better to keep lexer simple - just convert character stream into a token stream - and push contextual constraints like "beginning of the line" into parsing rules, like this: /* Tokens */ NEWLINE: '\n' ; E: 'E'; C: 'C'; CALL: 'CALL'; // default greediness ensures "C

[il-antlr-interest: 29127] Re: [antlr-interest] Multiple lexer tokens per rule

2010-06-04 Thread Junkman
Ken Williams wrote: > > > On 6/4/10 4:16 PM, "Junkman" wrote: >> The way nextToken() is overriden, it first returns the token matched by >> the rule, and subsequently any additional queued token before matching a >> new token in the input stream. > &

[il-antlr-interest: 29125] Re: [antlr-interest] Multiple lexer tokens per rule

2010-06-04 Thread Junkman
Ken Williams wrote: > > > On 6/4/10 2:53 PM, "Jim Idle" wrote: > >> You need to use a collection that gives out the entries in the order they >> were >> added: >> >> http://java.sun.com/docs/books/tutorial/collections/interfaces/queue.html > > I don't think that's the issue here, there's only

[il-antlr-interest: 29115] Re: [antlr-interest] Multiple lexer tokens per rule

2010-06-03 Thread Junkman
Try this to get you started: - @lexer::members { // Queue to hold additional tokens private java.util.Queue tokenQueue = new java.util.LinkedList(); // Include queue in reset(). public void reset() { super.reset();

[il-antlr-interest: 29112] [antlr-interest] '%' in action (bug?)

2010-06-03 Thread Junkman
Greetings, The following grammar generates invalid string template error (146): - grammar Test; @lexer::members { int x = 1234 \% 1; } TOKEN : 'bogus' ; stmt: ( . )+ ; - For @lexer::members

[il-antlr-interest: 29072] Re: [antlr-interest] Comments, EOF, and Debugger

2010-06-01 Thread Junkman
Disclaimer: I'm a noob. :) Taking the newline out of comment seems to work, like this: COMMENT : '#' (~( '\r' | '\n' ))* ; NEWLINE : '\r'? '\n' { // kick it off to the hidden channel // $channel=HIDDEN; // or skip it altogether

[il-antlr-interest: 29030] Re: [antlr-interest] greedy subrule option idiom

2010-05-28 Thread Junkman
thing very basic in the grammars above. I did a quick search of the list archive using the MarkMail link Jim provided, and did find a recent thread on non-greedy loop, but it concerns suggestion for v4 and not sure it's directly applicable to this question. Sorry if it seems like I'm bea

[il-antlr-interest: 29023] Re: [antlr-interest] greedy subrule option idiom

2010-05-27 Thread Junkman
o error. Is this the expected behavior? Is there a problem with the grammar given above? Thanks for any insight/assistance. J Junkman wrote: > Hello, > > Following is a lexer rule to match quoted string that allows backslash > escape sequence. > > > STRING > :

[il-antlr-interest: 29006] [antlr-interest] greedy subrule option idiom

2010-05-26 Thread Junkman
Hello, Following is a lexer rule to match quoted string that allows backslash escape sequence. STRING :'"' ( options {greedy=false;} : ( ~ '\\' | '\\' . ) )* '"' ; It seems to work. But if you put the '*' operator inside the subrule like this: STRING :

[il-antlr-interest: 28994] Re: [antlr-interest] Dynamic scope for lexer rule

2010-05-25 Thread Junkman
in Antlr. Junkman Jim Idle wrote: > Scopes are not supported for lexer rules, you need to implement your own > things to do this, but try to leave any kind of context out of the lexer if > you can. You want to push such things as high up the tool chain as you can. > IT isn'

[il-antlr-interest: 0] Re: [antlr-interest] Dynamic scope for lexer rule

2010-05-24 Thread Junkman
d attributes allowed for lexer rules? If so, what is the error in the grammar above? Thanks for any assistance. Junkman Junkman wrote: > Greetings, > > I've added an attribute with dynamic scoping to a lexer rule, and when > generating code, I'm encountering an "intern

[il-antlr-interest: 28966] [antlr-interest] Dynamic scope for lexer rule

2010-05-22 Thread Junkman
Greetings, I've added an attribute with dynamic scoping to a lexer rule, and when generating code, I'm encountering an "internal error". Listed below is partial call stack reported: error(10): internal error: Junkscript.g : java.lang.NullPointerException org.antlr.grammar.v2.DefineGramm

[il-antlr-interest: 28939] Re: [antlr-interest] Referencing attributes

2010-05-20 Thread Junkman
Sorry for dupe, but I'm hoping to get some/any response. Are attribute reference allowed outside actions and action-like elements (e.g., semantic predicates), other than as parameters in rule invocation? Thanks for any info. J Junkman wrote: > Greetings, > > I'm a Ant

[il-antlr-interest: 28914] [antlr-interest] Referencing attributes

2010-05-19 Thread Junkman
Greetings, I'm a Antlr noob, and have a question regarding accessing attributes. Where, outside of action, can you reference attributes? One place seems to be as parameter to rule invocation like this: decl: type declarator[ $type.text ] ';' ; This is from The Definitive Antlr Reference, pag