Antlr 词法分析器规则标记浮点/双精度

发布于 2025-01-19 18:44:32 字数 751 浏览 0 评论 0原文

我正在尝试使用 这个正则表达式 来标记 Antlr 中的双精度值,但显然这个正则表达式没有被 Antlr 理解。

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

错误:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2025-01-26 18:44:32

Antlr Lexer统治在某种程度上类似于Regex,但绝对不是正则。

尝试:

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

字符需要包含在'标记中(除了集符号([ and ]之间的字符,] )

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 ])

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文