[antlr-interest] Parse rule to add multiple homogeneous branches under a root node?
Peter Bosch
pbosch at highpointsoftware.com
Thu May 10 08:40:49 PDT 2012
The best answer I got (thanks, David Turvey & Stefan Mätje)
Was:
public parse
: (r+=BRANCH|r+=BRUNCH)* EOF -> ^(ROOT $r*)
;
I'm off and running into new territory, preparing my next antlr-interest
submission for your viewing pleasure. :-)
Regards, all
Pete
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Stephan Opfer
Sent: Thursday, May 10, 2012 9:29 AM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Parse rule to add multiple homogeneous
branches under a root node?
My first guess would be
public parse : branches EOF -> ^(ROOT branches);
branches: (BRANCH)*;
Does that help?
Stephan
On 05/08/2012 02:25 PM, Peter Bosch wrote:
> Okay, I've tried to boil it down to a simple test case that
> illustrates (probably in my parse rule) what I'm doing wrong. Target is
C#.
>
>
>
> //-----------------------------
>
> // TreeTestInput.txt
>
> Branch1
> Branch2
> Branch3
>
>
>
> //-----------------------------
>
> // Desired output:
>
> ROOT
>
> Branch1
>
> Branch2
>
> Branch3
>
> //-----------------------------
>
> // Actual output:
>
> ROOT
>
> Branch3
>
>
>
> //-----------------------------
>
> // TreeTest.g
>
> grammar TreeTest;
>
>
>
> options {
>
> language=CSharp3;
>
> output=AST;
>
> }
>
>
>
> tokens {
>
> ROOT;
>
> }
>
>
>
> public parse
>
> : ( r=BRANCH )* EOF -> ^(ROOT $r*)
>
> ;
>
>
>
> BRANCH
>
> : 'Branch' ('0'..'9')
>
> ;
>
>
>
> EOL : ('\r'? '\n') {$channel=Hidden;} ;
>
> WS : (' '|'\t'|'\f'| EOL)+ {$channel=Hidden;} ;
>
>
>
>
>
> Peter Bosch
> Highpoint Software Systems
> E-mail : < <mailto:pbosch at highpointsoftware.com>
mailto:pbosch at highpointsoftware.com>
> <mailto:pbosch at highpointsoftware.com> pbosch at highpointsoftware.com Phone
: 262-893-5400 P-Mail : S42 W27451
> Oak Grove Lane Waukesha, WI, 53189 Useful and Usable Decision Support
> & Technical Software
>
>
>
>
> List: <http://www.antlr.org/mailman/listinfo/antlr-interest>
http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> <http://www.antlr.org/mailman/options/antlr-interest/your-email-address>
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
List: <http://www.antlr.org/mailman/listinfo/antlr-interest>
http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
<http://www.antlr.org/mailman/options/antlr-interest/your-email-address>
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-----
No virus found in this message.
Checked by AVG - <http://www.avg.com> www.avg.com
Version: 2012.0.2171 / Virus Database: 2425/4989 - Release Date: 05/10/12
More information about the antlr-interest
mailing list