Esempio n. 1
0
        /// <summary>
        /// Visit LetStatement
        /// </summary>
        /// <param name="statement">LetStatement to check</param>
        public override void Visit(LetStatement statement)
        {
            foreach (Assignment assignment in statement.GetAssignments())
            {
                //Go level deeper in SymbolTable, to check using variables in other assignments
                CreateChildSymbolTable();

                //Visit Assignment
                assignment.AcceptVisitor(this);
            }

            //Visit statements
            foreach(Statement stmt in statement.GetStatements())
            {
                stmt.AcceptVisitor(this);
            }

            //Go back to level of statement in SymbolTable
            foreach (Assignment assignment in statement.GetAssignments())
            {
                MoveToParentSymbolTable();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Parser for LetStatement
        /// </summary>
        /// <returns>Parsed LetStatement</returns>
        public LetStatement ParseLetStatement()
        {
            LetStatement letStatement = new LetStatement();

            //Skip let token
            NextToken("let", "let assignment+ in statement* end", "let");

            //Parse arguments
            while(TokenStream.HasNext())
            {
                if(TokenStream.Peek(1).GetValue().ToString() == "in")
                {
                    break; //no more assignments left
                }
                letStatement.AddAssignment(ParseAssignment());
            }
            if (letStatement.GetAssignments().Count == 0)
            {   //No assignments is not allowed
                throw new UnexpectedToken("LetStatement doesn't contain assignments.", "Expected at least one assignment ", CurrentToken.GetLine());
                //throw new UnexpectedToken();
            }

            //Skip in token
            NextToken("in", "let assignment+ in statement* end", "in");

            //Parse statements
            while (TokenStream.HasNext())
            {
                if (TokenStream.Peek(1).GetValue().ToString() == "end")
                {   //No more statements left
                    break;
                }
                letStatement.AddStatement(ParseStatement());
            }

            //Skip end token
            NextToken("end", "let assignment+ in statement* end", "end");

            return letStatement;
        }