can an element contain attribute as parsed by parser generated by ANTLR? if so, how?

前端 未结 3 1798
野性不改
野性不改 2021-01-26 17:42

I am following this tutorial and successfully replicated its behavior except that I am using Antlr 4.7 instead of the 4.5 that the tutorial was using.

I am trying to bui

3条回答
  •  春和景丽
    2021-01-26 18:21

    I'm not entirely sure what exactly you want but for the provided examples this grammar should do the job:

    payments: (payment NL)* ;  
    payment: PAY receiver amount=NUMBER ;  
    receiver: surname=ID (lastname=ID)? ;  
    
    PAY: 'pay' ;
    NUMBER: [0-9]+ (',' [0-9]+)+ ('.' [0-9]+)? ;  
    ID: [a-zA-Z0-9_]+ ;
    NL: '\n' | '\r\n' ;  
    WS: [\t ]+ -> skip ;
    

    If this is what you were asking for I will add some more explanation if needed...

提交回复
热议问题