Fixed a problem with passing unnamed parameters.
Fixed a problem with file reading. git-svn-id: http://picoc.googlecode.com/svn/trunk@30 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
ef8969d975
commit
a15cf7dd36
5
parse.c
5
parse.c
|
@ -92,6 +92,8 @@ void ParseParameterList(struct LexState *CallLexer, struct LexState *FuncLexer,
|
|||
{
|
||||
ParseType(FuncLexer, &Typ);
|
||||
Token = LexGetToken(FuncLexer, &Identifier);
|
||||
if (Token != TokenComma && Token != TokenCloseBracket)
|
||||
{ /* there's an identifier */
|
||||
if (Token != TokenIdentifier)
|
||||
ProgramFail(FuncLexer, "invalid parameter");
|
||||
|
||||
|
@ -107,6 +109,7 @@ void ParseParameterList(struct LexState *CallLexer, struct LexState *FuncLexer,
|
|||
if (Token != TokenComma && Token != TokenCloseBracket)
|
||||
ProgramFail(FuncLexer, "comma expected");
|
||||
}
|
||||
}
|
||||
if (ParameterUsed == 0)
|
||||
Token = LexGetPlainToken(FuncLexer);
|
||||
|
||||
|
@ -580,9 +583,9 @@ int ParseStatement(struct LexState *Lexer, int RunIt)
|
|||
LexToEndOfLine(Lexer);
|
||||
break;
|
||||
|
||||
case TokenBreak:
|
||||
case TokenSwitch:
|
||||
case TokenCase:
|
||||
case TokenBreak:
|
||||
case TokenReturn:
|
||||
case TokenDefault:
|
||||
ProgramFail(Lexer, "not implemented yet");
|
||||
|
|
19
picoc.c
19
picoc.c
|
@ -31,10 +31,11 @@ void ProgramFail(struct LexState *Lexer, const char *Message, ...)
|
|||
|
||||
/* read a file into memory. this is the only function using malloc().
|
||||
* do it differently for embedded devices without malloc */
|
||||
char *ReadFile(const Str *FileName)
|
||||
Str ReadFile(const Str *FileName)
|
||||
{
|
||||
struct stat FileInfo;
|
||||
char *Text;
|
||||
char *ReadText;
|
||||
Str Text;
|
||||
FILE *InFile;
|
||||
char CFileName[PATH_MAX];
|
||||
|
||||
|
@ -43,15 +44,19 @@ char *ReadFile(const Str *FileName)
|
|||
if (stat(CFileName, &FileInfo))
|
||||
Fail("can't read file %s\n", CFileName);
|
||||
|
||||
Text = malloc(FileInfo.st_size);
|
||||
ReadText = malloc(FileInfo.st_size);
|
||||
if (ReadText == NULL)
|
||||
Fail("out of memory\n");
|
||||
|
||||
InFile = fopen(CFileName, "r");
|
||||
if (InFile == NULL)
|
||||
Fail("can't read file %s\n", CFileName);
|
||||
|
||||
if (fread(Text, 1, FileInfo.st_size, InFile) != FileInfo.st_size)
|
||||
if (fread(ReadText, 1, FileInfo.st_size, InFile) != FileInfo.st_size)
|
||||
Fail("can't read file %s\n", CFileName);
|
||||
|
||||
Text.Str = ReadText;
|
||||
Text.Len = FileInfo.st_size;
|
||||
fclose(InFile);
|
||||
|
||||
return Text;
|
||||
|
@ -60,11 +65,7 @@ char *ReadFile(const Str *FileName)
|
|||
/* read and scan a file for definitions */
|
||||
void ScanFile(const Str *FileName)
|
||||
{
|
||||
char *Source;
|
||||
Str SourceStr;
|
||||
|
||||
Source = ReadFile(FileName);
|
||||
StrFromC(&SourceStr, Source);
|
||||
Str SourceStr = ReadFile(FileName);
|
||||
Parse(FileName, &SourceStr, TRUE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue