/// <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); } }
/// <summary> /// Visit EachStatement /// </summary> /// <param name="statement">EachStatement to check</param> public override void Visit(EachStatement statement) { CreateChildSymbolTable(); //Store variable of Each = IdCon : Expression SymbolTable.AddVariableDefinition(statement.GetIdentifier(), statement.GetExpression()); //Visit statement statement.GetStatement().AcceptVisitor(this); MoveToParentSymbolTable(); }