public static FuncValue TryParse(ref Source s) { const string funcName = "function"; FuncValue res = null; if (!s.SkipIf(funcName)) { s.Rollback(); return(null); } res = new FuncValue(); if (!ArgumentsFormal.TryParse(ref s, res)) { s.Rollback(); return(null); } Source tempSource = s.Clone(); res.body = StatementSequence.TryParse(ref tempSource); s.currentPos = tempSource.currentPos; s.Save(); 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); }
private void InitPrint() { FuncValue print = new FuncValue(); print.body = new StatementSequence(); var temp = this; print.body.AddStatement(new PrintStatement(ref temp)); var printVar = context.FindFirstVar("print"); printVar.Value = print; }
public static Value TryParse(ref Source s) { Value res = null; Null tempNull = Null.TryParse(ref s); if (tempNull != null) { res = tempNull; } Number tempNum = Number.TryParse(ref s); if (tempNum != null) { res = tempNum; } Bool tempBool = Bool.TryParse(ref s); if (tempBool != null) { res = tempBool; } FuncValue tempFunc = FuncValue.TryParse(ref s); if (tempFunc != null) { res = tempFunc; } Variable tempVar = Variable.TryParse(ref s); if (tempVar != null) { res = tempVar; } if (res != null) { res.argsList = ArgumentsFact.TryParse(ref s); //if (res.args != null && res.nodeType != ExprNodeType.Function) // return null; } return(res); }