带有python3的Antlr4不接受重音词

2024-09-30 20:35:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将Antlr4与Python3一起使用,但是Antlr不接受重音字母或其他类似!的符号。你知道吗

我使用以下语法:

grammar GramaticaSintagmatica;
tokens {ART,ADJ,SUBS,VERB,PREP,PRON,CONJ,ADV,NUM,FABRICANTE}
WS : ( ’ ’ | ’\t’ | ’\r’ | ’\n’) {skip();} ;
fragment
LetrasAcentuadas :’á’|’à’|’â’|’ã’|’é’|’ê’|’í’|’ó’|’ô’|’õ’|’ú’|’ü’|’ç’|’À’|’Á’|’Â’|’Ã’|’É’|’Ê’|’Í'|’Ó’|’Ô’|’Õ’|’Ú’|’Ü’|’Ç’|’-’;
PALAVRA : (’a’..’z’|’A’..’Z’|LetrasAcentuadas)+ ;
INTS : ’0’..’9’+ (’.’ ’0’..’9’+)? ;
TERMINAL : ’.’|’?’|’!’|’;’;
VIRGULA : ’,’;
MODELO: ((’a’..’z’|’A’..’Z’) ’0’..’9’)+;
NAO : ’não’;
periodo :(oracao | . )*?;
oracao : sn_suj? nao_opc? sv sp_opc?| sp VIRGULA sn_suj? nao_opc? sv sp_opc?;
nao_opc: NAO;
sn_opc : sn;
sn : SUBS| det sa_opc? SUBS mod?;
sn_suj : ( SUBS (PREP? SUBS)* | PRON )| det sa_opc? SUBS (PREP? SUBS)* mod?;
det : pre_det? det_base pos_det?;
pre_det:;
det_base: ART| PRON| NUM;
pos_det: NUM| PRON;
mod : sa?| sp;
sp_opc : sp;
sp : PREP sn| ADV sp_opc?;
sa_opc : sa?;
sa : intens? ADJ ((CONJ | VIRGULA)? ADJ)* sp_opc?;
intens : ADV;
sv : VERB complemento;
complemento : sa_opc? sn_opc? sp_opc?;

有这样的错误:

error<50>: GramaticaSintagmatica.g4:9:76: syntax error: '?' came as a complete surprise to me error<50>: GramaticaSintagmatica.g4:9:84: syntax error: '-' came as a complete surprise to me error<50>: GramaticaSintagmatica.g4:10:18: syntax error: '..' came as a complete surprise to me while looking for lexer rule element error<50>: GramaticaSintagmatica.g4:12:30: syntax error: '!' came as a complete surprise to me

我打电话给antlr-4.5.1-完成.jar这样:

java -jar antlr-4.5.1-complete.jar GramaticaSintagmatica.g4 -o build_python -Dlanguage=Python3


Tags: assaerrorspcompletesubsdetsyntax