岛语语法antlr3 [英] Island grammar antlr3

查看:197
本文介绍了岛语语法antlr3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在antlr3中使用岛语法是什么以及如何使用?

What are and how to use the "island grammar" in antlr3?

推荐答案

岛屿语法是最能对待它的语法一种语言作为一个文本(水),并挑选出感兴趣的语言部分,使用语法规则(岛)进行解析。例如,您可以选择构建一个岛语法来挑选C#程序中找到的所有表达式,并忽略变量/方法/类声明和语句语法(if,while,...)。

An island grammar is one that treats most of a language as a blob of text ("water") and picks out the part of the langauge of interest to parse using grammar rules ("island"). For instance, you might choose to build an island grammar to pick out all the expressions found in a C# program, and ignore the variable/method/class declarations and the statement syntax (if, while, ...).

真正的问题是,你应该使用岛文法吗?。

The real question is, "Should you use island grammars at all?".

积极的好处:


  • 您不必为要处理的语言编写完整,完整的语法。

缺点:


  • 选择零件并不总是那么容易感兴趣的来源。例如,
    你如何确保岛语法没有拾取被注释掉的代码块,除非你的岛语法详细解释了所有的注释?岛语法的要点是避免进入那种细节,但是你必须在这里。

  • It isn't always easy to pick out the part of the source of interest. For example, how do you ensure that the island grammar doesn't pick up a block of code that is commented out, unless your island grammar lexes all the comments in detail? The point of an island grammar was to avoid going into that kind of detail, and yet here you must.

你只能使用岛语法来关注你现在明白的问题。如果问题发生了变化,那么你的岛语语法也可能不得不改变,这并不总是容易的。

You can only use the island grammar to focus on the problem as you understand it right now. If the problem moves, then your island grammar may have to shift, too, and that isn't always easy.

程序操作中最有趣的问题需要您不仅可以确定语法(例如,解析)并构建某种树来操作,而且您还可以确定符号的含义。使用岛语法,你已经有效地注销了这样做的可能性(除非你想要包括块,声明等的所有语法......哎呀突然它不是岛语法而是小大陆语法) 。那真的限制了你可以做的事情。

Most interesting problems in program manipulation require that you be able to determine not only the syntax (e.g., "parse") and build some kind of tree to manipulate, but that you also be able to determine the meaning of symbols. With an island grammar, you've effectively written off the possibility of doing that (unless you want to include all the syntax for blocks, declarations, etc. ... oops suddenly it isn't an island grammar but a small continent grammar). And that really limits what you can do.

叫我有偏见,但我'很长一段时间以来一直在做这种事情。我相信岛屿语法确实不那么有用。我建议的替代方案是基于共同基础的多种语言的摊销成本解析器,其名为 DMS软件再造工具包

Call me biased, but I've been doing this kind of stuff a long time. I believe that island grammars really aren't that useful. The alternative I propose is amortized-cost parsers over many languages based on common foundations, and its called DMS Software Reengineering Toolkit.

YMMV。

这篇关于岛语语法antlr3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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