Completed lexer.
Removed dependence on strtol() git-svn-id: http://picoc.googlecode.com/svn/trunk@7 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
d89cc62990
commit
5ddfcfd14a
35
lex.c
35
lex.c
|
@ -1,4 +1,3 @@
|
|||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "picoc.h"
|
||||
|
@ -39,7 +38,6 @@ void LexInit(struct LexState *Lexer, const Str *Source, const Str *FileName, int
|
|||
Lexer->FileName = FileName;
|
||||
}
|
||||
|
||||
|
||||
enum LexToken LexCheckReservedWord(const Str *Word)
|
||||
{
|
||||
int Count;
|
||||
|
@ -53,14 +51,17 @@ enum LexToken LexCheckReservedWord(const Str *Word)
|
|||
return TokenNone;
|
||||
}
|
||||
|
||||
|
||||
enum LexToken LexGetNumber(struct LexState *Lexer)
|
||||
{
|
||||
Lexer->Value.Integer = strtol(Lexer->Pos, &Lexer->Pos, 10);
|
||||
int Result = 0;
|
||||
|
||||
while (Lexer->Pos != Lexer->End && isdigit(*Lexer->Pos))
|
||||
Result = Result * 10 + (*Lexer->Pos - '0');
|
||||
|
||||
Lexer->Value.Integer = Result;
|
||||
return TokenIntegerConstant;
|
||||
}
|
||||
|
||||
|
||||
enum LexToken LexGetWord(struct LexState *Lexer)
|
||||
{
|
||||
const char *Pos = Lexer->Pos + 1;
|
||||
|
@ -80,14 +81,26 @@ enum LexToken LexGetWord(struct LexState *Lexer)
|
|||
return TokenIdentifier;
|
||||
}
|
||||
|
||||
|
||||
enum LexToken LexGetStringConstant(struct LexState *Lexer)
|
||||
{
|
||||
// XXX
|
||||
int Escape = FALSE;
|
||||
|
||||
Lexer->Pos++;
|
||||
Lexer->Value.String.Str = Lexer->Pos;
|
||||
while (Lexer->Pos != Lexer->End && !Escape && *Lexer->Pos != '"')
|
||||
{
|
||||
if (Escape)
|
||||
Escape = FALSE;
|
||||
else if (*Lexer->Pos == '\\')
|
||||
Escape = TRUE;
|
||||
}
|
||||
Lexer->Value.String.Len = Lexer->Pos - Lexer->Value.String.Str;
|
||||
if (*Lexer->Pos != '"')
|
||||
Lexer->Pos++;
|
||||
|
||||
return TokenStringConstant;
|
||||
}
|
||||
|
||||
|
||||
enum LexToken LexGetCharacterConstant(struct LexState *Lexer)
|
||||
{
|
||||
Lexer->Value.Integer = Lexer->Pos[1];
|
||||
|
@ -98,14 +111,18 @@ enum LexToken LexGetCharacterConstant(struct LexState *Lexer)
|
|||
return TokenCharacterConstant;
|
||||
}
|
||||
|
||||
|
||||
enum LexToken LexGetToken(struct LexState *Lexer)
|
||||
{
|
||||
char ThisChar;
|
||||
char NextChar;
|
||||
|
||||
while (Lexer->Pos != Lexer->End && isspace(*Lexer->Pos))
|
||||
{
|
||||
if (*Lexer->Pos == '\n')
|
||||
Lexer->Line++;
|
||||
|
||||
Lexer->Pos++;
|
||||
}
|
||||
|
||||
if (Lexer->Pos == Lexer->End)
|
||||
return TokenEOF;
|
||||
|
|
Loading…
Reference in a new issue