我正在尝试将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)