Starting the parser
git-svn-id: http://picoc.googlecode.com/svn/trunk@8 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
5ddfcfd14a
commit
50c7494508
9
lex.c
9
lex.c
|
@ -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
32
parse.c
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue