Loading ...
Sorry, an error occurred while loading the content.

Re: [antlr-interest] Writer's block

Expand Messages
  • Ryan Davis
    ... I m always partial to having the grammar figure things out themselves, instead of lots of imbedded code. Any reason why any of the following are no good?
    Message 1 of 4 , May 31, 2000
    • 0 Attachment
      jay@... writes:

      > OK.. This is so simple that I can't figure out how to do it. This usually
      > means I'm thinking about it wrong. I've looked through the examples and
      > nothing obvious is coming to mind.
      >
      > I have a parser that looks something like:
      >
      > listDef: (listType)? LCURLY stuff RCURLY
      >
      > listType: "domain" | "ip"

      I'm always partial to having the grammar figure things out themselves,
      instead of lots of imbedded code.

      Any reason why any of the following are no good?

      listDef
      : LCURLY stuff RCURLY
      | "domain" LCURLY domain-stuff RCURLY
      | "ip" LCURLY ip-stuff RCURLY
      ;

      or:

      listDef
      : LCURLY stuff[1] RCURLY
      | "domain" LCURLY stuff[2] RCURLY
      | "ip" LCURLY stuff[3] RCURLY
      ;

      or:

      listDef
      { int code = 0; }
      : ( "domain" { code=1; } | "ip" { code=2; } ) LCURLY stuff[code] RCURLY
      ;
    Your message has been successfully submitted and would be delivered to recipients shortly.