Ejemplo n.º 1
0
        public void ParseFormalsTest()
        {
            FunctionParser     functionParser     = new FunctionParser(Init("(param1, param2)"));
            FunctionDefinition functionDefinition = new FunctionDefinition();

            functionParser.ParseFormals(functionDefinition);

            //Test formals
            Assert.AreEqual(2, functionDefinition.GetFormals().Count);
            Formal[] formalArray = (Formal[])functionDefinition.GetFormals().ToArray();

            Assert.AreEqual("param1", formalArray[0].ToString());
            Assert.AreEqual("param2", formalArray[1].ToString());
        }
Ejemplo n.º 2
0
        public void ParseEmptyFunctionDefinitionTest()
        {
            FunctionParser     functionParser           = new FunctionParser(Init("home(param1, param2) \n end"));
            FunctionDefinition parsedFunctionDefinition = functionParser.ParseFunctionDefinition();

            //Test FunctionDefinition
            Assert.AreEqual("home", parsedFunctionDefinition.GetIdentifier());
            Assert.AreEqual(2, parsedFunctionDefinition.GetFormals().Count);

            //Check formals
            Formal[] formalArray = (Formal[])parsedFunctionDefinition.GetFormals().ToArray();
            Assert.AreEqual("param1", formalArray[0].ToString());
            Assert.AreEqual("param2", formalArray[1].ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Visit FunctionDefinition to check declarations
        /// </summary>
        /// <param name="functionDefinition">FunctionDefinition to check</param>
        public override void Visit(FunctionDefinition functionDefinition)
        {
            CreateChildSymbolTable();

            //Check Formals
            foreach (Formal formal in functionDefinition.GetFormals())
            {
                //Add variable, but with nullvalue, because value is undefined in definition
                TextExpression textExpression = new TextExpression();
                SymbolTable.AddVariableDefinition(formal.GetIdentifier(), textExpression);
            }

            //Check Statements of function
            foreach (Statement statement in functionDefinition.GetStatements())
            {
                statement.AcceptVisitor(this);
            }

            MoveToParentSymbolTable();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Visit Markup
        /// </summary>
        /// <param name="markup">Markup to check</param>
        public override void Visit(Markup markup)
        {
            //Check identifier in designator, it should be an XHTML or an user defined function
            String identifier = markup.GetDesignator().GetIdentifier();

            if (SymbolTable.ContainsFunction(identifier))
            {
                //Check arguments
                FunctionDefinition referencedDefinition = SymbolTable.GetFunctionDefinition(identifier);

                if (referencedDefinition.GetFormals().Count != markup.GetArguments().Count)
                {   //Arity mismatch
                    ExceptionList.Add(new FunctionCallArityIncorrect(identifier));
                }
            }
            else
            {
                //Check if it is XHTML, if not its undefined
                if (!IdentifierIsXHTML(identifier) && markup.GetCallState())
                {
                    ExceptionList.Add(new UndefinedFunction(identifier));
                }
            }
        }