我正在尝试使用Jison编写一个解析器来解析该javap
工具的输出。这是我的 .jison 文件的内容:
%lex
%x classfile
%%
"Classfile" { this.begin("classfile"); }
<classfile>\s+ { /* ignore whitespace */ }
<classfile>[^\n]+ { this.popState(); return 'CLASSFILE'; }
<INITIAL><<EOF>> { return 'EOF'; }
/lex
%start root
%%
root
: CLASSFILE EOF { return $1; }
;
不幸的是,当我运行“jison javap.jison”时,我收到了这个错误:
undefined:5
case 0:"Classfile" { this.begin("classfile"); }
^
SyntaxError: Unexpected token {
at Function (<anonymous>)
at Object.buildActions (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\node_modules\jison-lex\regexp-lexer.js:118:12)
at Object.RegExpLexer (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\node_modules\jison-lex\regexp-lexer.js:131:39)
at Jison_Generator (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\jison.js:108:22)
at (anonymous function) (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\util\typal.js:23:28)
at new o.constructor (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\util\typal.js:77:70)
at new Jison_Generator (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\jison.js:1578:20)
at processGrammar (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\cli.js:87:21)
at Object.exports.main (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\cli.js:61:56)
at Object.<anonymous> (C:\Users\cdmck_000\AppData\Roaming\npm\node_modules\jison\lib\cli.js:105:13)
我试过用替换"Classfile"
但\w+
它只是给我一个错误\
而\w+
不是。