[antlr-interest] how to print input statement when it is matched with grammar rule

Gavin Lambert antlr at mirality.co.nz
Mon Sep 15 14:13:49 PDT 2008


At 04:20 16/09/2008, harshada gune wrote:
>Suppose I am having following grammar rule;
>
>stmt : LHS '=' RHS ;
>Now when input statement matches this rule, I want to print the 
>input statement or use it in some another way(Say I want to save 
>it).

stmt : LHS '=' RHS { System.out.println("LHS = " + $LHS.text + ", 
RHS = " + $RHS.text); };

OR

stmt : l=LHS '=' r=RHS { System.out.println("LHS = " + $l.text + 
", RHS = " + $r.text); };



More information about the antlr-interest mailing list