我正在尝试使用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+错误。

最佳答案

我将行尾从Windows格式转换为UNIX格式,问题消失了。

08-19 14:55