Now recognising and ignoring "static".

Recognising and ignoring 'L' following integer constants.
Tallying the line count in multi-line C-style comments more correctly.



git-svn-id: http://picoc.googlecode.com/svn/trunk@466 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2010-07-18 20:27:05 +00:00
parent 809cdf5b94
commit 3deb0908bb
4 changed files with 43 additions and 6 deletions

38
lex.c
View file

@ -74,6 +74,7 @@ static struct ReservedWord ReservedWords[] =
{ "short", TokenShortType, NULL },
{ "signed", TokenSignedType, NULL },
{ "sizeof", TokenSizeof, NULL },
{ "static", TokenStaticType, NULL },
{ "struct", TokenStructType, NULL },
{ "switch", TokenSwitch, NULL },
{ "typedef", TokenTypedef, NULL },
@ -168,6 +169,16 @@ enum LexToken LexGetNumber(struct LexState *Lexer, struct Value *Value)
Value->Val->Integer = Result;
ResultToken = TokenIntegerConstant;
}
if (Lexer->Pos == Lexer->End)
return ResultToken;
if (*Lexer->Pos == 'l' || *Lexer->Pos == 'L')
{
LEXER_INC(Lexer);
return ResultToken;
}
#ifndef NO_FP
if (Lexer->Pos == Lexer->End || *Lexer->Pos != '.')
return ResultToken;
@ -349,17 +360,29 @@ enum LexToken LexGetCharacterConstant(struct LexState *Lexer, struct Value *Valu
}
/* skip a comment - used while scanning */
void LexSkipComment(struct LexState *Lexer, char NextChar)
void LexSkipComment(struct LexState *Lexer, char NextChar, enum LexToken *ReturnToken)
{
LEXER_INC(Lexer);
if (NextChar == '*')
{
/* conventional C comment */
while (Lexer->Pos != Lexer->End && (*(Lexer->Pos-1) != '*' || *Lexer->Pos != '/'))
LEXER_INC(Lexer);
{
if (*Lexer->Pos == '\n')
{
LEXER_INC(Lexer);
Lexer->Mode = LexModeMultiLineComment;
*ReturnToken = TokenEndOfLine;
return;
}
else
LEXER_INC(Lexer);
}
if (Lexer->Pos != Lexer->End)
LEXER_INC(Lexer);
Lexer->Mode = LexModeNormal;
}
else
{
@ -376,6 +399,15 @@ enum LexToken LexScanGetToken(struct LexState *Lexer, struct Value **Value)
char NextChar;
enum LexToken GotToken = TokenNone;
/* handle the end of multi-line comments */
if (Lexer->Mode == LexModeMultiLineComment)
{
LexSkipComment(Lexer, '*', &GotToken);
if (GotToken != TokenNone)
return GotToken;
}
/* scan for a token */
do
{
*Value = &LexValue;
@ -422,7 +454,7 @@ enum LexToken LexScanGetToken(struct LexState *Lexer, struct Value **Value)
case '+': NEXTIS3('=', TokenAddAssign, '+', TokenIncrement, TokenPlus); break;
case '-': NEXTIS4('=', TokenSubtractAssign, '>', TokenArrow, '-', TokenDecrement, TokenMinus); break;
case '*': NEXTIS('=', TokenMultiplyAssign, TokenAsterisk); break;
case '/': if (NextChar == '/' || NextChar == '*') LexSkipComment(Lexer, NextChar); else NEXTIS('=', TokenDivideAssign, TokenSlash); break;
case '/': if (NextChar == '/' || NextChar == '*') LexSkipComment(Lexer, NextChar, &GotToken); else NEXTIS('=', TokenDivideAssign, TokenSlash); break;
case '%': NEXTIS('=', TokenModulusAssign, TokenModulus); break;
case '<': if (Lexer->Mode == LexModeHashInclude) GotToken = LexGetStringConstant(Lexer, *Value, '>'); else { NEXTIS3PLUS('=', TokenLessEqual, '<', TokenShiftLeft, '=', TokenShiftLeftAssign, TokenLessThan); } break;
case '>': NEXTIS3PLUS('=', TokenGreaterEqual, '>', TokenShiftRight, '=', TokenShiftRightAssign, TokenGreaterThan); break;

View file

@ -571,6 +571,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
case TokenEnumType:
case TokenSignedType:
case TokenUnsignedType:
case TokenStaticType:
*Parser = PreState;
CheckTrailingSemicolon = ParseDeclaration(Parser, Token);
break;

View file

@ -73,7 +73,7 @@ enum LexToken
/* 0x32 */ TokenSemicolon, TokenEllipsis,
/* 0x34 */ TokenLeftBrace, TokenRightBrace,
/* 0x36 */ TokenIntType, TokenCharType, TokenFloatType, TokenDoubleType, TokenVoidType, TokenEnumType,
/* 0x3c */ TokenLongType, TokenSignedType, TokenShortType, TokenStructType, TokenUnionType, TokenUnsignedType, TokenTypedef,
/* 0x3c */ TokenLongType, TokenSignedType, TokenShortType, TokenStaticType, TokenStructType, TokenUnionType, TokenUnsignedType, TokenTypedef,
/* 0x43 */ TokenContinue, TokenDo, TokenElse, TokenFor, TokenIf, TokenWhile, TokenBreak, TokenSwitch, TokenCase, TokenDefault, TokenReturn,
/* 0x4e */ TokenHashDefine, TokenHashInclude, TokenHashIf, TokenHashIfdef, TokenHashIfndef, TokenHashElse, TokenHashEndif,
/* 0x55 */ TokenNew, TokenDelete,
@ -185,7 +185,6 @@ union AnyValue
unsigned long UnsignedLongInteger;
char *Identifier;
char ArrayMem[2]; /* placeholder for where the data starts, doesn't point to it */
/* struct ParseState Parser; */
struct ValueType *Typ;
struct FuncDef FuncDef;
struct MacroDef MacroDef;
@ -247,7 +246,8 @@ enum LexMode
LexModeHashInclude,
LexModeHashDefine,
LexModeHashDefineSpace,
LexModeHashDefineSpaceIdent
LexModeHashDefineSpaceIdent,
LexModeMultiLineComment
};
struct LexState

4
type.c
View file

@ -323,6 +323,10 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ)
struct Value *VarValue;
*Typ = NULL;
/* ignore leading type qualifiers */
while (Token == TokenStaticType)
Token = LexGetToken(Parser, &LexerValue, TRUE);
/* handle signed/unsigned with no trailing type */
if (Token == TokenSignedType || Token == TokenUnsignedType)
{