public void Assign(string variable, ProgNodeValue value, int index) { if (scope.TryGetValue(variable, out SymbolTableRec record)) { record.Assign(value, index); } }
public override ProgNodeValue Evaluate(ProgNodeContext context) { ProgNodeValue value = expression.Evaluate(context); context.SymTable.Assign(variable, value, 0); return(null); }
private void PushVarStack(Token token, Stack <ProgNode> varStack) { ProgNodeValue value = new ProgNodeValue(token); value.Arguments = GetArgList(); varStack.Push(value); }
public void Assign(string variable, ProgNodeValue value, int index) { SymbolTableRec record = GetSymbolTableRec(variable); if (record != null) { record.Assign(value, index); } }
/***************************/ /*** Protected Functions ***/ /***************************/ public override ProgNodeValue Evaluate(ProgNodeContext context) { ProgNodeValue left = leftExp.Evaluate(context); ProgNodeValue right = rightExp.Evaluate(context); int type = GetBoxType(left, right); return(ExecBoxing(left, right, type)); }
public ProgNodeValue GetInitialize(ProgNodeContext context) { ProgNodeValue value = null; if (Initialize != null) { value = Initialize.Evaluate(context); } return(value); }
/*******************/ /*** Constructor ***/ /*******************/ public SymbolTableRec(string name, SymbolTableRecType type, int size, ProgNodeValue initialize) { Name = name; Type = type; Designation = (size == 1) ? SymbolTableRecDesig.SCALAR : SymbolTableRecDesig.ARRAY; values = new ProgNodeValue[size]; for (int i = 0; i < size; i++) { values[i] = initialize; } }
/**************************/ /*** Override Functions ***/ /**************************/ public override ProgNodeValue Evaluate(ProgNodeContext context) { foreach (var variable in variables) { int size = variable.GetSize(context); ProgNodeValue initialize = variable.GetInitialize(context); context.SymTable.Declare(variable.Name, variable.Type, size, initialize); } return(null); }
public override ProgNodeValue ExecBoxing(ProgNodeValue left, ProgNodeValue right, int type) { ProgNodeValue result = null; switch (type) { case TYPE_FLOAT: float fvalue = (float)(Math.Pow(left.GetFloat(), right.GetFloat())); result = new ProgNodeValue(fvalue); break; } return(result); }
public override ProgNodeValue ExecBoxing(ProgNodeValue left, ProgNodeValue right, int type) { ProgNodeValue result = null; switch (type) { case TYPE_INTEGER: int ivalue = left.GetInteger() % right.GetInteger(); result = new ProgNodeValue(ivalue); break; } return(result); }
public void Assign(ProgNodeValue value, int index) { switch (Type) { case SymbolTableRecType.INTEGER: values[index] = new ProgNodeValue(value.GetInteger()); break; case SymbolTableRecType.FLOAT: values[index] = new ProgNodeValue(value.GetFloat()); break; case SymbolTableRecType.STRING: values[index] = new ProgNodeValue(value.GetString()); break; case SymbolTableRecType.BOOLEAN: values[index] = new ProgNodeValue(value.GetBoolean()); break; } }
/**************************/ /*** Override Functions ***/ /**************************/ public override ProgNodeValue ExecBoxing(ProgNodeValue left, ProgNodeValue right, int type) { ProgNodeValue result = null; switch (type) { case TYPE_FLOAT: float fvalue = left.GetFloat() + right.GetFloat(); result = new ProgNodeValue(fvalue); break; case TYPE_INTEGER: int ivalue = left.GetInteger() + right.GetInteger(); result = new ProgNodeValue(ivalue); break; case TYPE_STRING: string svalue = left.GetString() + right.GetString(); result = new ProgNodeValue(svalue); break; } return(result); }
/**************************/ /*** Override Functions ***/ /**************************/ public override ProgNodeValue ExecBoxing(ProgNodeValue left, ProgNodeValue right, int action) { bool value = false; switch (action) { case BOX_INTEGER: int iLeft = left.GetInteger(); int iRight = right.GetInteger(); switch (type) { case TokenType.LT: value = iLeft < iRight; break; case TokenType.LE: value = iLeft <= iRight; break; case TokenType.GT: value = iLeft > iRight; break; case TokenType.GE: value = iLeft >= iRight; break; case TokenType.NE: value = iLeft != iRight; break; } break; case BOX_FLOAT: float fLeft = left.GetFloat(); float fRight = right.GetFloat(); switch (type) { case TokenType.LT: value = fLeft < fRight; break; case TokenType.LE: value = fLeft <= fRight; break; case TokenType.GT: value = fLeft > fRight; break; case TokenType.GE: value = fLeft >= fRight; break; case TokenType.NE: value = fLeft != fRight; break; } break; } return(new ProgNodeValue(value)); }
protected int GetBoxType(ProgNodeValue left, ProgNodeValue right) { return(boxing[(int)left.Type, (int)right.Type]); }
public abstract ProgNodeValue ExecBoxing(ProgNodeValue left, ProgNodeValue right, int type);
public void Declare(string variable, SymbolTableRecType type, int size, ProgNodeValue initialize) { SymTable[activeScope].Declare(variable, type, size, initialize); }
public override ProgNodeValue Evaluate(ProgNodeContext context) { ProgNodeValue value = null; return(value); }
/************************/ /*** Public Functions ***/ /************************/ public void Declare(string name, SymbolTableRecType type, int size, ProgNodeValue initialize) { scope.Add(name, new SymbolTableRec(name, type, size, initialize)); }