-
Notifications
You must be signed in to change notification settings - Fork 44
532 support negative numbers #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
532 support negative numbers #872
Conversation
| [InlineData("-10 > 9", false)] | ||
| [InlineData("-10 < 9", true)] | ||
| [InlineData("-10 < -9", true)] | ||
| [InlineData("-9 == -9", true)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add tests for <= >= too. so we can test that these cases coverted too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also can you check that -10 < 0x10 for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, i added
| if (Regex.IsMatch(macrosValue, $"^(0|[1-9][0-9]*)$")) | ||
| return int.Parse(macrosValue); | ||
|
|
||
| if (Regex.IsMatch(macrosValue, $"^(-[1-9][0-9]*)$")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the change should be in CPreprocessorExpresisonParser I think that's change not applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean that this function should not return a negative number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. We belive should not have negative numbers as tokens, expression can have them just fine. Negaive numbers can be treated as unary expression - Token, for example. So likely you should expand expression grammar in the CPreprocessorExpressionParser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if unary expression with minus exists, I left it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suspect that we have other issue here. Numbers are tokens without sign. Sign + or - handled by Unary expression, but that does not work for some reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So probably something wrong with out Regex for PreprocessorToken
Cesium/Cesium.Preprocessor/CPreprocessorTokenType.cs
Lines 32 to 33 in e0091ae
| [Regex("[^ \t\v\f\r\n#;+\\-*/()=!<>\",.|\\[\\]&\\\\]+")] | |
| PreprocessingToken, |
Also I found issue in Yoakke, which generates lexer for us. LanguageDev/Yoakke#186 maybe that's related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suspect that we have other issue here. Numbers are tokens without sign. Sign + or - handled by Unary expression, but that does not work for some reasons.
currently, PreprocessorToken recognize number with operator - (sub) here.
Now Numbers are tokens without sign but with operator sub and etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's not, otherwise how do you get token -10 so you need to handle it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think error here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| || Regex.IsMatch(searchValue, "^0[0-7]+$") | ||
| || Regex.IsMatch(searchValue, "^0b[01]+$")) | ||
| || Regex.IsMatch(searchValue, "^0b[01]+$") | ||
| || Regex.IsMatch(searchValue, "^(-[1-9][0-9]*)$")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the change should be in CPreprocessorExpresisonParser I think that's change not applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
| int Parse(Location location, string macrosValue) | ||
| { | ||
| if (Regex.IsMatch(macrosValue, $"^(0|[1-9][0-9]*)$")) | ||
| if (Regex.IsMatch(macrosValue, $"^(0|-*[1-9][0-9]*)$")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are --0 allowed in C ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we probably should support -0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, -0 is supported by c.
fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about +0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too.
+-...+-+0 and -+...-+-0 are supported. in these cases the result will be 0.
In other words, the result will always be without a sign.
+-+4 => 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry,
If count of - is even then number otherwise -number


No description provided.