简体   繁体   English

Profile Antlr语法

[英]Profile Antlr grammar

I found this question here in which OP asks for a way to profile an ANTLTR grammar. 我在这里找到了这个问题 ,OP在其中询问一种分析ANTLTR语法的方法。
However the answer is somewhat unsatisfying as it is limited to grammars without actions and - even more important - it is an automated profiling that will (as I see it) use the defaul constructor of the generated lexer/parser to construct it. 但是,答案有些不尽人意,因为它仅限于没有动作的语法,而且,更重要的是,它是一种自动配置文件,如我所见,它将使用生成的词法分析器/解析器的默认构造器来构造它。

I need to profile a grammar, that does contain actions and that has to be constructed using a custom constructor. 我需要配置文件语法, 不会包含行动和必须使用自定义构造函数来构建。 Therefore I'd need to be able to instantiate the lexer + parser myself and then profile it. 因此,我需要能够自己实例化lexer +解析器,然后对其进行概要分析。
I was unable to find any information on this topic. 我找不到有关此主题的任何信息。 I know there is a profiler for IntelliJ but it works quite similar to the one described in the linked question's answer (maybe it's even the same). 我知道有一个用于IntelliJ的探查器,但它的工作原理与链接问题的答案中所述的探查器非常相似(甚至可能相同)。

Does anyone know how I can profile my grammar with this special needs? 有谁知道我该如何针对我的特殊语法进行语法分析? I don't need any fancy GUI. 我不需要任何精美的GUI。 I'd be satisified if I get the result printed to the console or something like that. 如果将结果打印到控制台或类似的东西,我会感到满意。

To wrap it up: I'm searching for either a tool or a hint on how to write some code that lets me profile my ANTLR grammar (with self-instantiated lexer/parser). 总结一下:我正在寻找一种工具或关于如何编写一些代码的提示,这些代码使我可以分析ANTLR语法(使用自我实例化的词法分析器/解析器)。
Btw my target language is Java so I guess the profiler has to be in Java as well. 顺便说一句,我的目标语言是Java,所以我想探查器也必须是Java。

A good start is setting Parser.setProfile() to true and examine what you get from Parser.getParseInfo() after a parse run. 一个良好的开始是将Parser.setProfile()设置为true,并在解析运行后检查从Parser.getParseInfo()获得的Parser.getParseInfo() I haven't yet looked closer what's provided in detail by the profiling result, but it's on the todo list for my vscode extension for ANTLR4 to provide profiling info for grammars to help improving them. 我尚未仔细查看概要分析结果所提供的详细信息,但它在我的ANTLR4的vscode扩展的待办事项列表中,以提供语法的概要分析信息以帮助改进语法。

A hint for getting from the decision info to a specific rule: there's a decision number , which is an index into ATN.decisionToState . 从决策信息到特定规则的提示:有一个决策号 ,它是ATN.decisionToState的索引。 The DecisionState instance you can get by this is an ATNState descendant, which allows to get a ATNState.ruleIndex from it. 您可以通过该实例获得的DecisionState实例是ATNState子孙,它可以从中获取ATNState.ruleIndex The rule index then can be used with your parser's ruleNames property to find the name of that rule. 然后,可以将规则索引与解析器的ruleNames属性一起使用,以查找该规则的名称。 The value is also what is used for the rule's enum entry. 该值也是用于规则的枚举条目的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM