示例#1
0
        //declarestmt
        public override void OutADeclarestmt(ADeclarestmt node)
        {
            Definition typeDef, varDef;
            String     typeName = node.GetType().Text;
            String     varName  = node.GetVarname().Text;

            //    check type name is defined
            if (!(_currentSymbolTable.TryGetValue(typeName, out typeDef) || _globalSymbolTable.TryGetValue(typeName, out typeDef)))
            {
                Console.WriteLine("[" + node.GetType().Line + "] : " + typeName + " is not defined.");

                //    check if type name is defined as a type
            }
            else if (!(typeDef is TypeDefinition))
            {
                Console.WriteLine("[" + node.GetType().Line + "] : " + typeName + " is not a valid type.");

                //    check var name is not defined
            }
            else if (_currentSymbolTable.TryGetValue(varName, out varDef))
            {
                Console.WriteLine("[" + node.GetVarname().Line + "] : " + varName + " is already defined.");

                //    add to symbol table
            }
            else
            {
                VariableDefinition newDef = new VariableDefinition();
                newDef.name    = varName;
                newDef.vartype = (TypeDefinition)typeDef;
                _currentSymbolTable.Add(varName, newDef);
            }
        }
示例#2
0
 public override void CaseADeclarestmt(ADeclarestmt node)
 {
     InADeclarestmt(node);
     if (node.GetEol() != null)
     {
         node.GetEol().Apply(this);
     }
     if (node.GetVarname() != null)
     {
         node.GetVarname().Apply(this);
     }
     if (node.GetTypename() != null)
     {
         node.GetTypename().Apply(this);
     }
     OutADeclarestmt(node);
 }
示例#3
0
 public override void InADeclarestmt(ADeclarestmt node)
 {
     _output.Write("\t.locals init(");
     _output.WriteLine(node.GetTypename().Text + "32 " + node.GetVarname().Text + ")");
 }