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

Re: Its a keyword, but it shouldn't be...

Expand Messages
  • Monty Zukowski
    From: Mcree, Randy ... a ... keyword, ... I wrote a parser for a context sensitive language with ANTLR, it can be done. Ambiguities
    Message 1 of 2 , Sep 28, 1998
    • 0 Attachment
      From: "Mcree, Randy" <randy.mcree@...>
      >
      >Dear ANTLR-folk,
      >
      >The OMG in its finite wisdom has changed their IDL grammar to be context
      >sensitive. Thus the constant "value" may be a keyword, or an identifier. So
      >it should be legal to say:
      > value xyz; // ok
      > value value; // first token is keyword, second should be
      >identifier
      >The second line produces an error in my current antlr grammar since I have
      a
      >rule which is basically
      > fwd_value : "value" identifier SEMI;
      >
      >Naturally the lexer generated by ANTLR always recognizes value as a
      keyword,
      >disallowing the second line, above.
      >
      >Does anyone know of a way around this? This same problem crops up with a
      >total of eight keyword/identifier possibilities.


      I wrote a parser for a context sensitive language with ANTLR, it can be
      done. Ambiguities are the real issue here. Assuming you understand ANTLR's
      ambiguity messages, try something like:

      identifier:
      IDENT
      | "value" { $setType(IDENT); } // match literal "value" and change
      token type to IDENT
      ;

      Follow through by convincing yourself that any new ambiguities are
      acceptable, or fix with appropriate syntactic predicates.

      For clearer ambiguity messages, search dejanews in
      comp.compilers.tools.pccts for a patch I posted that generates better
      messages.

      Monty
    Your message has been successfully submitted and would be delivered to recipients shortly.