bxb100 / bxb100.github.io

This is my blog
https://blog.tomcat.run
MIT License
1 stars 0 forks source link

ANTLR 速记 #31

Open bxb100 opened 1 year ago

bxb100 commented 1 year ago

结合性和左、右递归

grammar Expr;

expr: expr '^' expr
| INT
;

INT: [0-9]+;
WS: [ \t\r\n]+ -> skip;

使用 assoc

grammar Expr;

expr: <assoc=right> expr '^' expr
| INT
;

INT: [0-9]+;
WS: [ \t\r\n]+ -> skip;
image
bxb100 commented 1 year ago

左递归

*( *a) [] []

grammar PC;

decl: decl '[' ']'
| '*' decl
| '(' decl ')'
| ID
;

ID: [a-zA-Z]+;
WS: [ \t\r\n]+ -> skip;
image