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
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
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()
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
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
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,
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
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
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
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
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
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
--
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
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 )"
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
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
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
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
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
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
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
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
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.
>
&
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
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();
Greetings,
The following grammar generates invalid string template error (146):
-
grammar Test;
@lexer::members {
int x = 1234 \% 1;
}
TOKEN : 'bogus' ;
stmt:
( . )+
;
-
For @lexer::members
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
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
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
> :
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
:
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'
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
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
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
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
35 matches
Mail list logo