From 70cc4eae498ef62cba353bbc7126bb9b2be57b6f Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 3 Feb 2009 11:09:07 +0000 Subject: [PATCH] Fixed lexer EOF handling when whitespace at end of file git-svn-id: http://picoc.googlecode.com/svn/trunk@63 21eae674-98b7-11dd-bd71-f92a316d2d60 --- Makefile | 2 +- lex.c | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index db40e4f..62647e1 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-Wall -g +CFLAGS=-Wall -g -DDEBUG_HEAP LIBS=-lm TARGET = picoc diff --git a/lex.c b/lex.c index 57edf72..af8fc20 100644 --- a/lex.c +++ b/lex.c @@ -214,18 +214,6 @@ enum LexToken LexScanGetToken(struct LexState *Lexer, struct Value **Value) do { - if (Lexer->Pos == Lexer->End) - { /* end of input */ - if (Lexer->FileName == StrEmpty) - { /* get interactive input */ - char LineBuffer[LINEBUFFER_MAX]; - if (fgets(&LineBuffer[0], LINEBUFFER_MAX, stdin) == NULL) - return TokenEOF; - } - else - return TokenEOF; - } - *Value = &LexValue; while (Lexer->Pos != Lexer->End && isspace(*Lexer->Pos)) { @@ -235,6 +223,20 @@ enum LexToken LexScanGetToken(struct LexState *Lexer, struct Value **Value) Lexer->Pos++; } + if (Lexer->Pos == Lexer->End) + { /* end of input */ + if (Lexer->FileName == StrEmpty) + { /* get interactive input */ + char LineBuffer[LINEBUFFER_MAX]; + if (fgets(&LineBuffer[0], LINEBUFFER_MAX, stdin) == NULL) + return TokenEOF; + + // XXX - finish this + } + else + return TokenEOF; + } + ThisChar = *Lexer->Pos; if (isCidstart(ThisChar)) return LexGetWord(Lexer, *Value);