public Action Compile (Statement statement) { if (statement is ExpressionStatement) { var s = statement as ExpressionStatement; var result = Compile (s.Expression); return () => { if (s.Location != null && s.Location.Region != null) s.Location.Region.SetResult (result ().ToString ()); }; } if (statement is StatementBlock) { var block = statement as StatementBlock; var actions = block.Children.Select (s => Compile (s)).ToList (); return () => { foreach (var action in actions) { action (); } }; } if (statement is AssignmentVariable) { var s = statement as AssignmentVariable; var result = Compile (s.Expression); return () => { CurrentScope.SetVariable (s.Id, result ()); }; } if (statement is AssignmentFunction) { var s = statement as AssignmentFunction; var result = Compile (s.Body); return () => { var index = functions.FindIndex (f => f.Id == s.Id); var function = new FunctionSignature () {Id = s.Id, Parameters = s.Parameters, Body = result }; if (index != -1) functions [index] = function; else functions.Add (function); }; } return null; }
public void Add (Statement statement) { children.Add (statement); statement.Parent = this; }