Exemple #1
0
        public void VisitNode(Number node)
        {
            Attributes            a   = new Attributes("Number");
            IntegerTypeDescriptor ITD = new IntegerTypeDescriptor();

            a.typeInfo   = ITD;
            node.attrRef = a;
        }
Exemple #2
0
        public void VisitNode(Expr node)
        {
            Utilities.TypeVisitAllChildren(node);

            Attributes exprAttr = new Attributes("Expr");

            node.attrRef = exprAttr;

            ErrorTypeDescriptor ETD = new ErrorTypeDescriptor();

            switch (node.Name)
            {
            case "-":
            case "+":
            case "/":
            case "*":
            case "%":
            case "|":
            case "&":
            case "^":
                IntegerTypeDescriptor ITD = new IntegerTypeDescriptor();
                if (allChildrenAreInts(node) == true)
                {
                    exprAttr.typeInfo = ITD;
                }
                else
                {
                    exprAttr.typeInfo = ETD;
                }
                break;

            case "<":
            case ">":
            case "<=":
            case ">=":
            case "||":
            case "&&":
            case "==":
            case "!=":
                BooleanTypeDescriptor BTD = new BooleanTypeDescriptor();
                if (allChildrenAreSame(node) == true)
                {
                    exprAttr.typeInfo = BTD;
                }
                else
                {
                    exprAttr.typeInfo = ETD;
                }
                break;

            case null:
                ContainerTypeDescriptor CTD = new ContainerTypeDescriptor();
                exprAttr.typeInfo = CTD;

                break;
            }
        }
        public SymbolTable()
        {
            symTableIdx = 0;
            symTables.Add(new SymTable_Type());

            // Add some basic things to the symbol table
            Attributes a;

            // Integer
            IntegerTypeDescriptor ITD = new IntegerTypeDescriptor();

            a          = new Attributes("Type");
            a.typeInfo = ITD;
            symTables[0].Add("int32", a);

            // Java types
            JaveTypeTypeDescriptor JTD = new JaveTypeTypeDescriptor();

            a          = new Attributes("Some Java Thing");
            a.typeInfo = JTD;
            symTables[0].Add("java.io.PrintStream", a);

            // Some methods

            string[] knownMethods = { "Write",
                                      "WriteLine",
                                      "ps.print", };
            foreach (string s in knownMethods)
            {
                a = new Attributes("MethodCall");
                MethodDclTypeDescp MTD = new MethodDclTypeDescp();
                a.typeInfo       = MTD;
                MTD.nameSpaceVar = "[mscorlib]System.Console";
                MTD.Name         = s;
                MTD.returnType   = "void";
                symTables[0].Add(s, a);
            }
        }