Antlr 等待连接到远程解析器超时
我正在使用最新的 ANTLR。我在尝试调试此语法时收到此错误消息:
grammar Grammar;
options { language = Java;
}
@header {
package parser;
import java.util.HashMap;
import viewmodel.*;
import java.util.List;
}
@members {
/** Map variable name to Integer object holding value */
HashMap memory = new HashMap();
}
prog returns [DiagramNode node]
: clas
{$node = $clas.node;}
;
clas returns [DiagramNode node]
:VISIBILITY* CLASSORINTERFACE name=NAME '{' classDef '}' NEWLINE
{$node = $classDef.node;
$node.setName(name.getText());
}
;
classDef returns [DiagramNode node]
:{$node = new DiagramNode(); }
fieldDef ';' NEWLINE?
{$node.getFields().add($fieldDef.field);}
;
fieldDef returns [DiagramField field]
:{$field = new DiagramField();}
type=NAME name=NAME ';' NEWLINE?
{$field.setType(type.getText());
$field.setName(name.getText());
}
;
VISIBILITY
: ('public' | 'private' | 'protected');
CLASSORINTERFACE
: ('class' | 'inerface');
NAME
: ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9') *;
INT : '0'..'9'+ ;
NEWLINE:'\r'? '\n' {skip();};
WS : (' '|'\t')+ {skip();} ;
输入是:
class Abc {
Type1 Name1;
Type2 Name2;
}
我假设这是语法的错误,因为另一个语法正在编译并且工作正常。你能指出我可能的错误吗?
I am using the newest ANTLR. I get this error message while trying to debug this grammar:
grammar Grammar;
options { language = Java;
}
@header {
package parser;
import java.util.HashMap;
import viewmodel.*;
import java.util.List;
}
@members {
/** Map variable name to Integer object holding value */
HashMap memory = new HashMap();
}
prog returns [DiagramNode node]
: clas
{$node = $clas.node;}
;
clas returns [DiagramNode node]
:VISIBILITY* CLASSORINTERFACE name=NAME '{' classDef '}' NEWLINE
{$node = $classDef.node;
$node.setName(name.getText());
}
;
classDef returns [DiagramNode node]
:{$node = new DiagramNode(); }
fieldDef ';' NEWLINE?
{$node.getFields().add($fieldDef.field);}
;
fieldDef returns [DiagramField field]
:{$field = new DiagramField();}
type=NAME name=NAME ';' NEWLINE?
{$field.setType(type.getText());
$field.setName(name.getText());
}
;
VISIBILITY
: ('public' | 'private' | 'protected');
CLASSORINTERFACE
: ('class' | 'inerface');
NAME
: ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9') *;
INT : '0'..'9'+ ;
NEWLINE:'\r'? '\n' {skip();};
WS : (' '|'\t')+ {skip();} ;
The input is:
class Abc {
Type1 Name1;
Type2 Name2;
}
I am assuming that it's grammar's fault, cause another one was compiling and working fine. Could you point me possible errors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现这里没有人了解 ANTLR。幸运的是我已经自己想出了办法。问题的原因是语法内部的逻辑 - 我不知道到底是什么,可能是错误的导入、使用变量、参数或以错误的方式返回,或者最终缺少词法分析器的包声明:
I see that there are no people here who know anything about ANTLR. Luckily I've figured it out on my own. The cause of the problem was the logic inside the grammar - I don't know what exactly, it could be wrong import, using variables, arguments or returns in a wrong way, or eventually missing package declaration for lexer: