尝试将语法重新组织为两个文件时出现异常 ANTLR 错误

发布于 2024-08-21 01:49:13 字数 9283 浏览 9 评论 0原文

我正在将语法重新组织为两个文件,以适应树语法; Lua.g 和 LuaGrammar.g。 Lua.g 将拥有我所有的词法分析器规则,LuaGrammar.g 将拥有我所有的树语法和解析器规则。但是,当我尝试编译 LuaGrammar.gi 时,出现以下错误:

[00:28:37] error(10):  internal error: C:\Users\RCIX\Desktop\AguaLua\Project\trunk\AguaLua\AguaLua\ANTLR Data\LuaGrammar.g : java.lang.IllegalArgumentException: Can't find template ruleRefBang.st; group hierarchy is [CSharp2]
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:507)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:484)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:484)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.grammar.v2.CodeGenTreeWalker.getRuleElementST(CodeGenTreeWalker.java:152)
org.antlr.grammar.v2.CodeGenTreeWalker.atom(CodeGenTreeWalker.java:1986)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1708)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1556)
org.antlr.grammar.v2.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1306)
org.antlr.grammar.v2.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1081)
org.antlr.grammar.v2.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:1871)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1704)
org.antlr.grammar.v2.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1306)
org.antlr.grammar.v2.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1081)
org.antlr.grammar.v2.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:797)
org.antlr.grammar.v2.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:588)
org.antlr.grammar.v2.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:530)
org.antlr.grammar.v2.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java:336)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:432)
org.antlr.Tool.generateRecognizer(Tool.java:641)
org.antlr.Tool.process(Tool.java:454)
org.antlr.works.generate.CodeGenerate.generate(CodeGenerate.java:104)
org.antlr.works.generate.CodeGenerate.run(CodeGenerate.java:185)
java.lang.Thread.run(Unknown Source)

并且,我收到以下错误:

[00:34:58] error(100): C:\Users\RCIX\Desktop\AguaLua\Project\trunk\AguaLua\AguaLua\ANTLR Data\Lua.g:0:0: syntax error: codegen: <AST>:0:0: unexpected end of subtree

尝试生成 Lua.g 时。为什么我会收到这些错误,我该如何修复它们? (使用ANTLR V3,我能够提供语法文件)

更新:这是我正在尝试编译的语法文件。

tree grammar LuaGrammar;

options {
  backtrack=true;
  language=CSharp2;
  output=AST;
  tokenVocab=Lua;
  filter=true;
  ASTLabelType=CommonTree;
}


assignment 
    :   
    ^('=' left=NAME right=NAME) {Ast. };
/*



chunk : (stat (';'!)?)* (laststat (';'!)?)?;

block : chunk;

stat :  varlist1 '='^ explist1 | 
    functioncall | 
    doblock | 
    'while'^ exp doblock | 
    'repeat'^ block untilrule | 
    'if'^ exp thenchunk elseifchunk* elsechunk? 'end'! | 
    'for'^ forinitializer doblock | 
    'for'^ namelist inlist doblock | 
    'function'^ funcname funcbody | 
    'local' 'function' NAME funcbody | 
    'local'^ namelist localstat? ;

localstat 
    :   '='^ explist1;

untilrule
    :   'until'^ exp;

elseifchunk
    :   'elseif'^ exp thenchunk;

thenchunk
    :   'then'^ block;

elsechunk
    :   'else'^ block;

forinitializer
    :   NAME '='^ exp ','! exp (','! exp)?;

doblock
    :   'do'^ block 'end'!;

inlist
    :   'in'^ explist1;

laststat : 'return'^ (explist1)? | 'break';




dotname : '.'! funcname;

colonname
    :   ':' NAME;

funcname :   NAME^ (dotname | colonname)?;




varlist1 : var (','! var)*;


namelist : NAME (','! NAME)*;

explist1 : (exp ','!)* exp;
*/
/*
exp :  expelement (binop^ exp)* ;

expelement
    :   ('nil' | 'false' | 'true' | number | stringrule | '...' | /*function |*\ prefixexp | tableconstructor | unop exp);
var: (namevar | dotvar | expvar | arrayvar)?;

namevar
    :   NAME^ var;

dotvar
    :   '.'! var;

expvar
    :   '('^ exp ')'! var;

arrayvar
    :   '['^ var ']'! var;

varSuffix: nameAndArgs* ('[' exp ']' | '.' NAME);

prefixexp: varOrExp nameAndArgs*;

functioncall: varOrExp nameAndArgs+;

varOrExp: var | '('! exp ')'!;


nameAndArgs: (':' NAME)? argsrule;

argsrule :  '(' (explist1)? ')' | tableconstructor | stringrule ;

function : 'function' funcbody;

funcbody :  funcparams funcblock;

funcblock
    :   ')'^ block 'end'!;

funcparams
    :   '('^ parlist1? ;

parlist1 : namelist (','! '...')? | '...';

tableconstructor : '{'^ (fieldlist)? '}'!;

fieldlist : field (fieldsep! field)* (fieldsep!)?;

field : '['! exp ']'! '='^ exp | NAME '='^ exp | exp;
*/
fieldsep : ',' | ';';

binop : '+' | '-' | '*' | '/' | '^' | '%' | '..' | 
         '<' | '<=' | '>' | '>=' | '==' | '~=' | 
         'and' | 'or';

unop : '-' | 'not' | '#';

number : INT | FLOAT | EXP | HEX;

stringrule  : NORMALSTRING | CHARSTRING | LONGSTRING;

Lua.g:(

/*
 * Lua 5.1 grammar
 * 
 * Nicolai Mainiero
 * May 2007
 * 
 * This is a Lua (http://www.lua.org) grammar for the version 5.1 for ANTLR 3.
 * I tested it with basic and extended examples and it worked fine. It is also used
 * for LunarEclipse (http://lunareclipse.sf.net) a Lua editor based on Eclipse.
 * 
 * Thanks to Johannes Luber and Gavin Lambert who helped me with some mutually left recursion.
 *  
 */

grammar Lua;

options {
  backtrack=true;
  language=CSharp2;
  //output=AST;
  //ASTLabelType=CommonTree;
}
@lexer::namespace{AguaLua}


chunk : (stat (';'!)?)* (laststat (';'!)?)?;

block : chunk;

stat :  varlist1 '='^ explist1 | 
    functioncall | 
    doblock | 
    'while'^ exp doblock | 
    'repeat'^ block untilrule | 
    'if'^ exp thenchunk elseifchunk* elsechunk? 'end'! | 
    'for'^ forinitializer doblock | 
    'for'^ namelist inlist doblock | 
    'function'^ funcname funcbody | 
    'local' 'function' NAME funcbody | 
    'local'^ namelist localstat? ;

localstat 
    :   '='^ explist1;

untilrule
    :   'until'^ exp;

elseifchunk
    :   'elseif'^ exp thenchunk;

thenchunk
    :   'then'^ block;

elsechunk
    :   'else'^ block;

forinitializer
    :   NAME '='^ exp ','! exp (','! exp)?;

doblock
    :   'do'^ block 'end'!;

inlist
    :   'in'^ explist1;

laststat : 'return'^ (explist1)? | 'break';




dotname : '.'! funcname;

colonname
    :   ':' NAME;

funcname :   NAME^ (dotname | colonname)?;




varlist1 : var (','! var)*;


namelist : NAME (','! NAME)*;

explist1 : (exp ','!)* exp;

exp :  expelement (binop^ exp)* ;

expelement
    :   ('nil' | 'false' | 'true' | number | stringrule | '...' | function | prefixexp | tableconstructor | unop exp);

var: (namevar | dotvar | expvar | arrayvar)?;

namevar
    :   NAME^ var;

dotvar
    :   '.'! var;
expvar
    :   '('^ exp ')'! var;
arrayvar
    :   '['^ var ']'! var;

varSuffix: nameAndArgs* ('[' exp ']' | '.' NAME);

prefixexp: varOrExp nameAndArgs*;

functioncall: varOrExp nameAndArgs+;

varOrExp: var | '('! exp ')'!;

nameAndArgs: (':' NAME)? argsrule;

argsrule :  '(' (explist1)? ')' | tableconstructor | stringrule ;

function : 'function' funcbody;

funcbody :  funcparams funcblock;

funcblock
    :   ')'^ block 'end'!;

funcparams
    :   '('^ parlist1? ;

parlist1 : namelist (','! '...')? | '...';

tableconstructor : '{'^ (fieldlist)? '}'!;

fieldlist : field (fieldsep! field)* (fieldsep!)?;

field : '['! exp ']'! '='^ exp | NAME '='^ exp | exp;

fieldsep : ',' | ';';

binop : '+' | '-' | '*' | '/' | '^' | '%' | '..' | 
         '<' | '<=' | '>' | '>=' | '==' | '~=' | 
         'and' | 'or';

unop : '-' | 'not' | '#';

number : INT | FLOAT | EXP | HEX;

stringrule  : NORMALSTRING | CHARSTRING | LONGSTRING;

// LEXER

NAME    :('a'..'z'|'A'..'Z'|'_')(options{greedy=true;}: 'a'..'z'|'A'..'Z'|'_'|'0'..'9')*
    ;

INT : ('0'..'9')+;

FLOAT   :INT '.' INT ;

EXP : (INT| FLOAT) ('E'|'e') ('-')? INT;

HEX :'0x' ('0'..'9'| 'a'..'f')+ ;

NORMALSTRING
    :  '"' ( EscapeSequence | ~('\\'|'"') )* '"' 
    ;

CHARSTRING
   :    '\'' ( EscapeSequence | ~('\''|'\\') )* '\''
   ;

LONGSTRING
    :   '['('=')*'[' ( EscapeSequence | ~('\\'|']') )* ']'('=')*']'
    ;

fragment
EscapeSequence
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UnicodeEscape
    |   OctalEscape
    ;

fragment
OctalEscape
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UnicodeEscape
    :   '\\' 'u' HexDigit HexDigit HexDigit HexDigit
    ;

fragment
HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;


COMMENT
    :   '--[[' ( options {greedy=false;} : . )* ']]' {Skip();}
    ;

LINE_COMMENT  : '--' (~ NEWLINE)* {Skip();};
fragment NEWLINE : '\r'|'\n' | '\r\n' ;

WS  :  (' '|'\t'|'\u000C') {Skip();};

两者均基于 Nicolai Mainero 生成的语法,可在 ANTLR 网站上找到,Lua 5.1 语法) 如果我取消注释超过此,则会出现上述错误。

I am reorganizing my grammar into two files in order to accomodate a tree grammar; Lua.g and LuaGrammar.g. Lua.g will have all of my lexer rules, and LuaGrammar.g will have all of my tree grammar and parser rules. However, when i try and compile LuaGrammar.g i get the following error:

[00:28:37] error(10):  internal error: C:\Users\RCIX\Desktop\AguaLua\Project\trunk\AguaLua\AguaLua\ANTLR Data\LuaGrammar.g : java.lang.IllegalArgumentException: Can't find template ruleRefBang.st; group hierarchy is [CSharp2]
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:507)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:484)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.stringtemplate.StringTemplateGroup.lookupTemplate(StringTemplateGroup.java:484)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:392)
org.antlr.stringtemplate.StringTemplateGroup.getInstanceOf(StringTemplateGroup.java:404)
org.antlr.grammar.v2.CodeGenTreeWalker.getRuleElementST(CodeGenTreeWalker.java:152)
org.antlr.grammar.v2.CodeGenTreeWalker.atom(CodeGenTreeWalker.java:1986)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1708)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1556)
org.antlr.grammar.v2.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1306)
org.antlr.grammar.v2.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1081)
org.antlr.grammar.v2.CodeGenTreeWalker.ebnf(CodeGenTreeWalker.java:1871)
org.antlr.grammar.v2.CodeGenTreeWalker.element(CodeGenTreeWalker.java:1704)
org.antlr.grammar.v2.CodeGenTreeWalker.alternative(CodeGenTreeWalker.java:1306)
org.antlr.grammar.v2.CodeGenTreeWalker.block(CodeGenTreeWalker.java:1081)
org.antlr.grammar.v2.CodeGenTreeWalker.rule(CodeGenTreeWalker.java:797)
org.antlr.grammar.v2.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:588)
org.antlr.grammar.v2.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:530)
org.antlr.grammar.v2.CodeGenTreeWalker.grammar(CodeGenTreeWalker.java:336)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:432)
org.antlr.Tool.generateRecognizer(Tool.java:641)
org.antlr.Tool.process(Tool.java:454)
org.antlr.works.generate.CodeGenerate.generate(CodeGenerate.java:104)
org.antlr.works.generate.CodeGenerate.run(CodeGenerate.java:185)
java.lang.Thread.run(Unknown Source)

And, i'm getting the following error:

[00:34:58] error(100): C:\Users\RCIX\Desktop\AguaLua\Project\trunk\AguaLua\AguaLua\ANTLR Data\Lua.g:0:0: syntax error: codegen: <AST>:0:0: unexpected end of subtree

when attempting to generate Lua.g. Why am i getting these errors, and how can i fix them? (Using ANTLR V3, am able to provide grammar files)

Update: here is the grammar file i am trying to compile.

tree grammar LuaGrammar;

options {
  backtrack=true;
  language=CSharp2;
  output=AST;
  tokenVocab=Lua;
  filter=true;
  ASTLabelType=CommonTree;
}


assignment 
    :   
    ^('=' left=NAME right=NAME) {Ast. };
/*



chunk : (stat (';'!)?)* (laststat (';'!)?)?;

block : chunk;

stat :  varlist1 '='^ explist1 | 
    functioncall | 
    doblock | 
    'while'^ exp doblock | 
    'repeat'^ block untilrule | 
    'if'^ exp thenchunk elseifchunk* elsechunk? 'end'! | 
    'for'^ forinitializer doblock | 
    'for'^ namelist inlist doblock | 
    'function'^ funcname funcbody | 
    'local' 'function' NAME funcbody | 
    'local'^ namelist localstat? ;

localstat 
    :   '='^ explist1;

untilrule
    :   'until'^ exp;

elseifchunk
    :   'elseif'^ exp thenchunk;

thenchunk
    :   'then'^ block;

elsechunk
    :   'else'^ block;

forinitializer
    :   NAME '='^ exp ','! exp (','! exp)?;

doblock
    :   'do'^ block 'end'!;

inlist
    :   'in'^ explist1;

laststat : 'return'^ (explist1)? | 'break';




dotname : '.'! funcname;

colonname
    :   ':' NAME;

funcname :   NAME^ (dotname | colonname)?;




varlist1 : var (','! var)*;


namelist : NAME (','! NAME)*;

explist1 : (exp ','!)* exp;
*/
/*
exp :  expelement (binop^ exp)* ;

expelement
    :   ('nil' | 'false' | 'true' | number | stringrule | '...' | /*function |*\ prefixexp | tableconstructor | unop exp);
var: (namevar | dotvar | expvar | arrayvar)?;

namevar
    :   NAME^ var;

dotvar
    :   '.'! var;

expvar
    :   '('^ exp ')'! var;

arrayvar
    :   '['^ var ']'! var;

varSuffix: nameAndArgs* ('[' exp ']' | '.' NAME);

prefixexp: varOrExp nameAndArgs*;

functioncall: varOrExp nameAndArgs+;

varOrExp: var | '('! exp ')'!;


nameAndArgs: (':' NAME)? argsrule;

argsrule :  '(' (explist1)? ')' | tableconstructor | stringrule ;

function : 'function' funcbody;

funcbody :  funcparams funcblock;

funcblock
    :   ')'^ block 'end'!;

funcparams
    :   '('^ parlist1? ;

parlist1 : namelist (','! '...')? | '...';

tableconstructor : '{'^ (fieldlist)? '}'!;

fieldlist : field (fieldsep! field)* (fieldsep!)?;

field : '['! exp ']'! '='^ exp | NAME '='^ exp | exp;
*/
fieldsep : ',' | ';';

binop : '+' | '-' | '*' | '/' | '^' | '%' | '..' | 
         '<' | '<=' | '>' | '>=' | '==' | '~=' | 
         'and' | 'or';

unop : '-' | 'not' | '#';

number : INT | FLOAT | EXP | HEX;

stringrule  : NORMALSTRING | CHARSTRING | LONGSTRING;

Lua.g:

/*
 * Lua 5.1 grammar
 * 
 * Nicolai Mainiero
 * May 2007
 * 
 * This is a Lua (http://www.lua.org) grammar for the version 5.1 for ANTLR 3.
 * I tested it with basic and extended examples and it worked fine. It is also used
 * for LunarEclipse (http://lunareclipse.sf.net) a Lua editor based on Eclipse.
 * 
 * Thanks to Johannes Luber and Gavin Lambert who helped me with some mutually left recursion.
 *  
 */

grammar Lua;

options {
  backtrack=true;
  language=CSharp2;
  //output=AST;
  //ASTLabelType=CommonTree;
}
@lexer::namespace{AguaLua}


chunk : (stat (';'!)?)* (laststat (';'!)?)?;

block : chunk;

stat :  varlist1 '='^ explist1 | 
    functioncall | 
    doblock | 
    'while'^ exp doblock | 
    'repeat'^ block untilrule | 
    'if'^ exp thenchunk elseifchunk* elsechunk? 'end'! | 
    'for'^ forinitializer doblock | 
    'for'^ namelist inlist doblock | 
    'function'^ funcname funcbody | 
    'local' 'function' NAME funcbody | 
    'local'^ namelist localstat? ;

localstat 
    :   '='^ explist1;

untilrule
    :   'until'^ exp;

elseifchunk
    :   'elseif'^ exp thenchunk;

thenchunk
    :   'then'^ block;

elsechunk
    :   'else'^ block;

forinitializer
    :   NAME '='^ exp ','! exp (','! exp)?;

doblock
    :   'do'^ block 'end'!;

inlist
    :   'in'^ explist1;

laststat : 'return'^ (explist1)? | 'break';




dotname : '.'! funcname;

colonname
    :   ':' NAME;

funcname :   NAME^ (dotname | colonname)?;




varlist1 : var (','! var)*;


namelist : NAME (','! NAME)*;

explist1 : (exp ','!)* exp;

exp :  expelement (binop^ exp)* ;

expelement
    :   ('nil' | 'false' | 'true' | number | stringrule | '...' | function | prefixexp | tableconstructor | unop exp);

var: (namevar | dotvar | expvar | arrayvar)?;

namevar
    :   NAME^ var;

dotvar
    :   '.'! var;
expvar
    :   '('^ exp ')'! var;
arrayvar
    :   '['^ var ']'! var;

varSuffix: nameAndArgs* ('[' exp ']' | '.' NAME);

prefixexp: varOrExp nameAndArgs*;

functioncall: varOrExp nameAndArgs+;

varOrExp: var | '('! exp ')'!;

nameAndArgs: (':' NAME)? argsrule;

argsrule :  '(' (explist1)? ')' | tableconstructor | stringrule ;

function : 'function' funcbody;

funcbody :  funcparams funcblock;

funcblock
    :   ')'^ block 'end'!;

funcparams
    :   '('^ parlist1? ;

parlist1 : namelist (','! '...')? | '...';

tableconstructor : '{'^ (fieldlist)? '}'!;

fieldlist : field (fieldsep! field)* (fieldsep!)?;

field : '['! exp ']'! '='^ exp | NAME '='^ exp | exp;

fieldsep : ',' | ';';

binop : '+' | '-' | '*' | '/' | '^' | '%' | '..' | 
         '<' | '<=' | '>' | '>=' | '==' | '~=' | 
         'and' | 'or';

unop : '-' | 'not' | '#';

number : INT | FLOAT | EXP | HEX;

stringrule  : NORMALSTRING | CHARSTRING | LONGSTRING;

// LEXER

NAME    :('a'..'z'|'A'..'Z'|'_')(options{greedy=true;}: 'a'..'z'|'A'..'Z'|'_'|'0'..'9')*
    ;

INT : ('0'..'9')+;

FLOAT   :INT '.' INT ;

EXP : (INT| FLOAT) ('E'|'e') ('-')? INT;

HEX :'0x' ('0'..'9'| 'a'..'f')+ ;

NORMALSTRING
    :  '"' ( EscapeSequence | ~('\\'|'"') )* '"' 
    ;

CHARSTRING
   :    '\'' ( EscapeSequence | ~('\''|'\\') )* '\''
   ;

LONGSTRING
    :   '['('=')*'[' ( EscapeSequence | ~('\\'|']') )* ']'('=')*']'
    ;

fragment
EscapeSequence
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UnicodeEscape
    |   OctalEscape
    ;

fragment
OctalEscape
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UnicodeEscape
    :   '\\' 'u' HexDigit HexDigit HexDigit HexDigit
    ;

fragment
HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;


COMMENT
    :   '--[[' ( options {greedy=false;} : . )* ']]' {Skip();}
    ;

LINE_COMMENT  : '--' (~ NEWLINE)* {Skip();};
fragment NEWLINE : '\r'|'\n' | '\r\n' ;

WS  :  (' '|'\t'|'\u000C') {Skip();};

(both are based off of a grammar produced by Nicolai Mainero and available at ANTLR's site, Lua 5.1 grammar)
If i uncomment anymore than this, it comes up with the error above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不顾 2024-08-28 01:49:13

好吧,'找不到模板ruleRefBang.st' 与非法使用“树排除”运算符有关:!。通常,这是一个矛盾的重写规则:某处有一个 !,然后使用 -> 重写它,但无论如何都使用被忽略的标记。由于我在您的语法中看不到 -> ,因此情况不可能如此(除非您简化了树语法以在此处发布并删除了一些重写规则?)。

无论如何,我首先删除树语法中的所有 ! 运算符,如果您的语法有效,则将它们一一放回原处。然后您应该能够在语法中找出非法 ! 所在的位置。

祝你好运!

Okay, a 'Can't find template ruleRefBang.st' has something to do with the illegal use of a "tree exclude" operator: !. Usually, it is a contradicting rewrite rule: somewhere you have a ! and then rewrite it using -> but use that ignored token anyway. Since I cannot see a -> in your grammar, that can't be the case (unless you simplified the tree grammar to post here and removed some rewrite rules?).

Anyway, I'd start by removing all ! operators in your tree grammar and if your grammar then works put them, one by one, back in again. Then you should be able to pin point the place in your grammar that houses the illegal !.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文