[antlr-interest] Newbie Parser/Lexer question

Gavin Lambert antlr at mirality.co.nz
Mon Apr 2 13:29:02 PDT 2007


At 07:46 3/04/2007, John Howard wrote:
 >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.

Tokens don't necessarily have to be assigned meaning.  In your 
case it might be easier to have very basic tokens (eg. NUMBER and 
LETTERS) and work everything else out in the parser, where you've 
got contextual information.  You might have to use semantic 
predicates in a couple of places, though, if your context allows a 
specific subset of numbers or letters rather than accepting 
anything.

Although (not being familiar with bridge), is the 1C at the start 
(the bid) also representing "one diamond", or is it a different 
D?  If so, then you could make a combined token (CARDSET or 
something).  Though that would end up comprising most of the 
lexing output, from the looks of things.



More information about the antlr-interest mailing list