First stab at interactive mode needs debug.

git-svn-id: http://picoc.googlecode.com/svn/trunk@164 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-03-07 11:23:42 +00:00
parent 9780c54403
commit 05d377e49d
4 changed files with 20 additions and 3 deletions

2
lex.c
View file

@ -460,7 +460,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I
return TokenEOF;
/* put the new line at the end of the linked list of interactive lines */
LineTokens = LexAnalyse(TableStrRegister("input"), &LineBuffer[0], strlen(LineBuffer), &LineBytes);
LineTokens = LexAnalyse(StrEmpty, &LineBuffer[0], strlen(LineBuffer), &LineBytes);
LineNode = VariableAlloc(Parser, sizeof(struct TokenLine), TRUE);
LineNode->Tokens = LineTokens;
LineNode->NumBytes = LineBytes;

11
parse.c
View file

@ -1070,3 +1070,14 @@ void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt)
HeapFree(Tokens);
}
/* parse interactively */
void ParseInteractive()
{
struct ParseState Parser;
LexInitParser(&Parser, NULL, StrEmpty, 1, TRUE);
while (ParseStatement(&Parser))
LexInteractiveCompleted(&Parser);
}

View file

@ -18,13 +18,16 @@ void Initialise()
int main(int argc, char **argv)
{
if (argc < 2)
ProgramFail(NULL, "Format: picoc <program.c> <args>...\n");
ProgramFail(NULL, "Format: picoc <program.c> - run a program\n picoc -i - interactive mode\n");
Initialise();
if (PlatformSetExitPoint())
return 1;
PlatformScanFile(argv[1]);
if (strcmp(argv[1], "-i") == 0)
ParseInteractive();
else
PlatformScanFile(argv[1]);
return 0;
}

View file

@ -20,6 +20,7 @@
#define MEM_ALIGN(x) (((x) + ARCH_ALIGN_WORDSIZE - 1) & ~(ARCH_ALIGN_WORDSIZE-1))
#define LOG10E 0.43429448190325182765
#define INTERACTIVE_FILE_NAME "input"
#ifndef PATH_MAX
#define PATH_MAX 1024
@ -259,6 +260,7 @@ void LexInitParser(struct ParseState *Parser, void *TokenSource, const char *Fil
enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int IncPos);
void LexToEndOfLine(struct ParseState *Parser);
void *LexCopyTokens(struct ParseState *StartParser, struct ParseState *EndParser);
void LexInteractiveCompleted(struct ParseState *Parser);
/* parse.c */
int ParseExpression(struct ParseState *Parser, struct Value **Result);
@ -266,6 +268,7 @@ int ParseIntExpression(struct ParseState *Parser);
int ParseStatement(struct ParseState *Parser);
struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueType *ReturnType, char *Identifier, int IsProtoType);
void Parse(const char *FileName, const char *Source, int SourceLen, int RunIt);
void ParseInteractive();
/* type.c */
void TypeInit();