Пример #1
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();
        }
Пример #2
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());
        }