Let the scanner returned unsigned integers

- The scanner already recognized the u suffix for unsigned integers, but
  otherwise ignored it. Return it as a proper token.
This commit is contained in:
Randy Heit 2013-09-10 21:40:05 -05:00
parent aec6aff7a8
commit 33344201fa
3 changed files with 15 additions and 3 deletions

View file

@ -530,8 +530,19 @@ bool FScanner::GetToken ()
else if (TokenType == TK_IntConst)
{
char *stopper;
Number = strtol(String, &stopper, 0);
Float = Number;
// Check for unsigned
if (String[StringLen - 1] == 'u' || String[StringLen - 1] == 'U' ||
String[StringLen - 2] == 'u' || String[StringLen - 2] == 'U')
{
TokenType = TK_UIntConst;
Number = strtoul(String, &stopper, 0);
Float = (unsigned)Number;
}
else
{
Number = strtol(String, &stopper, 0);
Float = Number;
}
}
else if (TokenType == TK_FloatConst)
{

View file

@ -188,7 +188,7 @@ std2:
L (L|D)* { RET(TK_Identifier); }
("0" [xX] H+ IS?) | ("0" D+ IS?) | (D+ IS?)
("0" [xX] H+ IS?IS?) | ("0" D+ IS?IS?) | (D+ IS?IS?)
{ RET(TK_IntConst); }
(D+ E FS?) | (D* "." D+ E? FS?) | (D+ "." D* E? FS?)

View file

@ -2,6 +2,7 @@ xx(TK_Identifier, "identifier")
xx(TK_StringConst, "string constant")
xx(TK_NameConst, "name constant")
xx(TK_IntConst, "integer constant")
xx(TK_UIntConst, "unsigned constant")
xx(TK_FloatConst, "float constant")
xx(TK_NonWhitespace, "non-whitespace")
xx(TK_ColonColon, "'::'")