Replies: 1 comment 2 replies
-
Yes, you can call only the lexer if you want. I do this when printing out tokens in a driver written as a template. https://github.com/kaby76/Domemtech.Trash/blob/main/src/trgen/templates/CSharp/Test.cs#L231-L239 But, if this is to provide a parser-sensitive lexer, it doesn't make sense to use the generated lexer. That's because the API does not pass the state of the parser into LT(). That, in fact, is the "call back" from the parser to the lexer. To change this behavior if you were to still use an Antlr parser, you would need to add code to provide state to the lexer in at least two codes: the generated parser code, and the parser ATN engine--basically anywhere |
Beta Was this translation helpful? Give feedback.
-
I'm wondering how one leverages a generated lexer. I might want to write my own recursive descent parser and create my AST as I do so. I could then leverage the Atlr4 Lexer as my token source and still get a huge benefit.
Do people "do this"? has anyone taken this approach?
Also, kind of related, is there any way to have the generated parser "call back" a handler that I supply, but as it parses the input?
This would be an alternative strategy for creating an AST in addition to the visitor and listener options.
Beta Was this translation helpful? Give feedback.
All reactions