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:
parent
809cdf5b94
commit
3deb0908bb
36
lex.c
36
lex.c
|
@ -74,6 +74,7 @@ static struct ReservedWord ReservedWords[] =
|
||||||
{ "short", TokenShortType, NULL },
|
{ "short", TokenShortType, NULL },
|
||||||
{ "signed", TokenSignedType, NULL },
|
{ "signed", TokenSignedType, NULL },
|
||||||
{ "sizeof", TokenSizeof, NULL },
|
{ "sizeof", TokenSizeof, NULL },
|
||||||
|
{ "static", TokenStaticType, NULL },
|
||||||
{ "struct", TokenStructType, NULL },
|
{ "struct", TokenStructType, NULL },
|
||||||
{ "switch", TokenSwitch, NULL },
|
{ "switch", TokenSwitch, NULL },
|
||||||
{ "typedef", TokenTypedef, NULL },
|
{ "typedef", TokenTypedef, NULL },
|
||||||
|
@ -168,6 +169,16 @@ enum LexToken LexGetNumber(struct LexState *Lexer, struct Value *Value)
|
||||||
Value->Val->Integer = Result;
|
Value->Val->Integer = Result;
|
||||||
ResultToken = TokenIntegerConstant;
|
ResultToken = TokenIntegerConstant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Lexer->Pos == Lexer->End)
|
||||||
|
return ResultToken;
|
||||||
|
|
||||||
|
if (*Lexer->Pos == 'l' || *Lexer->Pos == 'L')
|
||||||
|
{
|
||||||
|
LEXER_INC(Lexer);
|
||||||
|
return ResultToken;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
if (Lexer->Pos == Lexer->End || *Lexer->Pos != '.')
|
if (Lexer->Pos == Lexer->End || *Lexer->Pos != '.')
|
||||||
return ResultToken;
|
return ResultToken;
|
||||||
|
@ -349,17 +360,29 @@ enum LexToken LexGetCharacterConstant(struct LexState *Lexer, struct Value *Valu
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip a comment - used while scanning */
|
/* 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);
|
LEXER_INC(Lexer);
|
||||||
if (NextChar == '*')
|
if (NextChar == '*')
|
||||||
{
|
{
|
||||||
/* conventional C comment */
|
/* conventional C comment */
|
||||||
while (Lexer->Pos != Lexer->End && (*(Lexer->Pos-1) != '*' || *Lexer->Pos != '/'))
|
while (Lexer->Pos != Lexer->End && (*(Lexer->Pos-1) != '*' || *Lexer->Pos != '/'))
|
||||||
|
{
|
||||||
|
if (*Lexer->Pos == '\n')
|
||||||
|
{
|
||||||
LEXER_INC(Lexer);
|
LEXER_INC(Lexer);
|
||||||
|
Lexer->Mode = LexModeMultiLineComment;
|
||||||
|
*ReturnToken = TokenEndOfLine;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LEXER_INC(Lexer);
|
||||||
|
}
|
||||||
|
|
||||||
if (Lexer->Pos != Lexer->End)
|
if (Lexer->Pos != Lexer->End)
|
||||||
LEXER_INC(Lexer);
|
LEXER_INC(Lexer);
|
||||||
|
|
||||||
|
Lexer->Mode = LexModeNormal;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -376,6 +399,15 @@ enum LexToken LexScanGetToken(struct LexState *Lexer, struct Value **Value)
|
||||||
char NextChar;
|
char NextChar;
|
||||||
enum LexToken GotToken = TokenNone;
|
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
|
do
|
||||||
{
|
{
|
||||||
*Value = &LexValue;
|
*Value = &LexValue;
|
||||||
|
@ -422,7 +454,7 @@ enum LexToken LexScanGetToken(struct LexState *Lexer, struct Value **Value)
|
||||||
case '+': NEXTIS3('=', TokenAddAssign, '+', TokenIncrement, TokenPlus); break;
|
case '+': NEXTIS3('=', TokenAddAssign, '+', TokenIncrement, TokenPlus); break;
|
||||||
case '-': NEXTIS4('=', TokenSubtractAssign, '>', TokenArrow, '-', TokenDecrement, TokenMinus); break;
|
case '-': NEXTIS4('=', TokenSubtractAssign, '>', TokenArrow, '-', TokenDecrement, TokenMinus); break;
|
||||||
case '*': NEXTIS('=', TokenMultiplyAssign, TokenAsterisk); 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 '%': NEXTIS('=', TokenModulusAssign, TokenModulus); break;
|
||||||
case '<': if (Lexer->Mode == LexModeHashInclude) GotToken = LexGetStringConstant(Lexer, *Value, '>'); else { NEXTIS3PLUS('=', TokenLessEqual, '<', TokenShiftLeft, '=', TokenShiftLeftAssign, TokenLessThan); } break;
|
case '<': if (Lexer->Mode == LexModeHashInclude) GotToken = LexGetStringConstant(Lexer, *Value, '>'); else { NEXTIS3PLUS('=', TokenLessEqual, '<', TokenShiftLeft, '=', TokenShiftLeftAssign, TokenLessThan); } break;
|
||||||
case '>': NEXTIS3PLUS('=', TokenGreaterEqual, '>', TokenShiftRight, '=', TokenShiftRightAssign, TokenGreaterThan); break;
|
case '>': NEXTIS3PLUS('=', TokenGreaterEqual, '>', TokenShiftRight, '=', TokenShiftRightAssign, TokenGreaterThan); break;
|
||||||
|
|
1
parse.c
1
parse.c
|
@ -571,6 +571,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
|
||||||
case TokenEnumType:
|
case TokenEnumType:
|
||||||
case TokenSignedType:
|
case TokenSignedType:
|
||||||
case TokenUnsignedType:
|
case TokenUnsignedType:
|
||||||
|
case TokenStaticType:
|
||||||
*Parser = PreState;
|
*Parser = PreState;
|
||||||
CheckTrailingSemicolon = ParseDeclaration(Parser, Token);
|
CheckTrailingSemicolon = ParseDeclaration(Parser, Token);
|
||||||
break;
|
break;
|
||||||
|
|
6
picoc.h
6
picoc.h
|
@ -73,7 +73,7 @@ enum LexToken
|
||||||
/* 0x32 */ TokenSemicolon, TokenEllipsis,
|
/* 0x32 */ TokenSemicolon, TokenEllipsis,
|
||||||
/* 0x34 */ TokenLeftBrace, TokenRightBrace,
|
/* 0x34 */ TokenLeftBrace, TokenRightBrace,
|
||||||
/* 0x36 */ TokenIntType, TokenCharType, TokenFloatType, TokenDoubleType, TokenVoidType, TokenEnumType,
|
/* 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,
|
/* 0x43 */ TokenContinue, TokenDo, TokenElse, TokenFor, TokenIf, TokenWhile, TokenBreak, TokenSwitch, TokenCase, TokenDefault, TokenReturn,
|
||||||
/* 0x4e */ TokenHashDefine, TokenHashInclude, TokenHashIf, TokenHashIfdef, TokenHashIfndef, TokenHashElse, TokenHashEndif,
|
/* 0x4e */ TokenHashDefine, TokenHashInclude, TokenHashIf, TokenHashIfdef, TokenHashIfndef, TokenHashElse, TokenHashEndif,
|
||||||
/* 0x55 */ TokenNew, TokenDelete,
|
/* 0x55 */ TokenNew, TokenDelete,
|
||||||
|
@ -185,7 +185,6 @@ union AnyValue
|
||||||
unsigned long UnsignedLongInteger;
|
unsigned long UnsignedLongInteger;
|
||||||
char *Identifier;
|
char *Identifier;
|
||||||
char ArrayMem[2]; /* placeholder for where the data starts, doesn't point to it */
|
char ArrayMem[2]; /* placeholder for where the data starts, doesn't point to it */
|
||||||
/* struct ParseState Parser; */
|
|
||||||
struct ValueType *Typ;
|
struct ValueType *Typ;
|
||||||
struct FuncDef FuncDef;
|
struct FuncDef FuncDef;
|
||||||
struct MacroDef MacroDef;
|
struct MacroDef MacroDef;
|
||||||
|
@ -247,7 +246,8 @@ enum LexMode
|
||||||
LexModeHashInclude,
|
LexModeHashInclude,
|
||||||
LexModeHashDefine,
|
LexModeHashDefine,
|
||||||
LexModeHashDefineSpace,
|
LexModeHashDefineSpace,
|
||||||
LexModeHashDefineSpaceIdent
|
LexModeHashDefineSpaceIdent,
|
||||||
|
LexModeMultiLineComment
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LexState
|
struct LexState
|
||||||
|
|
4
type.c
4
type.c
|
@ -323,6 +323,10 @@ int TypeParseFront(struct ParseState *Parser, struct ValueType **Typ)
|
||||||
struct Value *VarValue;
|
struct Value *VarValue;
|
||||||
*Typ = NULL;
|
*Typ = NULL;
|
||||||
|
|
||||||
|
/* ignore leading type qualifiers */
|
||||||
|
while (Token == TokenStaticType)
|
||||||
|
Token = LexGetToken(Parser, &LexerValue, TRUE);
|
||||||
|
|
||||||
/* handle signed/unsigned with no trailing type */
|
/* handle signed/unsigned with no trailing type */
|
||||||
if (Token == TokenSignedType || Token == TokenUnsignedType)
|
if (Token == TokenSignedType || Token == TokenUnsignedType)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue