public void Visit(IfStmt ifStmt, object[] args) { ifStmt.BlockList = new List <IfBlock>(); do { IfBlock block = new IfBlock(); block.Content = new List <Statement>(); block.Parent = ifStmt; block.Location = new Location(file, reader.LineNumber, reader.LinePosition); if (dic[reader.Name] == "else") { block.Condition = null; } else { reader.MoveToAttribute("cond"); string condExpr = reader.Value; Expr.Expression expr = exprParser.ParseExpr(condExpr, new Location(file, reader.LineNumber, reader.LinePosition).Offset(6)); //TODOļ¼Location block.Condition = expr; } visitMainContent(block, block.Content); ifStmt.BlockList.Add(block); } while (dic[reader.Name] == "elseif" || dic[reader.Name] == "else"); }
public void Visit(ReturnStmt returnStmt, object[] args) { string expr = reader.ReadString(); Expr.Expression result = exprParser.ParseExpr(expr, new Location(file, reader.LineNumber, reader.LinePosition).Offset(8)); returnStmt.Expression = result; }
public void Visit(ExpressionStmt expressionStmt, object[] args) { expressionStmt.ExpressionList = new List <Expr.Expression>(); string expr = reader.ReadString(); bool escape = false; bool inQuot = false; int firstPos = 0; string subExpr; for (int i = 0; i < expr.Length; i++) { if (expr[i] == '\\') { escape = !escape; } else if (expr[i] == '"') { if (!inQuot) { inQuot = true; } else if (escape) { escape = false; } else { inQuot = false; } } else if (expr[i] == ';') { subExpr = expr.Substring(firstPos, i - firstPos); if (subExpr.Trim().Length > 0) { Expr.Expression result = exprParser.ParseExpr(subExpr, new Location(file, reader.LineNumber, reader.LinePosition).Offset(6 + firstPos)); expressionStmt.ExpressionList.Add(result); } firstPos = i + 1; escape = false; } else { escape = false; } } if (firstPos < expr.Length) { subExpr = expr.Substring(firstPos, expr.Length - firstPos); if (subExpr.Trim().Length > 0) { Expr.Expression result = exprParser.ParseExpr(subExpr, new Location(file, reader.LineNumber, reader.LinePosition).Offset(6 + firstPos)); expressionStmt.ExpressionList.Add(result); } } }