如何匹配 ANTLR 解析器(不是词法分析器)中的任何符号? [英] How to match any symbol in ANTLR parser (not lexer)?

查看:24
本文介绍了如何匹配 ANTLR 解析器(不是词法分析器)中的任何符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何匹配 ANTLR 解析器(不是词法分析器)中的任何符号?ANTLR4 解析器的完整语言描述在哪里?

How to match any symbol in ANTLR parser (not lexer)? Where is the complete language description for ANTLR4 parsers?

更新

答案是不可能"吗?

推荐答案

首先需要了解每个部分在解析中的作用:

You first need to understand the roles of each part in parsing:

词法分析器:这是标记输入字符串的对象.标记化意味着将输入字符流转换为抽象标记符号(通常只是一个数字).

The lexer: this is the object that tokenizes your input string. Tokenizing means to convert a stream of input characters to an abstract token symbol (usually just a number).

解析器:这是仅与标记一起工作以确定语言结构的对象.一种语言(编写为一个或多个语法文件)定义了有效的标记组合.

The parser: this is the object that only works with tokens to determine the structure of a language. A language (written as one or more grammar files) defines the token combinations that are valid.

如您所见,解析器甚至不知道字母是什么.它只知道令牌.所以你的问题已经错了.

As you can see, the parser doesn't even know what a letter is. It only knows tokens. So your question is already wrong.

话虽如此,了解为什么要在解析器中跳过单个输入字母可能会有所帮助.看起来您的基本概念需要调整.

Having said that it would probably help to know why you want to skip individual input letters in your parser. Looks like your base concept needs adjustments.

这篇关于如何匹配 ANTLR 解析器(不是词法分析器)中的任何符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆