Skip to content

How would it be possible to look ahead more than one token? #2

Answered by atifaziz
springcomp asked this question in Q&A
Discussion options

You must be logged in to vote

I wonder if you could disambiguate at the tokenization level in this particular case. In other words, what if you tried treating "[" "*" "]" as a single token along? As in:

T_STAR = "*"
T_LBRACKET = "["
T_RBRACKET = "]"
T_BRACKETED_STAR = "[" "*" "]"

If just two tokens are sufficient to disambiguate then you could just go with:

T_STAR = "*"
T_LBRACKET = "["
T_RBRACKET = "]"
T_LBRACKET_STAR = "[" "*"

This way, you could easily do your lookaheads at the character level during tokenization rather than needing to do it during parsing.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@springcomp
Comment options

@springcomp
Comment options

@atifaziz
Comment options

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

This discussion was converted from issue #1 on July 04, 2022 20:22.