[antlr-interest] Parse rule to add multiple homogeneous branches under a root node?
Stephan Opfer
stephan.opfer at gmx.net
Thu May 10 07:29:29 PDT 2012
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> 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
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
More information about the antlr-interest
mailing list