ANTLR 中解析器规则和词法分析器规则之间的实际区别? [英] Practical difference between parser rules and lexer rules in ANTLR?

查看:27
本文介绍了ANTLR 中解析器规则和词法分析器规则之间的实际区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理论上理解分离解析器规则和词法分析器规则背后的理论,但这两个语句在 ANTLR 中的实际区别是什么:

I understand the theory behind separating parser rules and lexer rules in theory, but what are the practical differences between these two statements in ANTLR:

my_rule: ... ;

MY_RULE: ... ;

它们会产生不同的 AST 树吗?性能不一样?潜在的歧义?

Do they result in different AST trees? Different performance? Potential ambiguities?

推荐答案

... ANTLR 中这两个语句之间的实际区别是什么...

... what are the practical differences between these two statements in ANTLR ...

MY_RULE 将用于标记您的输入源.它代表了您的语言的基本组成部分.

MY_RULE will be used to tokenize your input source. It represents a fundamental building block of your language.

my_rule 从解析器调用,它由零个或多个其他解析器规则或词法分析器生成的标记组成.

my_rule is called from the parser, it consists of zero or more other parser rules or tokens produced by the lexer.

这就是区别.

它们会产生不同的 AST 树吗?性能不一样?...

Do they result in different AST trees? Different performance? ...

解析器使用词法分析器生成的标记构建 AST,所以这些问题(对我来说)毫无意义.词法分析器仅馈送"解析器是一维标记流.

The parser builds the AST using tokens produced by the lexer, so the questions make no sense (to me). A lexer merely "feeds" the parser a 1 dimensional stream of tokens.

这篇关于ANTLR 中解析器规则和词法分析器规则之间的实际区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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