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 [[email protected]]
Sent: Thursday, May 26, 2011 5:56 PM
To: Patrick Hofman
Cc: [email protected]
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 
<[email protected]<mailto:[email protected]>> wrote:
And now the grammar

From: Patrick Hofman
Sent: donderdag 26 mei 2011 15:35
To: [email protected]<mailto:[email protected]>
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



List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to