[antlr-interest] Newbie Parser/Lexer question

John Howard john.howard9 at btinternet.com
Mon Apr 2 12:46:45 PDT 2007


I am trying to develop a grammar for a description of a bidding system 
for the card game Bridge.  Ideally I want to provide a grammar that 
closely resembles how the rule are written:

e.g.

Category - Openings
1C 11+HCP 4+C ->1CResp
1D 11+HCP 4+D ->1DResp

Category - 1CResp
1D 6-10HCP 4D

The key problem I have with this approach is that the meaning of a token 
is different dependant on it's location.  e.g.  The 4D token would be a 
bid if it was at the start of the line, but otherwise it would mean a 
hand with 4 cards that were diamonds.

Having played with ANTLR I'm not sure that this is possible and is 
probably against the spirit of a well constructed grammar. 

An alternate approach would be the following but this is less user friendly

Category - Openings
1C HCP(11+) C(4+) ->1CResp
1D HCP(11+) D(4+) ->1DResp

Category - 1CResp
1D HCP(6-10) 4D

Before I move to the above I just wanted to check that there isn't a way 
to make this work.  e.g. Could I pre-parse and create an intermediate 
state that could be more easily parsed.

Thanks,

John




More information about the antlr-interest mailing list