Home > Blockchain >  Antlr lexer rule to tokenize float/double
Antlr lexer rule to tokenize float/double

Time:04-08

I am trying to use this regex to tokenize a double in Antlr but apparently this regex is not getting understood by Antlr.

Number: (-?)(0|([1-9][0-9]*))(\\.[0-9] )?;

Error:

syntax error: '-' came as a complete surprise to me 
syntax error: '?' came as a complete surprise to me
syntax error: '0' came as a complete surprise to me
syntax error: '\' came as a complete surprise to me 
syntax error: '\' came as a complete surprise to me 
syntax error: '-' came as a complete surprise to me 
syntax error: '?' came as a complete surprise to me
syntax error: '0' came as a complete surprise to me
syntax error: '\' came as a complete surprise to me 
syntax error: '\' came as a complete surprise to me

CodePudding user response:

ANTLR Lexer rules somewhat resemble REGEX, but definitely are not REGEXs.

Try:

Number: '-'?('0'|[1-9][0-9]*)('.'[0-9] )?;

Characters need to be enclosed in ' marks (with the exception of set notation (characters between [ and ])

  • Related