SmaCC: Re-parsing strings as expressions #4100
-
I'd like to parse this
Here
I'd like to avoid implementing a separate preprocessor if possible. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 1 reply
-
Depending on your grammar, you may be able to treat it like a function call. Most likely you won't be able to do that and then the solution is to either implement a preprocessor or do some sort of tricks with how you handle tokens coming from the scanner. For example, you could expand the tokens for the |
Beta Was this translation helpful? Give feedback.
-
What is like to do is disable the string token from the method associated
with the @define token, then enable it back when done processing.
Can I do this and how?
|
Beta Was this translation helpful? Give feedback.
-
This is it exactly! I would like to expand expand I32 into its collection
of tokens.
I need to capture those tokens first, though, and right now they are
captured as a string.
So how would I set up this expansion with SmaCC?
|
Beta Was this translation helpful? Give feedback.
-
You could do something like override the |
Beta Was this translation helpful? Give feedback.
-
John, this is great advice! But how and when would I parse the original macro definition string to get its tokens? Is there a way to enable/disable tokens at runtime? I think all my problems would be solved by disabling the string token at the beginning of the macro definition production and re-enabling it at the end. There can be no strings within a macro definition so the approach should work. |
Beta Was this translation helpful? Give feedback.
-
Without knowing the specifics of what you are doing, there are a couple ways you can do things. One would be to define a scanner method for the |
Beta Was this translation helpful? Give feedback.
-
You could do something like this:
And define a
With this you can parse |
Beta Was this translation helpful? Give feedback.
You could do something like this:
And define a
define
method on your scanner:With this you can parse
@define asdf {{}}{{}{{} ; Foo
. It will skip over the@define
stuff and only see theFoo
token. For your use, you would need to store the tokens so you could replay them when you see the reference.