你好ANTLR专家,我需要你的帮助!
我已经使用ANTLR很长一段时间了,并使用它编写了几个解析器ANTLR4。我现在使用的版本是4.5.3。
好的我正在编写一个带有Javascript目标的c ++解析器。直到这个时候事情已经相当顺利。然后我尝试解析iostream.h(实际上是用一个小的main并使用Xcode llvm进行预处理)。它有超过30000行代码,大小为1.2MB。有错误,但可以修复。问题是我得到了内存错误。
375416 ms: Mark-sweep 1349.2 (1422.3) -> 1349.0 (1432.3) MB, 719.3 / 0 ms [allocation failure] [GC in old space requested]. 376141 ms: Mark-sweep 1349.0 (1432.3) -> 1349.0 (1433.3) MB, 725.6 / 0 ms [allocation failure] [GC in old space requested]. 376900 ms: Mark-sweep 1349.0 (1433.3) -> 1349.0 (1433.3) MB, 758.7 / 0 ms [last resort gc]. 377632 ms: Mark-sweep 1349.0 (1433.3) -> 1349.0 (1433.3) MB, 731.9 / 0 ms [last resort gc]. ==== JS stack trace ========================================= Security context: 0x973d6c9e59 1: Join(aka Join) [native array.js:179] [pc=0x109304f3a6b5] (this=0x973d604189 ,w=0x109e7ca91511 ,x=108,N=0x1a20734ed919 ,M=0x973d6b4a11 ) 2: InnerArrayJoin(aka InnerArrayJoin) [native array.js:~343] [pc=0x109304f1afac] (this=0x973d604189 ,N=0x1a20734ed919 ,w=0... FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory Abort trap: 6
我的主要现在是这样的
try { text = fs.readFileSync(filepath, 'utf8'); var chars = new antlr4.InputStream(text); var lexer = new CPP14Lexer.CPP14Lexer(chars); var tokens = new antlr4.CommonTokenStream(lexer); var parser = new CPP14Parser.CPP14Parser(tokens); var printer; try { // SLL mode parser.buildParseTrees = true; parser.setTrace(this.trace); var cache = new PredictionContextCache(); var sim = new ParserATNSimulator(parser, parser._interp.atn, parser._interp.decisionToDFA, cache); sim.parser._interp.predictionMode = PredictionMode.SLL; var tree = sim.parser.translationunit(); printer = new listener.CPPXXPrinter(tokens, lexer, parser, this.debug); antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree); } catch ...
它尝试为整个输入构建语法树。我的问题是,有没有办法在内存保存模式下执行操作,例如根本不创建树并只解析输入?
由于 -Yoshi