Beispiel #1
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);
        }
Beispiel #2
0
 public virtual void Visit(FuncBindAssignment assignment)
 {
     VisitSubNodes(assignment);
 }
Beispiel #3
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;
        }