Commit 2db135f4 by Andrew Dahl

Ref #12 Stage 9 should work in this one... got ahead of myself

parent c6e1681f
......@@ -26,10 +26,13 @@ class InstructionList {
int getStackAddress(Symbol* symbol);
void stackPush(Symbol* symbol);
void stackPush(enum Symbol::Type type);
Symbol* stackPop();
Symbol* stackPop(int num = 1);
void levelPush();
int levelPop();
int stackPushFunctionParam(Symbol* sym);
void moveStackPointer(int num);
string toString();
string FunctionToString(Instruction* inst, int varAddrSpace);
void Print();
private:
......
......@@ -19,7 +19,8 @@ class Symbol {
FLOAT,
INPUT,
VARIABLE,
FUNCTION
FUNCTION,
FUNC_ARG
};
union value_t {
......
......@@ -180,7 +180,7 @@ primary_exp: LPAREN additive_exp RPAREN {
yyerror(symbol_table, instructions, "Incorrect number of arguments given!");
} else {
instructions->addInstruction(new Instruction(Instruction::CALL, func));
instructions->addInstruction(new Instruction(Instruction::CALL, func, temp));
$$ = func;
}
}
......@@ -188,13 +188,15 @@ primary_exp: LPAREN additive_exp RPAREN {
func_call_args: { $$ = NULL; }
| additive_exp {
$1->setType(Symbol::VARIABLE);
$$ = $1;
Symbol* temp = new Symbol($1);
temp->setType(Symbol::VARIABLE);
$$ = temp;
}
| func_call_args COMMA additive_exp {
$3->setType(Symbol::VARIABLE);
$3->setValue($1);
$$ = $3;
Symbol* temp = new Symbol($3);
temp->setType(Symbol::VARIABLE);
temp->setValue($1);
$$ = temp;
}
;
%%
......
......@@ -12,3 +12,7 @@ var2=50
output var2
output var1
output var4
var5 = readInput
output var5
output readInput
var6 = var5
var1 = 1.0
var2=1.1
var4=2
function func(a,b,c)=a+b+c
function func(a,b,c)=a+b+func(1,2,3)
output var2 + func(1,2,3)
output 1 + 2 + var2 + readInput
output var2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment