public static void TraverseTree(Node root)
 {
     if (root.Name == "procdecl")
     {
         currentScope = root.children[0].children[1].Name;
         FuncTable.Add(currentScope, new funcVal());
         currentParam = new List <string>();
         ParamTraverse(root);
         FuncTable[currentScope].dts     = currentParam;
         FuncTable[currentScope].paramNo = currentParam.Count;
     }
     for (int i = 0; i < root.children.Count; i++)
     {
         TraverseTree(root.children[i]);
     }
     if (root.Name == "vardecl")
     {
         handleVarDecl(root);
     }
     if (root.Name == "Param decl")
     {
         if (SymbolTable.ContainsKey(root.children[1].Name))
         {
             MessageBox.Show("variable already declared");
         }
         else
         {
             SymbolVal sv = new SymbolVal();
             sv.DataType = root.children[0].children[0].Name;
             sv.Value    = 0;
             sv.Scope    = currentScope;
             SymbolTable.Add(root.children[1].Name, sv);
         }
     }
 }
Пример #2
0
 public static void TraverseTree(Node root)
 {
     if (root.Name == "Proc header")
     {
         currentScope = root.children[1].Name;
         if (FunctionTable.ContainsKey(currentScope))
         {
             MessageBox.Show("ERROR");
         }
         else
         {
             FunctionVal fv = new FunctionVal();
             FunctionTable.Add(currentScope, fv);
         }
     }
     if (root.Name == "paramdecls")
     {
         count = 0;
         dts   = new List <string>();
         handleParam(root);
         FunctionTable[currentScope].paramNumber   = count;
         FunctionTable[currentScope].paramDatatype = dts;
     }
     for (int i = 0; i < root.children.Count; i++)
     {
         TraverseTree(root.children[i]);
     }
     if (root.Name == "vardecl")
     {
         handleVarDecl(root);
     }
     if (root.Name == "Param decl")
     {
         if (SymbolTable.ContainsKey(root.children[1].Name))
         {
             MessageBox.Show("variable already declared");
         }
         else
         {
             SymbolVal sv = new SymbolVal();
             sv.datatype = root.children[0].children[0].Name;
             sv.val      = 0;
             sv.scope    = currentScope;
             SymbolTable.Add(root.children[1].Name, sv);
         }
     }
 }
 public static void handleIDlist(Node node)
 {
     node.children[0].datatype = node.datatype;
     if (SymbolTable.ContainsKey(node.children[0].Name))
     {
         MessageBox.Show("variable already declared");
     }
     else
     {
         SymbolVal sv = new SymbolVal();
         sv.DataType = node.children[0].datatype;
         sv.Value    = 0;
         sv.Scope    = "Global";
         SymbolTable.Add(node.children[0].Name, sv);
     }
     if (node.children.Count > 1)
     {
         node.children[2].datatype = node.datatype;
         handleIDlist(node.children[2]);
     }
 }