Esempio n. 1
0
        /// <summary>
        /// Parser for Formals
        /// </summary>
        /// <param name="functionDefinition">functionDefinition to add formals to</param>
        /// <returns>Parsed Formals</returns>
        public void ParseFormals(FunctionDefinition functionDefinition)
        {
            if (TokenStream.Peek(1).GetValue().ToString() != "(")
            {
                return; //No formals, so return empty formals
            }

            //Skip ( token
            NextToken("(","(formal1, formal2)",'(');

            while (TokenStream.HasNext())
            {   //Parse formals
                if (TokenStream.Peek(1).GetValue().ToString() == ")")
                {
                    break; //End of formals
                }
                else if(TokenStream.Peek(1).GetValue().ToString() == ",")
                {
                    //Skip , token
                    NextToken(",", "(formal1, formal2)", ',');
                }
                functionDefinition.AddFormal(ParseFormal());
            }

            //Skip ) token
            NextToken(")", "(formal1, formal2)", ')');
        }
Esempio n. 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());
        }
Esempio n. 3
0
 /// <summary>
 /// Add an 
 /// </summary>
 /// <param name="functionDefinition"></param>
 public void AddFunctionDefinition(FunctionDefinition functionDefinition)
 {
     FunctionDefinitionList.Add(functionDefinition);
 }
Esempio n. 4
0
 public virtual void Visit(FunctionDefinition functionDefinition)
 {
     VisitSubNodes(functionDefinition);
 }
Esempio n. 5
0
        /// <summary>
        /// Parser for FunctionDefinition
        /// </summary>
        /// <returns>Parsed FunctionDefinition</returns>
        public FunctionDefinition ParseFunctionDefinition()
        {
            FunctionDefinition functionDefinition = new FunctionDefinition();

            //Parse FunctionId
            CurrentToken = TokenStream.NextToken();
            functionDefinition.SetIdentifier(CurrentToken.GetValue().ToString());

            //Parse Formals
            ParseFormals(functionDefinition);

            //Parse Statements
            while (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() != "end")
            {
                functionDefinition.AddStatement(statementParser.ParseStatement());
            }

            //Skip end token
            NextToken("end", "def function() statements end", "end");

            return functionDefinition;
        }
Esempio n. 6
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();
        }
Esempio n. 7
0
        /// <summary>
        /// Visit FuncBindAssignment
        /// </summary>
        /// <param name="assignment">FuncBindAssignment to check</param>
        public override void Visit(FuncBindAssignment assignment)
        {
            //FuncBind is a function, so let checking do by FunctionDefinition visitor
            FunctionDefinition function = new FunctionDefinition();
            function.SetIdentifier(assignment.GetIdentifier());

            foreach (String identifier in assignment.GetIdentifiers())
            {
                Formal formal = new Formal();
                formal.SetIdentifier(identifier);
                function.AddFormal(formal);
            }

            function.AddStatement(assignment.GetStatement());

            //Check this new function
            function.AcceptVisitor(this);
            //Add to SymbolTable
            SymbolTable.AddFunctionDefinition(function);
        }