Starting the parser

git-svn-id: http://picoc.googlecode.com/svn/trunk@8 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2008-10-16 07:04:23 +00:00
parent 5ddfcfd14a
commit 50c7494508
2 changed files with 38 additions and 3 deletions

9
lex.c
View file

@ -20,14 +20,19 @@ struct ReservedWord
static struct ReservedWord ReservedWords[] =
{
{ "break", TokenBreak },
{ "case", TokenCase },
{ "char", TokenCharType },
{ "default", TokenDefault },
{ "do", TokenDo },
{ "else", TokenElse },
{ "for", TokenFor },
{ "if", TokenIf },
{ "int", TokenIntType },
{ "while", TokenWhile },
{ "void", TokenVoidType }
{ "return", TokenReturn },
{ "switch", TokenSwitch },
{ "void", TokenVoidType },
{ "while", TokenWhile }
};
void LexInit(struct LexState *Lexer, const Str *Source, const Str *FileName, int Line)

32
parse.c
View file

@ -13,6 +13,37 @@ void ParseInit()
TableInit(&GlobalTable, &GlobalHashTable[0], "global", GLOBAL_TABLE_SIZE);
}
/* parse and run some code */
void ParseRun(const Str *FileName, const Str *Source, int LineNo)
{
enum LexToken Token;
struct LexState Lexer;
int ParseDepth = 0;
int IntValue;
LexInit(&Lexer, Source, FileName, 1);
while ( (Token = LexGetToken(&Lexer)) != TokenEOF)
{
/* do parsey things here */
StrPrintf("token %d\n", (int)Token);
switch (ParseDepth)
{
case 0: /* top level */
if (Token == XXX
break;
case X: /* primary expression */
switch (Token)
{
case TokenIdentifier: IntValue = XXX; GoUp = TRUE; break;
case TokenIntegerConstant: IntValue = Lexer->Value.Integer; GoUp = TRUE; break;
case TokenStringConstant: StringValue = Lexer->Value.String; GoUp = TRUE; break;
case TokenOpenBracket:
}
}
}
/* quick scan a source file for definitions */
void ParseScan(const Str *FileName, const Str *Source)
@ -29,7 +60,6 @@ void ParseScan(const Str *FileName, const Str *Source)
}
}
void ParseCallFunction(const Str *FuncIdent, int argc, char **argv)
{
}