Exemple #1
0
 public override void Visit(FuncDecl n)
 {
     n.declaring.accept(this);
     emit("(");
     if (n.declarings.Count > 0)
     {
         SymDeclaring first = n.declarings[0];
         foreach (SymDeclaring ast in n.declarings)
         {
             if (first != ast)
             {
                 emit(", ");
             }
             ast.accept(this);
         }
     }
     emit(") {\n");
     foreach (AST ast in n.statments)
     {
         ast.accept(this);
     }
     if (n.returnValue != null)
     {
         emit("return ");
         n.returnValue.accept(this); emit(";\n");
         emit("}\n");
     }
 }
Exemple #2
0
        public override void Visit(StructDef n)
        {
            n.type = AST.STRUCT;
            List <Tuple <string, int> > tuples = new List <Tuple <string, int> >();

            PlusScope();
            foreach (AST ast in n.declarings)
            {
                ast.accept(this);
                if (ast is SymDeclaring)
                {
                    SymDeclaring symDeclaring = ast as SymDeclaring;
                    tuples.Add(new Tuple <string, int>(symDeclaring.id, GetType(ast)));
                }
                else if (ast is FuncDecl)
                {
                    FuncDecl     funcDecl     = ast as FuncDecl;
                    SymDeclaring symDeclaring = funcDecl.declaring as SymDeclaring;
                    tuples.Add(new Tuple <string, int>(symDeclaring.id, GetType(funcDecl.declaring)));
                }
            }
            MinusScope();
            SymReferencing current = n.structType as SymReferencing;

            StructDic.Add(current.id, tuples);
        }
Exemple #3
0
        public override void Visit(StructDef n)
        {
            plusScope();
            foreach (AST ast in n.declarings)
            {
                if (ast is SymDeclaring)
                {
                    SymDeclaring sym = ast as SymDeclaring;
                    InitiationTable[GetKey(sym.id)] = 1;
                }
                else
                {
                    ast.accept(this);
                }
            }
            SymReferencing current = n.structType as SymReferencing;

            StructDic.Remove(current.id);
            minusScope();
        }
Exemple #4
0
 public override void Visit(SymDeclaring n)
 {
     //throw new NotImplementedException();
 }
Exemple #5
0
 private string ListType(SymDeclaring node)
 {
     return($"{GetType(node)}");
 }
Exemple #6
0
 public abstract void visit(SymDeclaring n);