[antlr-interest] Read multiple times
John B. Brodie
jbb at acm.org
Fri Mar 18 16:19:26 PDT 2011
Greetings!
On Fri, 2011-03-18 at 15:24 -0700, Hiten R wrote:
> Hi everyone,
>
> I have a very simple problem described below and I don`t have a best way to
> solve it. The idea is to parse values in each Basket and populate POJO
> representing the Basket.
>
> Basket 200
> state California 246
> employee 678
> phone 555-9000 ext 90009
> zip 0909090
> Basket 300
> state NY 787
> emp.....
> phone .......
> zip......
>
> My parser parses the first line 'state California 246' and then moves to
> another basket. I want to recursively parse each line under basket and at
> the end populate POJO and then move to another basket.
>
use a loop! your collection is apparently 1 or more baskets, thus
collection : basket + EOF ;
basket : bannerPhrase stateClause empClause phoneClause zipClause ;
bannerPhrase : 'Basket' ... ;
stateCaluse : 'state' ... ;
empClause : 'employee' ... ;
phoneClause : 'phone' ... ;
zipClause : 'zip' ... ;
and of course need to add appropriate actions in order to populate your
data structure.
However, from your supplied grammar fragment, i suspect you will have
significant ambiguity issues with your definition of TOKEN.
Hope this helps...
-jbb
More information about the antlr-interest
mailing list