Fixed problem with 'return' parsing which was causing the factorial example to fail
git-svn-id: http://picoc.googlecode.com/svn/trunk@185 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
bee7e23212
commit
9769bd432b
3
parse.c
3
parse.c
|
@ -269,6 +269,7 @@ int ParseStatement(struct ParseState *Parser)
|
||||||
|
|
||||||
case TokenLeftBrace:
|
case TokenLeftBrace:
|
||||||
ParseBlock(Parser, FALSE, TRUE);
|
ParseBlock(Parser, FALSE, TRUE);
|
||||||
|
CheckTrailingSemicolon = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TokenIf:
|
case TokenIf:
|
||||||
|
@ -451,6 +452,8 @@ int ParseStatement(struct ParseState *Parser)
|
||||||
memcpy(TopStackFrame->ReturnValue->Val, CValue->Val, TypeSizeValue(CValue));
|
memcpy(TopStackFrame->ReturnValue->Val, CValue->Val, TypeSizeValue(CValue));
|
||||||
Parser->Mode = RunModeReturn;
|
Parser->Mode = RunModeReturn;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
ExpressionParse(Parser, &CValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
int fact(int i) {
|
int factorial(int i)
|
||||||
if (i < 2) {
|
{
|
||||||
return i;
|
if (i < 2)
|
||||||
}
|
return i;
|
||||||
return (i * fact(i - 1));
|
else
|
||||||
|
return (i * factorial(i - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
fact(5)
|
int Count;
|
||||||
fact(6)
|
|
||||||
|
|
||||||
|
for (Count = 1; Count <= 10; Count++)
|
||||||
|
printf("%d\n", factorial(Count));
|
||||||
|
|
|
@ -1,2 +1,10 @@
|
||||||
|
1
|
||||||
|
2
|
||||||
|
6
|
||||||
|
24
|
||||||
120
|
120
|
||||||
720
|
720
|
||||||
|
5040
|
||||||
|
40320
|
||||||
|
362880
|
||||||
|
3628800
|
||||||
|
|
|
@ -12,6 +12,7 @@ TESTS= 00_assignment.test \
|
||||||
12_hashdefine.test \
|
12_hashdefine.test \
|
||||||
13_integer_literals.test \
|
13_integer_literals.test \
|
||||||
14_if.test \
|
14_if.test \
|
||||||
|
15_recursion.test \
|
||||||
16_nesting.test \
|
16_nesting.test \
|
||||||
17_enum.test \
|
17_enum.test \
|
||||||
18_include.test
|
18_include.test
|
||||||
|
|
Loading…
Reference in a new issue