Example #1
0
        /// <summary>
        /// Interpret LetStatement
        /// </summary>
        /// <param name="statement">LetStatement to interpret</param>
        public override void Visit(LetStatement statement)
        {
            //Create SymbolTable's for each assignment to let referencing work properly
            foreach (Assignment asgn in statement.GetAssignments())
            {
                SymbolTable = new SymbolTable(SymbolTable);
                asgn.AcceptVisitor(this);
            }

            //If no root element, create one
            if (statement.GetStatements().Count > 1 && Root == null)
            {
                XHTMLElement newRoot = new XHTMLElement("html", null, true);
                Root    = newRoot;
                Current = Root;
            }

            //Interpret statements
            int depth = this.Depth;

            foreach (Statement stmt in statement.GetStatements())
            {
                stmt.AcceptVisitor(this);
                BackToParentXHTMLElement(depth);
            }

            //Go back to scope outside let statement
            foreach (Assignment asgn in statement.GetAssignments())
            {
                SymbolTable = SymbolTable.GetParentSymbolTable();
            }
        }
Example #2
0
        /// <summary>
        /// Interpret EachStatement
        /// </summary>
        /// <param name="statement">EachStatement to interpret</param>
        public override void Visit(EachStatement statement)
        {
            //If no root element, create one
            if (Root == null)
            {
                XHTMLElement newRoot = new XHTMLElement("html", null, true);
                Root    = newRoot;
                Current = Root;
            }

            Expression expr = statement.GetExpression();

            //Different looping with different expression types
            if (expr is ListExpression)
            {   //Iterate through list
                ListExpression listExpression = (ListExpression)expr;

                //Iterate through list with expression
                XHTMLElement temp = Current;
                foreach (Expression currentExpr in listExpression.GetExpressions())
                {
                    Current = temp;

                    //New scope
                    SymbolTable = new SymbolTable(SymbolTable);

                    //Define variable and interpret statement with this scope
                    SymbolTable.AddVariableDefinition(statement.GetIdentifier(), currentExpr);
                    statement.GetStatement().AcceptVisitor(this);

                    //Return to parent scope
                    SymbolTable = SymbolTable.GetParentSymbolTable();
                }
            }
            else if (expr is FieldExpression)
            {   //Get expression in referenced record
                Expression expression = GetExpression((FieldExpression)expr);

                //Visit each for expression
                EachStatement eachStatement = new EachStatement();
                eachStatement.SetExpression(expression);
                eachStatement.SetStatement(statement.GetStatement());
                eachStatement.SetIdentifier(statement.GetIdentifier());
                Visit(eachStatement);
            }
            else if (expr is VarExpression)
            {   //Get expression of variable
                Expression expression = SymbolTable.GetVariableDefinition(((VarExpression)expr).GetVariableIdentifier());

                //Visit each for expression
                EachStatement eachStatement = new EachStatement();
                eachStatement.SetExpression(expression);
                eachStatement.SetStatement(statement.GetStatement());
                eachStatement.SetIdentifier(statement.GetIdentifier());
                Visit(eachStatement);
            }
        }
Example #3
0
        /// <summary>
        /// Interpret VarExpression
        /// </summary>
        /// <param name="expression">VarExpression to interpret</param>
        public override void Visit(VarExpression expression)
        {
            //Check if variable does exist
            String     varName = expression.GetVariableIdentifier();
            Expression check   = SymbolTable.GetVariableDefinition(varName);

            //If reference has been made to parent variable with same name, take parent reference
            if (check == expression && SymbolTable.GetParentSymbolTable() != null)
            {
                check = SymbolTable.GetParentSymbolTable().GetVariableDefinition(varName);
            }

            if (check != null)
            {   //Visit variable to retrieve current value
                check.AcceptVisitor(this);
            }
            else
            {
                TextValue = "undef";
            }
        }