Ejemplo n.º 1
0
        public void Visit(AssignmentStatement assignStmt)
        {
            // Count right side of expression and place the result on the stack
            assignStmt.RightSideExpression.Accept(this);

            // Find item (variable) in the scope by name and try to assign it a value
            Item    item         = Environment.GetItem(assignStmt.Variable);
            dynamic varFromStack = Environment.PopFromTheStack();

            if (item is StrItem && varFromStack is string)
            {
                (item as StrItem).Value = varFromStack;
            }
            else if (item is NumItem && varFromStack is double)
            {
                (item as NumItem).Value = varFromStack;
            }
            else
            {
                throw new ExecutorException($"Cannot assign {varFromStack} to {item.Name}");
            }
        }
Ejemplo n.º 2
0
 public void Visit(AssignmentStatement assignStmt)
 {
     Console.Write($"{assignStmt.Variable}=");
     assignStmt.RightSideExpression.Accept(this);
 }