/// <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(); } }
/// <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(); } }
/// <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); }