Fixed bug108 - brackets were not collapsing the expression stack

as they should have.
Now more permissive in declarations of void main()


git-svn-id: http://picoc.googlecode.com/svn/trunk@520 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2011-02-14 06:05:53 +00:00
parent 3893e46c26
commit b2c4d6ce83
7 changed files with 41 additions and 21 deletions

View file

@ -475,16 +475,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, TRUE)); ExpressionPushInt(Parser, StackTop, TypeSize(TopValue->Typ, TopValue->Typ->ArraySize, TRUE));
break; break;
case TokenLeftSquareBracket:
/* XXX */
ProgramFail(Parser, "not supported");
break;
case TokenOpenBracket:
/* XXX - cast */
ProgramFail(Parser, "not supported");
break;
default: default:
/* an arithmetic operator */ /* an arithmetic operator */
#ifndef NO_FP #ifndef NO_FP
@ -1065,6 +1055,9 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result)
} }
else else
BracketPrecedence -= BRACKET_PRECEDENCE; BracketPrecedence -= BRACKET_PRECEDENCE;
/* collapse to the bracket precedence */
ExpressionStackCollapse(Parser, &StackTop, BracketPrecedence);
break; break;
default: default:

View file

@ -130,8 +130,9 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
if (strcmp(Identifier, "main") == 0) if (strcmp(Identifier, "main") == 0)
{ {
/* make sure it's int main() */ /* make sure it's int main() */
if (FuncValue->Val->FuncDef.ReturnType != &IntType) if ( FuncValue->Val->FuncDef.ReturnType != &IntType &&
ProgramFail(Parser, "main() should return an int"); FuncValue->Val->FuncDef.ReturnType != &VoidType )
ProgramFail(Parser, "main() should return an int or void");
if (FuncValue->Val->FuncDef.NumParams != 0 && if (FuncValue->Val->FuncDef.NumParams != 0 &&
(FuncValue->Val->FuncDef.NumParams != 2 || FuncValue->Val->FuncDef.ParamType[0] != &IntType) ) (FuncValue->Val->FuncDef.NumParams != 2 || FuncValue->Val->FuncDef.ParamType[0] != &IntType) )
@ -498,6 +499,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser, int CheckTrailingSemi
case TokenAmpersand: case TokenAmpersand:
case TokenIncrement: case TokenIncrement:
case TokenDecrement: case TokenDecrement:
case TokenOpenBracket:
*Parser = PreState; *Parser = PreState;
ExpressionParse(Parser, &CValue); ExpressionParse(Parser, &CValue);
if (Parser->Mode == RunModeRun) if (Parser->Mode == RunModeRun)

14
picoc.c
View file

@ -133,16 +133,16 @@ int picoc(char *SourceStr)
Initialise(HEAP_SIZE); Initialise(HEAP_SIZE);
sl = strlen(SourceStr); sl = strlen(SourceStr);
if (SourceStr) if (SourceStr)
{ {
for (i = 0; i < sl; i++) for (i = 0; i < sl; i++)
{ {
if (SourceStr[i] == 0x1A) if (SourceStr[i] == 0x1A)
{ {
SourceStr[i] = 0x20; SourceStr[i] = 0x20;
} }
} }
} }
ExitBuf[40] = 0; ExitBuf[40] = 0;
PlatformSetExitPoint(); PlatformSetExitPoint();

View file

@ -221,11 +221,13 @@ void print_led(unsigned long x, char *buf)
*buf='\0'; *buf='\0';
} }
void main() int main()
{ {
char buf[5*MAX_DIGITS]; char buf[5*MAX_DIGITS];
print_led(1234567, buf); print_led(1234567, buf);
printf("%s\n",buf); printf("%s\n",buf);
return 0;
} }
#ifndef NO_MAIN #ifndef NO_MAIN

View file

@ -0,0 +1,21 @@
#include <stdio.h>
struct point
{
double x;
double y;
};
struct point point_array[100];
int main()
{
int my_point = 10;
point_array[my_point].x = 12.34;
point_array[my_point].y = 56.78;
printf("%f, %f\n", point_array[my_point].x, point_array[my_point].y);
return 0;
}

View file

@ -0,0 +1 @@
12.340000, 56.780000

View file

@ -43,7 +43,8 @@ TESTS= 00_assignment.test \
44_scoped_declarations.test \ 44_scoped_declarations.test \
45_empty_for.test \ 45_empty_for.test \
47_switch_return.test \ 47_switch_return.test \
48_nested_break.test 48_nested_break.test \
49_bracket_evaluation.test
%.test: %.expect %.c %.test: %.expect %.c
@echo Test: $*... @echo Test: $*...