コード例 #1
0
        public AstExpression VisitVariable(Scope context, AstExpression.Var var)
        {
            var.Variable = context.FindVariable(var.TokenName.Value);
            if (var.Variable == null)
            {
                throw new CompilerException(var.TokenName, $"variable {var.TokenName.Value} is not defined.");
            }

            return(var);
        }
コード例 #2
0
        public List <Instruction> VisitVariable(Scope context, AstExpression.Var var)
        {
            if (var.Type == DataTypes.Int)
            {
                var heapLayout = context.GetHeapLayoutUntil(var.Variable);
                return(new List <Instruction>()
                {
                    new Instruction(ReadLocal, heapLayout),
                    new Instruction(DupInt),
                    new Instruction(WriteLocal, heapLayout),
                });
            }

            throw new NotImplementedException();
        }
コード例 #3
0
 public Tree VisitVariable(object c, AstExpression.Var var)
 => new Tree("v:" + var.TokenName.Value);