json解析器中的SyntaxError



我试图使用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。,我得到这个错误:

undefined:5
case 0:"Classfile"             { this.begin("classfile"); }
                               ^
SyntaxError: Unexpected token {
    at Function (<anonymous>)
    at Object.buildActions (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonnode_modulesjison-lexregexp-lexer.js:118:12)
    at Object.RegExpLexer (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonnode_modulesjison-lexregexp-lexer.js:131:39)
    at Jison_Generator (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibjison.js:108:22)
    at (anonymous function) (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibutiltypal.js:23:28)
    at new o.constructor (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibutiltypal.js:77:70)
    at new Jison_Generator (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibjison.js:1578:20)
    at processGrammar (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibcli.js:87:21)
    at Object.exports.main (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibcli.js:61:56)
    at Object.<anonymous> (C:Userscdmck_000AppDataRoamingnpmnode_modulesjisonlibcli.js:105:13)

我已经尝试用w+代替"Classfile",但它只是给了我一个错误在w+

我将行尾从Windows格式转换为UNIX格式,问题就解决了。

相关内容

  • 没有找到相关文章

最新更新