public static StatementSequence TryParse(ref Source s) { StatementSequence res = new StatementSequence(); Spaces.Skip(ref s); bool flag = s.SkipIf("{"); while (true) { Statement st = Statement.TryParseAny(ref s); if (st != null) { res.AddStatement(st); } else { break; } } Spaces.Skip(ref s); if (flag) { if (!s.SkipIf("}")) { return(null); } } return(res); }
public static Return TryParse(ref Source s) { const string returnName = "return"; Return res = null; Spaces.Skip(ref s); if (!s.SkipIf(returnName)) { s.Rollback(); return(null); } Spaces.Skip(ref s); Expression expr = new Expression(ref s); if (expr.Correct()) { res = new Return(expr); } Spaces.Skip(ref s); if (!s.SkipIf(";")) { s.Rollback(); return(null); } return(res); }
public static bool TryParse(ref Source s, FuncValue fv) { Spaces.Skip(ref s); if (!s.SkipIf("(")) { return(false); } while (true) { string ident = Identifier.Parse(ref s); if (ident == "") { break; } fv.arguments.Add(ident); if (!s.SkipIf(",")) { break; } } Spaces.Skip(ref s); if (!s.SkipIf(")")) { return(false); } return(true); }
public ExprNode Parse(ref Source s, Operator parent) { Spaces.Skip(ref s); ParseBracketOpen(ref s); Spaces.Skip(ref s); Value left = Value.TryParse(ref s); Spaces.Skip(ref s); ParseBracketClose(ref s); if (left == null) { SyntaxErrorPos = s.currentPos; } Spaces.Skip(ref s); if (s.IsEnd() || SyntaxErrorPos >= 0) { return(left); } else { int opPos = s.currentPos; Operator op = Operator.TryParse(ref s); if (op != null) { //op.context = context; op.level = k; op.SetArg1(left); op.parent = parent; if (parent != null) { parent.SetArg2(op); } while (op.Balance()) { ; } //ParseBracketOpen(ref s); if (SyntaxErrorPos >= 0) { SyntaxErrorPos = s.currentPos; return(op); } ExprNode right = Parse(ref s, op); if (!op.HaveArg2()) { op.SetArg2(right); } } else { return(left); } return(op); } }
public static Null TryParse(ref Source s) { const string NullName = "null"; Spaces.Skip(ref s); s.Save(); if (!s.SkipIf(NullName)) { return(null); } return(new Null()); }
public static ArgumentsFact TryParse(ref Source s) { ArgumentsFact res = new ArgumentsFact(); Spaces.Skip(ref s); if (!s.SkipIf("(")) { return(null); } while (true) { Spaces.Skip(ref s); if (s.SkipIf(")")) { break; } Source tempSource = s.Clone(); Expression expr = new Expression(ref tempSource); if (!expr.Correct()) { throw new lolException(); } s.currentPos = tempSource.currentPos; s.Save(); res.AddArg(expr); Spaces.Skip(ref s); if (s.SkipIf(",")) { continue; } if (s.SkipIf(")")) { break; } } //s.Rollback(); return(res); }
public static ExprStatement TryParse(ref Source s) { ExprStatement res = null; Spaces.Skip(ref s); Expression expr = new Expression(ref s); if (expr.Correct()) { res = new ExprStatement(expr); } Spaces.Skip(ref s); if (!s.SkipIf(";")) { s.Rollback(); return(null); } return(res); }
public static Expression TryParse(ref Source s) { Spaces.Skip(ref s); if (!s.SkipIf("(")) { return(null); } Expression res = new Expression(ref s); if (!res.Correct()) { s.Rollback(); return(null); } Spaces.Skip(ref s); if (!s.SkipIf(")")) { s.Rollback(); return(null); } return(res); }
public static Statement TryParseAny(ref Source s) { Spaces.Skip(ref s); Statement res; s.Save(); res = If.TryParse(ref s); if (res == null) { s.Rollback(); res = While.TryParse(ref s); } if (res == null) { s.Rollback(); res = Return.TryParse(ref s); } if (res == null) { s.Rollback(); res = Assignment.TryParse(ref s); } if (res == null) { s.Rollback(); res = ExprStatement.TryParse(ref s); } if (res == null) { s.Rollback(); s.SkipIf(";"); } s.Check(res); return(res); }
public static string Parse(ref Source s) { string res = ""; Spaces.Skip(ref s); if (char.IsLetter(s.CurrSymbol) || s.CurrSymbol == '_') { res += s.CurrSymbol; s.Next(); } else { return(res); } while (char.IsLetterOrDigit(s.CurrSymbol) || s.CurrSymbol == '_')//!Spaces.IsSpace(s.CurrSymbol) && s.CurrSymbol != (char)0 && { res += s.CurrSymbol; s.Next(); } return(res); }
public static Assignment TryParse(ref Source s) { Assignment res = null; string ident = Identifier.Parse(ref s); if (ident == "") { s.Rollback(); return(null); } Spaces.Skip(ref s); if (!s.SkipIf("=")) { s.Rollback(); return(null); } Variable v = new Variable(ident); Spaces.Skip(ref s); Expression expr = new Expression(ref s); if (expr.Correct()) { res = new Assignment(v, expr); } Spaces.Skip(ref s); if (!s.SkipIf(";")) { s.Rollback(); return(null); } return(res); }