예제 #1
0
        public override void AfterBehaviour()
        {
            modifiers = FindChild<VisibilityModifierNode>();
            var symbol = new ST.Symbol(Name, "property");
            if (modifiers.IsPublic)
                symbol.SetPublic();
            symbol.Scope = AST.Table.CurrentClass.Name;

            var type = FindChild("qualified-type");
            symbol.Type = type.ToJs();
            if (string.IsNullOrEmpty(symbol.Type))
                symbol.Type = "void";

            AST.Table.Elements.Add(symbol);
        }
예제 #2
0
        public override void AfterBehaviour()
        {
            var symbol = new ST.Symbol(id.ToJs(), "method");
            if (modifiers.IsPublic)
                symbol.SetPublic();
            symbol.Scope = AST.Table.CurrentClass.Name;

            var type = FindChild("qualified-type");
            symbol.Type = type.ToJs();
            if (string.IsNullOrEmpty(symbol.Type))
                symbol.Type = "void";

            AST.Table.Elements.Add(symbol);

            // Controlla se nel corpo del metodo è presente il return statement 
            if (symbol.Type != "void")
            {
                var return_stmt = FindChild<ReturnStmtNode>();
                if (return_stmt == null)
                {
                    AST.Errors = "Cannot find return statement on " + ToPosition();
                    AST.Errors = "Semantic Error on Symbol: " + symbol.ToString();
                }
            }

            // Aggiungi tutti i parametri del metodo alla Symbol Table
            if (parameters != null)
            {
                foreach(JsNode parameter in parameters.Children)
                {
                    var qi = parameter.FindChild("qualified-type");
                    var _id = parameter.FindChild<IdentifierToken>(false);

                    var p = new ST.Symbol(_id.Value, "parameter");
                    p.Scope = id.Value;
                    p.Type = qi.ToJs();

                    AST.Table.Elements.Add(p);
                }
            }
        }
예제 #3
0
        public override void AfterBehaviour()
        {
            var symbol = new ST.Symbol(id.Value, "attribute");
            if (modifiers.IsPublic)
                symbol.SetPublic();
            if (AST.Table.CurrentClass != null)
                symbol.Scope = AST.Table.CurrentClass.Name;

            var type = FindChild("qualified-type");
            symbol.Type = type.ToJs();
            if (string.IsNullOrEmpty(symbol.Type))
                symbol.Type = "void";

            var p_expr = FindChild<PrimaryExpressionNode>(false);
            if(p_expr != null && symbol.Type != p_expr.Type && p_expr.Type != "null" && string.IsNullOrEmpty(p_expr.Type) == false)
            {
                AST.Errors = "Type Check Error";
                AST.Errors = "Semantic Error on " + ToPosition();
                AST.Errors = symbol.Name + " cannot be " + p_expr.Type;
            }

            AST.Table.Elements.Add(symbol);
        }