ANTLR中的解析器规则和词法分析器规则之间的实际区别

ANTLR中的解析器规则和词法分析器规则之间的实际区别

本文介绍了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中的解析器规则和词法分析器规则之间的实际区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 17:20