Exemple #1
0
        public string VisitVarDecl(VarDecl basetype)
        {
            string contents = "";
            contents += basetype.varType.Accept(this);
            contents += " ";
            contents += basetype.varName.Accept(this);
            contents += ";";
            contents += "\n";

            return contents;
        }
        public object VisitVarDecl(VarDecl basetype)
        {
            string   variableName = (string)basetype.varName.value;
            Variable v            = new Variable(variableName, null);

            if (CurrentClass == null)
            {
                if (CurrentMethod == null)
                {
                    // Global scope
                    if (!Environment.Variables.Any(n => n.VariableName == v.VariableName))
                    {
                        new CompilerException("Variable: " + v.VariableName + " Could not be found");
                    }
                }
                else
                {
                    // Method in global scope
                    if (!CurrentMethod.Variables.Any(n => n.VariableName == v.VariableName))
                    {
                        new CompilerException("Variable: " + v.VariableName + " Could not be found");
                    }
                }
            }
            else
            {
                // In a class
                if (CurrentMethod == null)
                {
                    // In a method within a class
                    if (!CurrentClass.Variables.Any(n => n.VariableName == v.VariableName))
                    {
                        new CompilerException("Variable: " + v.VariableName + " Could not be found");
                    }
                }
                else
                {
                    // In a class and not in a method
                    if (!CurrentMethod.Variables.Any(n => n.VariableName == v.VariableName))
                    {
                        new CompilerException("Variable: " + v.VariableName + " Could not be found");
                    }
                }
            }

            return(v);
        }
Exemple #3
0
 public override void VisitVarDecl(VarDecl node)
 {
 }
 public abstract void VisitVarDecl(VarDecl node);
 public string VisitVarDecl(VarDecl basetype)
 {
     return(Parenthesize("VarDecl " + basetype.varName, basetype.varType));
 }