开发者

Antlr Time-out waiting to connect to the remote parser

开发者 https://www.devze.com 2023-04-05 19:16 出处:网络
I am using the newest ANTLR.I get this error message while trying to debug this grammar: grammar Grammar;

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?


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:

@lexer::header{
    package parser;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消