[il-antlr-interest: 26616] Re: [antlr-interest] [antlr-dev] Antlr Tree programming

2009-11-03 Thread Indhu Bharathi
Moving this to antlr-interest. What you do after that depends on what you want. Have you constructed an AST in the grammar? Then to get the AST, you have to do this: CommonTree t = (CommonTree)r.getTree(); And if you want to give this tree to a tree walker, you can do this: //

[il-antlr-interest: 26617] Re: [antlr-interest] [antlr-dev] Antlr Tree programming

2009-11-03 Thread Indhu Bharathi
I guess this article might help you: http://www.antlr.org/wiki/display/ANTLR3/Tree+construction It has a good test rig. Cheers, Indhu From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Indhu Bharathi Sent: Tuesday, November 03, 2009 3

[il-antlr-interest: 26577] Re: [antlr-interest] Please help with a grammar issue

2009-10-30 Thread Indhu Bharathi
Maybe you can use validating semantic predicate r @init { int cntA=0, cntB=0, cntC=0; } : ( a {cntA++;} | b {cntB++;} | c {cntC++;} )+ {cntA1 cntB=1 cntC==1}? ; Cheers, Indhu S7 Software From:

[il-antlr-interest: 26579] Re: [antlr-interest] Please help with a grammar issue

2009-10-30 Thread Indhu Bharathi
-Original Message- From: Frank Du [mailto:frank...@riskmetrics.com] Sent: Friday, October 30, 2009 10:38 PM To: Indhu Bharathi; antlr-inter...@antlr.org Subject: RE: [antlr-interest] Please help with a grammar issue Hi Indhu, Thank you so much! It works pretty well on correct input file

[il-antlr-interest: 26581] Re: [antlr-interest] How to create many AST trees from one rule

2009-10-30 Thread Indhu Bharathi
Use scope variables to remember what you saw in a rule and emit it in another rule further down in the chain. This will create the tree you want. But I feel 'TYPE' node is not needed. It is good to build your AST as terse as possible. grammar Test; options { output=AST; }

[il-antlr-interest: 26482] Re: [antlr-interest] Can some body give me the very simplest example of grammar to AST to St ringTemplate output

2009-10-23 Thread Indhu Bharathi
Section 9.6 of ANTLR definitive reference (Building a Java Bytecode Generator Using a Tree Grammar and Templates) does this. The free code samples are available at http://media.pragprog.com/titles/tpantlr/code/tpantlr-code.tgz Samples for this specific section is available at

[il-antlr-interest: 26307] Re: [antlr-interest] How do I output an alert box or something in the console in ANTLRWorks , in grammar actions?

2009-10-16 Thread Indhu Bharathi
Sustem.out.println will print in the output tab. From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Naveen Chawla Sent: Friday, October 16, 2009 4:21 PM To: antlr-inter...@antlr.org Subject: [antlr-interest] How do I output an alert box or something

[il-antlr-interest: 26259] Re: [antlr-interest] How to do not in a syntactic predicate?

2009-10-14 Thread Indhu Bharathi
The other say I replied from my ipod and was not able to test it with ANTLR. I checked it now and the code doesn't work for me too. However you can try a variant: q : a ((b)=NOWAY | /*nothing*/) ; fragment NOWAY : ;

[il-antlr-interest: 26263] Re: [antlr-interest] How to do not in a syntactic predicate?

2009-10-14 Thread Indhu Bharathi
parsing some very obscure languages. Cheers, Indhu From: Naveen Chawla [mailto:naveen.c...@googlemail.com] Sent: Wednesday, October 14, 2009 11:38 PM To: Indhu Bharathi Cc: Jim Idle; antlr-inter...@antlr.org Subject: Re: [antlr-interest] How to do not in a syntactic predicate? Yikes

[il-antlr-interest: 26223] Re: [antlr-interest] caseSensitive = false in C taget ??

2009-10-13 Thread Indhu Bharathi
AFAIK, there is no shortcut. You will have to write something like HELLO : ( ('H'|'h') ('E'|'e') ('L'|'l') ('L'|'l') ('O'|'o') ) ; You can make it more readable using fragments. HELLO : H E L L O fragment H: ('H'|'h') fragment E: ('E'|'e') fragment L: ('L'|'l') fragment

[il-antlr-interest: 26226] Re: [antlr-interest] bison/yacc to antlr; antlr pretty printer.

2009-10-13 Thread Indhu Bharathi
http://www.antlr.org/share/list has bison to ANTLR converter. I guess this should work fine for YACC grammars. Cheers, Indhu -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of postmaster Sent: Tuesday, October 13, 2009 8:44

[il-antlr-interest: 26233] Re: [antlr-interest] accepting nested code blocks

2009-10-13 Thread Indhu Bharathi
Balanced parenthesis cannot be expressed using regular expression which means you cannot recognize it using lexer. You need a push down automata which means you need a parser to recognize it. Try doing it using parser rules. Cheers, Indhu From: antlr-interest-boun...@antlr.org

[il-antlr-interest: 26236] Re: [antlr-interest] accepting nested code blocks

2009-10-13 Thread Indhu Bharathi
to allow catching it by a lexer rule? Cheers, Miklos 2009/10/13 Indhu Bharathi indh...@s7software.com: Balanced parenthesis cannot be expressed using regular expression which means you cannot recognize it using lexer. You need a push down automata which means you need a parser to recognize it. Try

[il-antlr-interest: 26238] Re: [antlr-interest] accepting nested code blocks

2009-10-13 Thread Indhu Bharathi
, Indhu -Original Message- From: Espák Miklós [mailto:esp...@gmail.com] Sent: Tuesday, October 13, 2009 11:11 PM To: Indhu Bharathi Cc: antlr-inter...@antlr.org Subject: Re: [antlr-interest] accepting nested code blocks Hi, I understand your point of view, but the book states explicitly

[il-antlr-interest: 26239] Re: [antlr-interest] ANTLRWorks question

2009-10-13 Thread Indhu Bharathi
Prefer using debugger instead of interpreter. Interpreter doesn't work as expected sometimes (when you are using semantic predicates). That said, for this particular case it seems to works fine. r : STRING ; STRING : '' (

[il-antlr-interest: 26202] Re: [antlr-interest] [LEXER] Unwanted behaviour ?

2009-10-12 Thread Indhu Bharathi
Can you post a small sample where the problem exists? -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Martin Potier Sent: Monday, October 12, 2009 5:44 PM To: antlr-inter...@antlr.org Subject: [antlr-interest] [LEXER]

[il-antlr-interest: 26204] Re: [antlr-interest] MismatchedTokenException in loop

2009-10-12 Thread Indhu Bharathi
problem, I’m not sure if this is an elegant way of fixing this problem. I would vote for parser checking only the syntax and the symantics handled by tree walkers. You can establish the relation between messages while tree walking. Cheers, Indhu Bharathi http://www.s7software.com/ S7

[il-antlr-interest: 26164] Re: [antlr-interest] Whitespace question

2009-10-09 Thread Indhu Bharathi
Try something like r : lbl=searchTerm ({spaceFollows($lbl.stop)}?= lbl=searchTerm)* ; @members { public boolean spaceFollows(Token tkn) { return input.get(tkn.getTokenIndex()+1).getType()==WS; } } Cheers, Indhu Bharathi http

[il-antlr-interest: 26083] Re: [antlr-interest] Out of Memory

2009-10-05 Thread Indhu Bharathi
Is it possible to write a separate program to break the PGN files into separate games and pass each game to the lexer/parser? That will be a simple solution assuming there is an easy way to split games in a PGN file. -Original Message- From: antlr-interest-boun...@antlr.org

[il-antlr-interest: 26089] Re: [antlr-interest] How to do not in a syntactic predicate?

2009-10-05 Thread Indhu Bharathi
Try something like: (a)= ((b)=/*nothing*/ | a) I remember facing similar problem. I guess you can't use '~' in a syntactic predicate. From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Naveen Chawla Sent: Monday, October 05, 2009 7:32 PM

[il-antlr-interest: 26090] Re: [antlr-interest] A wish

2009-10-05 Thread Indhu Bharathi
ANTLRWORKS already has this feature. Compile your grammar in ANTLRWORKS. When there is an ambiguity, the rule will be marked in red and you can check the Syntax diagram tab to graphically see the ambiguity. From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On

[il-antlr-interest: 25995] Re: [antlr-interest] StringTemplate to generate Grammar docs?

2009-09-29 Thread Indhu Bharathi
Try the tool 'strip'. It comes with ANTLR. From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Jonathan Claggett Sent: Tuesday, September 29, 2009 3:41 AM To: antlr-inter...@antlr.org Subject: [antlr-interest] StringTemplate to generate Grammar

[il-antlr-interest: 25929] Re: [antlr-interest] Recover grammar file from generated code?

2009-09-25 Thread Indhu Bharathi
I don't think if any tool exists to do it automatically. But the generator adds the grammar also as comments into the generated lexer/parser. You can manually go through it and recover the grammar. -Original Message- From: antlr-interest-boun...@antlr.org

[il-antlr-interest: 25900] Re: [antlr-interest] Howto modify token creation?

2009-09-24 Thread Indhu Bharathi
You can do something like ID : LETTER (LETTER|DIGIT)* { String text = getText(); Integer tknType; if( (tknType=table.get(text))!=null ) { $type = tknType; } } The table can be passed to

[il-antlr-interest: 25911] Re: [antlr-interest] Question with greedy

2009-09-24 Thread Indhu Bharathi
'!' is a rewrite operator used in tree construction. Since lexer doesn't construction a tree, I don't think this will work. -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Gordon Tyler Sent: Thursday, September 24, 2009

[il-antlr-interest: 25837] Re: [antlr-interest] Error: Declared package doesn't match expected package

2009-09-19 Thread Indhu Bharathi
Check if you are creating the lexer/parser under the right directories. Look like the files are getting generated at root level in source tree. On Sep 19, 2009, at 9:28 AM, Sailesh Kandula skand...@asu.edu wrote: While building my first ANTLR project SimpleCalc.g i ran into the error:

[il-antlr-interest: 25780] Re: [antlr-interest] About API in ANTLRWorks

2009-09-16 Thread Indhu Bharathi
A related mail from archive: you mean a parse tree, not AST, right? There is a ParseTreeBuilder i think. T On Sep 1, 2009, at 12:50 PM, Stefan Groschupf wrote: Hi, I'm making my first baby with antlr. Is there any chance to get a AST exactly as antlr work is generating

[il-antlr-interest: 25701] Re: [antlr-interest] Optimized code generation

2009-09-11 Thread Indhu Bharathi
the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it! _ From: Indhu Bharathi [mailto:indh...@s7software.com] Sent: Thursday, September 10, 2009 10:37 PM To: r.bhar...@huawei.com; 'antlr

[il-antlr-interest: 25695] Re: [antlr-interest] Optimized code generation

2009-09-10 Thread Indhu Bharathi
Yes, backtracking will affect performance. If you are concerned about performance, don't use backtrack and try left factoring your grammar instead. From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Bharath R Sent: Thursday, September 10, 2009 5:25

[il-antlr-interest: 25677] Re: [antlr-interest] Grammar inclusion

2009-09-09 Thread Indhu Bharathi
I guess you can do it with composite grammars. -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Martin Potier Sent: Wednesday, September 09, 2009 7:10 PM To: antlr-inter...@antlr.org Subject: [antlr-interest] Grammar

[il-antlr-interest: 25597] Re: [antlr-interest] ANTLR debug error

2009-09-04 Thread Indhu Bharathi
What exactly is the error message you get? On Sep 4, 2009, at 12:57 PM, Klaus Martinschitz klausmartinsch...@gmx.at wrote: Hi! I already looked around in the internet and do not find any answer to solve following problem. I downloaded the newest antlr works version 1.2.3 were antlr and

[il-antlr-interest: 24159] Re: [antlr-interest] Excluding keywords

2009-06-10 Thread Indhu Bharathi
As stated in the link you provided, there is nothing you have to do to get this functionality. But 'identifier' should be a lexer rule. I guess your grammar should be something like this: APPLY : 'apply'; BROWSE : 'browse' . ID

[il-antlr-interest: 24106] Re: [antlr-interest] Newbie grammar question...

2009-06-08 Thread Indhu Bharathi
I don't get any exception. BTW, it is good to match the entire 'phrase' as one token in the lexical analysis itself. Something like: PHRASE :( '0'..'9' | 'A'..'Z' | ' ' | '\t')+ ; and modify stmt to: stmt :SUBJ_TOK COLON PHRASE NL+ ; Else, you'll end up creating too

[il-antlr-interest: 24118] Re: [antlr-interest] newbie grammar question

2009-06-08 Thread Indhu Bharathi
SL_COMMENT_2 : '--' (options {greedy=false;} : . )* '\n' {$channel=HIDDEN;} { setText( // + getText().substring(2) ); } ; Should work. -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org]

[il-antlr-interest: 24123] Re: [antlr-interest] Bug in AntlrWorks debugger

2009-06-08 Thread Indhu Bharathi
ANTLRWORKS accepts tab in input box without any problem. The version I'm using is 1.2.3 -Original Message- From: antlr-interest-boun...@antlr.org [mailto:antlr-interest-boun...@antlr.org] On Behalf Of Dukie Banderjee Sent: Tuesday, June 09, 2009 12:45 AM To: antlr-inter...@antlr.org

[il-antlr-interest: 24029] Re: [antlr-interest] How to f orce ANTLR 3.1.2 to raise exceptions on invalid tokens?

2009-06-04 Thread Indhu Bharathi
By default error recovery is turned on and ANTLR will try to recover from syntax errors. However it will print error message on stderr. If you need error recovery to be turned off and throw an exception at the first sight of an error, you need to override 'recoverFromMismatchedToken' as shown

[il-antlr-interest: 23990] Re: [antlr-interest] Grammer file queries...

2009-06-03 Thread Indhu Bharathi
For your second and third question, solution is to use 'composite grammar'. You'll be able to extend the existing grammar file. You can also form a grammar by combining multiple .g files. One file might contain the lexer and the parser itself could be spread across multiple grammar files. There is

[il-antlr-interest: 23998] Re: [antlr-interest] Inconsistent Parse Results

2009-06-03 Thread Indhu Bharathi
That is an expected behavior. Seeing ' C' the lexer decides to go for 'CORP' token instead of OTHER(space) and WORD. You need to do some left factoring there. Or you can modify your grammar to avoid such problems. Here is a suggested correction: grammar Test ; test1 : NUMBER CORP data

[il-antlr-interest: 23884] Re: [antlr-interest] I want to throw an exception and stop parse, please!

2009-05-25 Thread Indhu Bharathi
Ah, forgot. Things changed after the book was written. I guess you have to override the following two methods from BaseRecognizer void recover (IntStream input, RecognitionException re) Object recoverFromMismatchedSet (IntStream input, RecognitionException e, BitSet follow) throws

[il-antlr-interest: 23882] Re: [antlr-interest] I want to throw an exception and stop parse, please!

2009-05-24 Thread Indhu Bharathi
Two methods of parser (mismatch and recoverFromMismatchedSet) are responsible for auto-recovery and showing error messages. If you want to throw an exception and exit right on the first error you need to override these methods and just throw the exception instead of handling it. Something like

[il-antlr-interest: 23741] Re: [antlr-interest] Lexer matching non-matching rule

2009-05-15 Thread Indhu Bharathi
This is because on seeing 'f' of foo lexer has two options - 1. IDENT 2. URL. And it takes the second options since that seems to be longer that the first alternative. Note that the lexer always tries to match the longest token possible. After having decided to go for URL, it matches the

[il-antlr-interest: 23603] Re: [antlr-interest] Whitespace issues

2009-05-08 Thread Indhu Bharathi
Looks like a lot of work that has to be done in the lexer is getting done in the parser. I would prefer tokenizing '[%"Dear "%]' as a separate token and similarly '[% name %]' as a separate token. Simple substring, trim operations can get you the actual block and string content later. Here

[il-antlr-interest: 23596] Re: [antlr-interest] Sometimes significant new lines

2009-05-07 Thread Indhu Bharathi
Did you evaluate the option of making semicolon a default token itself instead of hidden token? Unless there is compelling reason to make semicolon hidden token, let's make it default token. That will make the work easy. Now assuming there is some compelling reason to make semicolon hidden

[il-antlr-interest: 23498] Re: [antlr-interest] Tuning parser to non-default channel

2009-05-04 Thread Indhu Bharathi
It is true that the parser can 'tune' to any channel. But you can't do it while parsing. The channel should be set before parsing begins. If you want to see the off channel token while parsing, you can use LA( int ) and LT( int ) within the parser. For your example, you can write something

[il-antlr-interest: 23192] Re: [antlr-interest] Unexpected CommonTokenStream.Size() result in CSharp runtime

2009-04-16 Thread Indhu Bharathi
This is expected behavior only. It is designed this way so that user can filter for a particular channel if needed. For your task, you can use getTokens() method which will return a List of tokens that can be iterated. Cheers, Indhu Chris Lambrou wrote: Yesterday I was stung by some odd

[il-antlr-interest: 23057] Re: [antlr-interest] discrepancy between antlrworks and antlr generated parser

2009-04-09 Thread Indhu Bharathi
WS: (' ' | '\n' | '\r' )+ {$channel=HIDDEN}; This should give you compile error. There must be a ';' immediately after 'HIDDEN'. ( {$channel=HIDDEN;} ) Are you using tab instead of space in input? David Cournapeau wrote: Hi, I have started using antlr to catch up my lack of knowledge in

[il-antlr-interest: 23076] Re: [antlr-interest] Inject Lexer Tokens before parsing further

2009-04-09 Thread Indhu Bharathi
Curious. Why not change formula production to formula : EQ expression | expression ; If for some reason you want to enforce that the input has to start with PLUS or MINUS then maybe you can rewrite formula production as formula : EQ expression | (PLUS | MINUS)= expression ;

[il-antlr-interest: 23078] Re: [antlr-interest] Inject Lexer Tokens before parsing further

2009-04-09 Thread Indhu Bharathi
a rough solution which is to Pre-parse the text and then change the text to =-5+4 and then pass the new text to the second parser, but I was wondering if there is a more elegant solution Thanks Des 2009/4/10 Indhu Bharathi indh...@s7software.com mailto:indh...@s7software.com

[il-antlr-interest: 23080] Re: [antlr-interest] Inject Lexer Tokens before parsing further

2009-04-09 Thread Indhu Bharathi
the whole expression to expression? Thanks Des 2009/4/10 Indhu Bharathi indh...@s7software.com mailto:indh...@s7software.com Well, in that case the second solution that uses syntactic predicate should work. Des Hartman wrote: Indhu This is based on how users enter

[il-antlr-interest: 23047] Re: [antlr-interest] [antlr-dev] Why doesn't this work?

2009-04-08 Thread Indhu Bharathi
:; fragment FLOAT_LIT :; fragment INT_LIT :; fragment NUMBER:('0'..'9')+ ; fragment LETTER:'a'..'z' ; Thanks, Indhu Jim Idle wrote: Indhu Bharathi wrote: Yes, I've read that page earlier and I understand it (and that is how I've solved

[il-antlr-interest: 23051] Re: [antlr-interest] Why doesn't this work?

2009-04-08 Thread Indhu Bharathi
, Indhu Bharathi wrote: INT_FLOAT_PATTERN :(NUMBER DOT NUMBER LETTER ) = NUMBER DOT NUMBER LETTER { $type=PATTERN; } |( NUMBER DOT NUMBER ) = NUMBER DOT NUMBER { $type=FLOAT_LIT; } |(NUMBER) = NUMBER { $type=INT_LIT; } ; I'm not sure why

[il-antlr-interest: 23053] Re: [antlr-interest] simple arithmetic counter

2009-04-08 Thread Indhu Bharathi
Use '@members' to store 'global' variables. like @members{ int cnt; } and increase 'cnt' in 'species' production, like species : ret=atom NUMBER? { cnt += $ret.weight * Integer.parseInt($NUMBER.text) } ; and print out the sum in file production, like file

[il-antlr-interest: 23026] [antlr-interest] Why doesn't this work?

2009-04-07 Thread Indhu Bharathi
I was working in a big grammar and stumbled on a problem with predicates. I've simplified the problem as much as possible and here it is: When I give the input 1., I expect the tokens INT_LIT, DOT. But what I get is No viable alternative at character 'EOF'. I'm not able to understand why this

[il-antlr-interest: 23035] Re: [antlr-interest] Why doesn't this work?

2009-04-07 Thread Indhu Bharathi
Hi, Any clue why this doesn't work? I'm still clueless. - Indhu Indhu Bharathi wrote: I was working in a big grammar and stumbled on a problem with predicates. I've simplified the problem as much as possible and here it is: When I give the input 1., I expect the tokens INT_LIT, DOT

[il-antlr-interest: 23015] Re: [antlr-interest] A Simple Question on Channels

2009-04-04 Thread Indhu Bharathi
'expression' is rule 'r' wont return a Token since it is not a lexer rule. It will instead return 'ParserRuleReturnScope' since it is a parser rule. So '$expression.stop' or '$t.stop' will give you the last token of 'expr'. You can use it like shown below: r : t=expression {

[il-antlr-interest: 22975] Re: [antlr-interest] Composite grammar and memoize

2009-04-02 Thread Indhu Bharathi
Of Indhu Bharathi Sent: Thursday, April 02, 2009 10:58 PM To: antlr-interest Subject: [antlr-interest] Composite grammar and memoize Hi, It looks like memoize at rule level doesn't work in composite grammar. I get the error message '! memo array is null for ParserPart.g'. 'state.ruleMemo

[il-antlr-interest: 22978] Re: [antlr-interest] A Simple Question on Channels

2009-04-02 Thread Indhu Bharathi
I don't have ANTLR right now to test this. But guess it would work NEWLINE: '\r'?'\n' {$channel = HIDDEN;}; Then write expression_statement rule like this: expression_statement :expression { NewLineBeforeNextToken( input.LT(1) ) }?= /*nothing*/ ; And in the

[il-antlr-interest: 22909] Re: [antlr-interest] how to best break apart multiple assignments

2009-04-01 Thread Indhu Bharathi
How about something like this? r:(ID EQ)+ INTLIT SEMICOLON - ^(ASSIGN ID INTLIT)+ ; So, for your example, this will create two subtrees with ASSIGN as root. The tree generated will be ^(nil ^(ASSIGN Odd 0) ^(ASSIGN Even 0)) And then you can write string template in the tree walker

[il-antlr-interest: 22910] Re: [antlr-interest] Handling wiki-style plain text with optional markup?

2009-04-01 Thread Indhu Bharathi
Take a look at 'filter' mode of ANTLR lexer. This will let you skip text you are not interested in. Posting a more specific example of what you need might help. Peter Bertok wrote: I'm working on a trivial embedded wiki style content management system for a web project, and I'm trying

[il-antlr-interest: 22780] [antlr-interest] Is this possible?

2009-03-26 Thread Indhu Bharathi
Can 'dfa.predict' throw 'no viable alternative' exception? I'm facing this strange problem and wondering what could be the reason. Any pointers? Thanks, Indhu List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe:

[il-antlr-interest: 22799] Re: [antlr-interest] Problem with rewrite rules with optional non-terminals

2009-03-26 Thread Indhu Bharathi
Jim Idle wrote: Andreas Meyer wrote: David Jameson schrieb: I have the following grammar fragment refTag : LSQUARE a=expression (COMMA b=expression)? RSQUARE { //stuff } - ^(REFTAG $a $b)

[il-antlr-interest: 22684] Re: [antlr-interest] How can I avoid mismatched input error?

2009-03-24 Thread Indhu Bharathi
Looks like you are trying to use keyword as identifier. AFAIK, this cannot be resolved in the lexer. You have to use predicates in the parser rule. Something like this: rule : keyKEYWORD1 (keyKEYWORD2 enc=Name)? ';' ; keyKEYWORD1 :{input.LT(1).getText().equals(keyword1)}? Name ;

[il-antlr-interest: 22689] Re: [antlr-interest] How can I avoid mismatched input error?

2009-03-24 Thread Indhu Bharathi
On Tue, Mar 24, 2009 at 9:29 AM, Indhu Bharathi indh...@s7software.com mailto:indh...@s7software.com wrote: Looks like you are trying to use keyword as identifier. AFAIK, this cannot be resolved in the lexer. You have to use predicates in the parser rule. Something like

[il-antlr-interest: 22715] Re: [antlr-interest] Can TokenRewriteStream be applied to rules?

2009-03-24 Thread Indhu Bharathi
This will work: variableStatement : VAR? variableDeclaration ( COMMA m=variableDeclaration )* semic {tokens.replace($m.start, $m.end, something else);} n bsp; ; $m will be of type variableDeclaration_return which will be subclass of 'ParserRuleReturnScope'. $m is not Token. - Indhu YINGAnnie

[il-antlr-interest: 22719] Re: [antlr-interest] Can TokenRewriteStream be applied to rules?

2009-03-24 Thread Indhu Bharathi
Maybe 'm=variableDeclaration' didn't match anything in the input... YINGAnnie wrote: Sorry ,Iforgot to mention, Icorrected $m.end. Now, I am using {tokens.replace($m.start, $m.stop, something else);} but I got java.lang.NullPointerException error. It seems $m is null. Annie

[il-antlr-interest: 22625] Re: [antlr-interest] Order independent keywords

2009-03-22 Thread Indhu Bharathi
Maybe you are looking for something like this: attributes :attribute+ ; attribute :typeAttr |lengthAttr |pathAttr ; Here is a complete sample: grammar Test; attributes :attribute+ ;

[il-antlr-interest: 22626] Re: [antlr-interest] Order independent keywords

2009-03-22 Thread Indhu Bharathi
); } } :attribute+ ; typeAttr:'TYPE' ID ';' { $attributes::typeAttrSeen = true; } ; - Indhu Indhu Bharathi wrote: Maybe you are looking for something like this: attributes :attribute+ ; attribute

[il-antlr-interest: 22601] Re: [antlr-interest] how to all the matched in java

2009-03-21 Thread Indhu Bharathi
grammar Test; expr : (ID {System.out.println( $ID.text );} )* ; ID : 'a'..'z'+ ; WS : (' ' | '\t' | '\n')+ {$channel = HIDDEN;} ; - Indhu william yuan wrote: Hi , problem like this , i ve defined a grammar like this expr: ID*; ID:('a'..'z')*; and my input is ABC DEF so how can i

[il-antlr-interest: 22531] Re: [antlr-interest] no viab le alternative at character error for '; ' and ',' in a wild cast

2009-03-18 Thread Indhu Bharathi
Hi, The problem is because ',' or '=' is not defined anywhere in the lexer rule. To be able to lex an input completely, it is necessary that the lexer grammar must account for every character that can occur in the input and be able to convert it into tokens. If you dont want to intoduce these

[il-antlr-interest: 22471] [antlr-interest] Passing RuleReturnScope as argument

2009-03-16 Thread Indhu Bharathi
Hi, Is it not possible to pass an instance of RuleReturnScope as argument to a function? With the following sample, I get the error message 'missing attribute access on rule scope'. Curious to know the reason for this limitation... or am I missing something? Is there a workaround? foo :

[il-antlr-interest: 22363] Re: [antlr-interest] grammar inheritance

2009-03-10 Thread Indhu Bharathi
grammar SqlSQL2Parser; options { superClass=DmlSQL2Parser; } - Indhu - Original Message - From: Maciej Gawinecki mgawine...@gmail.com To: ANTLR Interest Mailing List antlr-inter...@antlr.org Sent: Tuesday, March 10, 2009 12:29:52 PM GMT+0530 Asia/Calcutta Subject: [antlr-interest]

[il-antlr-interest: 22364] Re: [antlr-interest] DMQL Grammar - ANTLR Eats Characters

2009-03-10 Thread Indhu Bharathi
Try this: Today: ( (Today_) = 'Today' ) ; fragment Today_ : 'Today' ; However, I'm not sure if this's the most elegant way to fix it. Read the following thread to understand more on why exactly this happens: http://www.antlr.org/pipermail/antlr-interest/2009-February/032959.html -

[il-antlr-interest: 22263] Re: [antlr-interest] Seperating grammar and actions

2009-03-05 Thread Indhu Bharathi
%21+Tree+pattern+matching%2C+rewriting+a+reality . This sounds damn sexy! But has this been released? Does the latest release (3.1.2) include this? Thanks, Indhu - Original Message - From: Sam Harwell sharw...@pixelminegames.com To: Indhu Bharathi indh...@s7software.com, antlr-inter

[il-antlr-interest: 22249] [antlr-interest] Seperating grammar and actions

2009-03-04 Thread Indhu Bharathi
Hi, Is there a way to separate grammar and actions into two different files? This will be helpful when multiple people are working with the same grammar file (each might write their own actions for the same production) and don't want to create redundant copies of the grammar file. One way

[il-antlr-interest: 22134] Re: [antlr-interest] Rewriting in non tree grammar

2009-02-27 Thread Indhu Bharathi
{ input.insertBefore(pos, inserted); } ; a : 'a' ; b : 'b' ; Let me know if there is a better or more elegant way to do this. But I'm fine with this :-) Thanks, Indhu - Original Message - From: Indhu Bharathi indh

[il-antlr-interest: 22149] Re: [antlr-interest] Rewriting in non tree grammar

2009-02-27 Thread Indhu Bharathi
On Feb 27, 2009, at 12:43 AM, Indhu Bharathi wrote: Figured it out :-) Here is a sample grammar that does what is required: grammar Test; @members { TokenRewriteStream input = (TokenRewriteStream) getTokenStream(); } r @init { int pos; } : a { pos = input.index

[il-antlr-interest: 22151] Re: [antlr-interest] Rewriting in non tree grammar

2009-02-27 Thread Indhu Bharathi
Bharathi indh...@s7software.com Cc: antlr-interest antlr-inter...@antlr.org Sent: Saturday, February 28, 2009 11:44:21 AM GMT+0530 Asia/Calcutta Subject: Re: [antlr-interest] Rewriting in non tree grammar label the rule refs, dude :) Ter On Feb 27, 2009, at 8:42 PM, Indhu Bharathi wrote

[il-antlr-interest: 22122] [antlr-interest] Rewriting in non tree grammar

2009-02-26 Thread Indhu Bharathi
Hi, Suppose I want to do something like this methodDecl : scope t=returnType ident LRAPEN RPAREN { insertBefore(t, something); or

[il-antlr-interest: 22131] Re: [antlr-interest] Rewriting in non tree grammar

2009-02-26 Thread Indhu Bharathi
there for this requirement. Can anybody explain a little more clear. Sorry if there is some simple way to do it and I'm not getting it. - Indhu -Original Message- From: Terence Parr [mailto:pa...@cs.usfca.edu] Sent: Friday, February 27, 2009 2:53 AM To: Indhu Bharathi Cc: 'antlr-interest

[il-antlr-interest: 22087] Re: [antlr-interest] Loosing characters when choosing a less strong alternative

2009-02-25 Thread Indhu Bharathi
attribute_type : 'unsigned long long' | 'unsigned long' ; Though you have written 'unsigned long long' and 'unsigned long' in the parser rule, they will be still considered as lexer rule only. The lexer after seeing 'unsigned long' will try to go for the bigger match ('unsigned

[il-antlr-interest: 22052] Re: [antlr-interest] quick question

2009-02-23 Thread Indhu Bharathi
A quick guess: Green: It was parsed since you had ‘backtrack’ option set and the parse was success. It will however be parsed again in black color. Red: It was parsed since you had ‘backtrack’ option set but the parse was failure. - Indhu

[il-antlr-interest: 21982] Re: [antlr-interest] Problem when parsing numerics

2009-02-18 Thread Indhu Bharathi
parser. But what your parser is expacting is NUMERIC followed by a '.'. So parsing fails. Simple. - Indhu - Original Message - From: Indhu Bharathi indh...@s7software.com To: Thomas Woelfle thomas.woel...@interactive-objects.com Cc: antlr-inter...@antlr.org, j...@temporal-wave.com Sent

[il-antlr-interest: 21983] Re: [antlr-interest] Problem when parsing numerics

2009-02-18 Thread Indhu Bharathi
at character 'EOF' - Indhu - Original Message - From: Indhu Bharathi indh...@s7software.com To: Thomas Woelfle thomas.woel...@interactive-objects.com Cc: antlr-inter...@antlr.org Sent: Wednesday, February 18, 2009 2:32:49 PM GMT+0530 Asia/Calcutta Subject: Re: [antlr-interest] Problem when

[il-antlr-interest: 21959] Re: [antlr-interest] Editor using ANTLR-Parser

2009-02-17 Thread Indhu Bharathi
: Indhu Bharathi indh...@s7software.com To: Ralf Düsedau ralf.duese...@imc-berlin.de Cc: antlr-inter...@antlr.org Sent: Tuesday, February 17, 2009 4:59:11 PM GMT+0530 Asia/Calcutta Subject: Re: [antlr-interest] Editor using ANTLR-Parser ANTLRWorks - http://www.antlr.org/works/index.html

[il-antlr-interest: 21958] Re: [antlr-interest] Editor using ANTLR-Parser

2009-02-17 Thread Indhu Bharathi
ANTLRWorks - http://www.antlr.org/works/index.html - Original Message - From: Ralf Düsedau ralf.duese...@imc-berlin.de To: antlr-inter...@antlr.org Sent: Tuesday, February 17, 2009 4:36:29 PM GMT+0530 Asia/Calcutta Subject: [antlr-interest] Editor using ANTLR-Parser Hi there, i'm new

[il-antlr-interest: 21978] Re: [antlr-interest] Lexer ambigiuoties

2009-02-17 Thread Indhu Bharathi
Looks like you are trying to do things in Lexer that actually have to be done in parser. Try keeping the bare minimum in Lexer and move other parsing logics into Parser. Can you post a small sample input you are trying to parse? - Indhu From: antlr-interest-boun...@antlr.org

[il-antlr-interest: 21520] Re: [antlr-interest] Binary data

2009-01-22 Thread Indhu Bharathi
'parseBinary' in Antlr examples folder might help you. - Indhu - Original Message - From: j...@mentics.com To: antlr-inter...@antlr.org Sent: Friday, January 23, 2009 1:51:23 AM GMT+0530 Asia/Calcutta Subject: [antlr-interest] Binary data I have data that is mixed text and binary, so

[il-antlr-interest: 21465] [antlr-interest] Highlighting syntax errors

2009-01-21 Thread Indhu Bharathi
Hi, When I parse an input in ANTLRWorks IDE, I can see which portion of the input has errors using the 'input' window in the debugger. Syntax error (handled by automatic error recovery) will be highlighted in red. While this is a very useful feature, I cannot parse a very big file (approx 1

[il-antlr-interest: 21242] [antlr-interest] Why is parsing in antlrworks slower?

2009-01-12 Thread Indhu Bharathi
Just curious. Why is parsing inside AntlrWorks (in debug) slower than parsing using a java program? Is this because of displaying the graphical parse tree or is there some other reason? - Indhu --~--~-~--~~~---~--~~ You received this message because you are

[il-antlr-interest: 21162] Re: [antlr-interest] Problem with disambiguating semantic predicates and the decision DFA

2009-01-01 Thread indhu bharathi
, Jan 1, 2009 at 4:34 PM, indhu bharathi indhubhara...@gmail.comwrote: This might not be an elegant fix. But it does fix the problem 13c13 : PROCEDURE IDENTIFIER SEMICOLON subroutineBlock SEMICOLON --- : PROCEDURE IDENTIFIER SEMICOLON subroutineBlock 17,19c17,19