This repository was archived by the owner on Dec 21, 2025. It is now read-only.
Allowing a feature for preprocessors by appending "lookahead" and "lookaheadstack " under "self."#33
Open
tanhongze wants to merge 1 commit intodabeaz:masterfrom
tanhongze:preprocessor-support-branch
Open
Allowing a feature for preprocessors by appending "lookahead" and "lookaheadstack " under "self."#33tanhongze wants to merge 1 commit intodabeaz:masterfrom tanhongze:preprocessor-support-branch
tanhongze wants to merge 1 commit intodabeaz:masterfrom
tanhongze:preprocessor-support-branch
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello,
I found that when writing a pre-processor, new tokens could be insert before the look-ahead token.
For example, using a syntax like C pre-processor (or Verilog pre-processor)
will generate a result as "A b".
It could be solved by pushing the look-ahead token back to the look-ahead stack in my parser.
And since a macro won't need the look-ahead token, the changing of next token won't disturb the parsing process.
To support this feature, the look-ahead token and the look-ahead stack need be visible in other function in the parser and I simply add "self." to each "lookahead" and "lookaheadstack" in function "parse", file "yacc.py".
It can successfully pass all of the given tests with command-line "pytest ./tests/".
========================== 11 passed in 0.08 seconds ===========================By the way, I found that SLY is pretty cool. I had a dream to write a compiler when I was having my "compilers' principles" class and it really helps.