Skip to content

Question about best practice regarding the lexer and negative look aheads. #2039

Answered by msujew
khkiley asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @khkiley,

Generally, I'd say that, if it's not absolutely necessary to facilitate correct lexing/parsing, you shouldn't use negative/positive lookaheads/lookbehinds. It adds complexity and most importantly has a negative performance impact.

For your specific question: It depends. In most normal languages, a string such as 123abc will be lexed as [INT, ID] tokens. If you add the negative lookahead, the lexer will need to find another matching token, maybe just [ID]. This is fine, if you allow variable names such as 123abc, but might otherwise lead to unexpected behavior. If the lexer doesn't find a matching token, it will yield a lexing error, Any characters included in that error will…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by msujew
Comment options

You must be logged in to vote
2 replies
@bd82
Comment options

@khkiley
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2038 on August 18, 2024 21:21.