[antlr-interest] Handling negative numbers

David Holroyd dave at badgers-in-foil.co.uk
Tue Aug 22 09:27:31 PDT 2006


On Tue, Aug 22, 2006 at 08:46:32AM -0700, Sathish K wrote:
>   Could anyone guide me as to how to handle negative numbers?

Don't bother trying to handle them in the lexer, handle uniary-minus in
the parser instead, i.e.,

  simpleExpr
      :   (MINUS)?
          NUM
      ;
----
  MINUS: '-';
  NUM: ('0'..'9')+


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list