Lexer rule that allows identifiers to begin with digits #4854
Unanswered
The-Futurist
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
If your grammar also supports non-decimal numbers, you might have a problem: |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
OK I think I have solved my problem now. Rather than messing with identifiers, I just added a new kind of literal (based on a new token with Then the language itself will define a way to define such literals with actual literal-decimal values and it's that value that will be seen/used by the compilation process itself. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm considering updating my grammar for a new language and want to support identifiers that begin with one or more digits. This seems to work fine but am I missing something? is there some edge case I'm not considering? (tests seem to suggest this works fine)
IDENTIFIER: [0-9]* [a-zA-Z_] [a-zA-Z0-9_]*;prior this tweak the rule was simply:
IDENTIFIER: [a-zA-Z_] [a-zA-Z0-9_]*;In fact I'd be interested to be able to class the following as identifiers too:
123.5nF0.1KHzBearing in mind the language uses DOT as a separator in structure member references and namespaces, but that should all still work because they are parse rules and once a identifier is recognized the fact it might have a DOT in it (as shown above) is immaterial.
I do currently recognize this kind of thing as a DECIMAL token:
123.4560.11055Beta Was this translation helpful? Give feedback.
All reactions