Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Recursive Lexer Rules in ANTLR4 good for?

Tags:

antlr

antlr4

Just beginning with ANTLR4. Found that lexer rules can be recursive https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#recursive-lexer-rules. What is the use case to use recursive lexer rules instead of recursive parser rules? Dont you loose all the information when using lexer recursive rules?

like image 515
igo Avatar asked Nov 02 '25 09:11

igo


1 Answers

As mentioned in the comments by sepp2k: besides nested string literals, nested comments are 1 of the use cases:

COMMENT
 : '/*' ( COMMENT | . )*? '*/'
 ;
like image 122
Bart Kiers Avatar answered Nov 04 '25 13:11

Bart Kiers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!