问题陈述所需的语法定义

发布于 2024-08-05 21:42:22 字数 767 浏览 0 评论 0原文

嗨,我现在有这个语法, 但当我有服务后,一张纸条。 Antlr 不想承认它不是服务,但请注意。并且service和note有不同的结构。 这个怎么写呢?

我正在尝试解析这个。但请注意 bla bla;正在服务中

777014322;O2 Optimum Profi Promo;

Free sms;0:00;250:00;0:00;

NOTE bla bla;

STM;



thank you.

    grammar teste;

file : phoneNumber*;

phoneNumber
 : number SEPARATOR tariff SEPARATOR? newline

  service*  
  note? 
  stm SEPARATOR* newline

 ;


note : NOTE TEXT SEPARATOR? newline;

service
 : TEXT SEPARATOR TEXT SEPARATOR TEXT SEPARATOR TEXT SEPARATOR? newline;



stm : STM;

tariff : TEXT;

newline : NEWLINE*;

number : NUMBER;

separator : SEPARATOR;


NOTE : 'NOTE';

STM : 'STM';

NEWLINE : '\r'? '\n';

NUMBER : (DIGIT)+ ;

SEPARATOR : ';';

TEXT  : ~(';' | '\r' | '\n')+;


fragment DIGIT : '0'..'9' ;

Hi I have this grammar for now,
but when I have after a service, a note. Antlr doesn't want to recognize that it's not the service, but note. And service and note have different structure.
How to write this?

I'm trying to parse this. but NOTE bla bla; is in service

777014322;O2 Optimum Profi Promo;

Free sms;0:00;250:00;0:00;

NOTE bla bla;

STM;



thank you.

    grammar teste;

file : phoneNumber*;

phoneNumber
 : number SEPARATOR tariff SEPARATOR? newline

  service*  
  note? 
  stm SEPARATOR* newline

 ;


note : NOTE TEXT SEPARATOR? newline;

service
 : TEXT SEPARATOR TEXT SEPARATOR TEXT SEPARATOR TEXT SEPARATOR? newline;



stm : STM;

tariff : TEXT;

newline : NEWLINE*;

number : NUMBER;

separator : SEPARATOR;


NOTE : 'NOTE';

STM : 'STM';

NEWLINE : '\r'? '\n';

NUMBER : (DIGIT)+ ;

SEPARATOR : ';';

TEXT  : ~(';' | '\r' | '\n')+;


fragment DIGIT : '0'..'9' ;

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

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

发布评论

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

评论(1

鯉魚旗 2024-08-12 21:42:22

我终于很容易地解决了这个问题,将注释修改为:

NOTE : 'NOTE'TEXT;

尽管我不确定我的语法是否真的很好。但我不确定是否能够从中获取文本到 java 变量中。我希望我是。

I've finally solved it very easily by modifying NOTE to:

NOTE : 'NOTE'TEXT;

Even though I'm not sure if my grammar is really good. But I'm not sure if am able to get text into java variable from this. I hope I am.

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