Jison解析器中的SyntaxError

时间:2013-03-11 20:55:55

标签: javascript bison flex-lexer jison

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

1 个答案:

答案 0 :(得分:2)

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