コード例 #1
0
        public void ParseFuncBindAssingmentTest()
        {
            //Create parser
            StatementParser    statementParser      = new StatementParser(Init("home(test1, test2) = {}"));
            FuncBindAssignment parsedFuncAssignment = statementParser.ParseFuncBindAssignment();

            //Test FuncBindAssignment
            Assert.AreEqual("home", parsedFuncAssignment.GetIdentifier());
            Assert.AreEqual(2, parsedFuncAssignment.GetIdentifiers().Count);

            String[] identifierArray = parsedFuncAssignment.GetIdentifiers().ToArray();
            Assert.AreEqual("test1", identifierArray[0]);
            Assert.AreEqual("test2", identifierArray[1]);

            Assert.AreEqual(typeof(BlockStatement), parsedFuncAssignment.GetStatement().GetType());
            BlockStatement statement = (BlockStatement)parsedFuncAssignment.GetStatement();

            Assert.AreEqual(0, statement.GetStatements().Count);
        }
コード例 #2
0
ファイル: XHTMLVisitor.cs プロジェクト: tvdstorm/waebric
        /// <summary>
        /// Interpret FuncBindAssignment
        /// </summary>
        /// <param name="assignment">FuncBindAssignment to interpret</param>
        public override void Visit(FuncBindAssignment assignment)
        {   //Make a function of this binding and add it to SymbolTable
            FunctionDefinition functionDefinition = new FunctionDefinition();

            functionDefinition.SetIdentifier(assignment.GetIdentifier());
            functionDefinition.AddStatement(assignment.GetStatement());

            //Convert identifiers to formals
            foreach (String id in assignment.GetIdentifiers())
            {
                Formal frml = new Formal();
                frml.SetIdentifier(id);
                functionDefinition.AddFormal(frml);
            }

            //Create new SymbolTable for function
            FunctionSymbolTable.Add(functionDefinition, (SymbolTable)SymbolTable.Clone());

            //Add function to SymbolTable
            SymbolTable.AddFunctionDefinition(functionDefinition);
        }
コード例 #3
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);
        }
コード例 #4
0
        /// <summary>
        /// Parser for FuncBindAssignment
        /// </summary>
        /// <returns>Parsed FuncBindAssignment</returns>
        public FuncBindAssignment ParseFuncBindAssignment()
        {
            FuncBindAssignment funcBindAssignment = new FuncBindAssignment();

            //Parse identifier
            CurrentToken = TokenStream.NextToken();
            funcBindAssignment.SetIdentifier(CurrentToken.GetValue().ToString());

            //Skip ( token
            NextToken("(", "identifier(identifier1, identifier2) = statement;", '(');

            //Parse identifiers
            while (TokenStream.HasNext())
            {
                if (TokenStream.HasNext() && TokenStream.Peek(1).GetValue().ToString() == ")")
                {   //No more identifiers
                    break;
                }
                else if (TokenStream.Peek(1).GetValue().ToString() == ",")
                {
                    //Skip , token
                    NextToken(",", "(identifier1, identifier2)", ',');
                }
                CurrentToken = TokenStream.NextToken();
                funcBindAssignment.AddIdentifier(CurrentToken.GetValue().ToString());
            }

            //Skip ) token
            NextToken(")", "identifier(identifier1, identifier2) = statement;", ')');

            //Skip = token
            NextToken("=", "identifier(identifier1, identifier2) = statement;", '=');

            //Parse statement
            funcBindAssignment.SetStatement(ParseStatement());

            return(funcBindAssignment);
        }
コード例 #5
0
ファイル: SyntaxNodeVisitor.cs プロジェクト: tvdstorm/waebric
 public virtual void Visit(FuncBindAssignment assignment)
 {
     VisitSubNodes(assignment);
 }