我刚刚遇到了非常好的工具Xtext来创建DSL以及IDE进行编辑.我在网上做了一些搜索,发现人们说它没有提供ANTLR的所有功能.我使用ANTLR作为我的解析器生成器.
我甚至不确定ANTLR的哪些功能我需要为我的语言编写完整的解析器,但ANTLR已经存在了很长时间,并且可能支持比Xtext更多的功能.
任何人都可以举一些不能在Xtext语法中指定的例子吗?
我正在尝试将Bart Kiers的ANTLR PCRE语法(参见:http://big-o.nl/apps/pcreparser/pcre/PCREParser.html)构建到JS目标.我得到它的唯一方法是使用全局回溯和memoization,它生成的代码在这里是无效的语法:
grammar PCRE;
options {
language=JavaScript;
backtrack=true;
memoize=true;
}
parse
: regexAtom* EOF
;
... and the rest of the grammar as seen: http://big-o.nl/apps/pcreparser/pcre/PCREParser.html
Run Code Online (Sandbox Code Playgroud)
词法分析器生成的代码如下所示:
//$ANTLR 3.4 PCRE.g 2011-11-19 23:22:35
var PCRELexer = function(input, state) {
// alternate constructor @todo
// public PCRELexer(CharStream input)
// public PCRELexer(CharStream input, RecognizerSharedState state) {
if (!state) {
state = new org.antlr.runtime.RecognizerSharedState();
}
(function(){
}).call(this);
PCRELexer.superclass.constructor.call(this, input, state);
};
org.antlr.lang.augmentObject(PCRELexer, {
: ,
: ,
: ,
: …Run Code Online (Sandbox Code Playgroud)