[antlr-interest] question about antlr

Patrick Hofman patrick.hofman at invantive.com
Fri May 27 00:42:32 PDT 2011


Hi Bart,



The input is something like this: '$C{D,.,.,.+1} + $C{D,.,.,.+2}'



The problem is filtering out the ' + ' part of the expression. The expression goes well when I don't include the ' + ' part. In fact, this part of the expression should be copied 'as is' to the output in the end.



The grammar part that is the problem is this part I think:



eca_kolom_expressie
 : {input.LT(1).getText().equals("$"+"C")}? ECA_ID ECA_LACCOLADE draaimethode separator sheet separator column separator row ECA_RACCOLADE {System.out.println("Gaaf, draaimethode " + draaimethode); mode="EXCEL"; System.out.println("Mode = " + mode);}
 ;
excel_fragment
        : {mode.equals("EXCEL")}? EXCEL_FRAGMENT {mode="ECA"; System.out.println("Mode = " + mode);}
 ;
excel_formula
 : excel_fragment (eca_kolom_expressie excel_fragment)*
 ;

Where EXCEL_FRAGMENT is:



EXCEL_FRAGMENT
 : (options {greedy=false;} : .)
 ;

The determination of excel_formula (entry point) (specific: the EXCEL_FRAGMENT part) goes well when I put in TILDE at the start and end of EXCEL_FRAGMENT. So it looks like the greedy is too greedy. It eats up a part of eca_kolom_expressie.



Is this better for you to understand? I am a ANTLR rookie so I'm sorry when it is hard to get it right for you.



Regards,





Patrick Hofman


________________________________
From: Bart Kiers [bkiers at gmail.com]
Sent: Thursday, May 26, 2011 5:56 PM
To: Patrick Hofman
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] question about antlr

Hi Patrick,

I have a hard time understanding what it is you're trying to do.
Instead of springing the entire grammar on us (or me), could you extract only those rules that are causing the problem(s)? And could you include some example input you'd like to match/parse?

Regards,

Bart Kiers.


On Thu, May 26, 2011 at 4:04 PM, Patrick Hofman <patrick.hofman at invantive.com<mailto:patrick.hofman at invantive.com>> wrote:
And now the grammar

From: Patrick Hofman
Sent: donderdag 26 mei 2011 15:35
To: antlr-interest at antlr.org<mailto:antlr-interest at antlr.org>
Subject: question about antlr

Hi all,

I have bought the ANTLR book in order to learn ANTLR better, but I still don't get how to fix one thing. I hope you can help me with that.

I have a grammar that is used to parse our custom formula format to an Excel formula. So when filling an Excel worksheet the string entered is something like '$C{D,.,.,.+1}' which means 'one cell right from the current cell'. You will understand that eventually we will get something like '$C{D,.,.,.+1} + $C{D,.,.,.+2}', so add up the value of the first cell right and the second cell right (in Excel when we are at A1 this results in '=B1 + B2'.

The problem is this: In the grammar I cannot find a way to 'eat up' the text between two 'eca_kolom_expressie' strings (the '$C{...}' part).

I already tried 'EXCEL_FRAGMENT' in a hundred ways, but none of them seemed to work. ('TILDE (options {greedy=false;} : .) TILDE' seems to work, but when removing the TILDEs it stops working)

I have included the grammar. Can you point me in the right direction?

Regards,

Patrick Hofman
Senior Consultant
Invantive B.V.


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