private static Classification <dynamic> Interpret(ref Environment <Classification <dynamic> > environment, string line) { var tokens = ProgramParsing.Separated(ProgramParsing.Token()).ParseCompletely(line.ToStream()); var command = ProgramParsing.CommandLine().ParseCompletely(tokens.ToStream()); foreach (var defun in command.Definition.Each()) { var term = defun; foreach (var type in command.Declaration.Each()) { term = new Term.Annotation(new Annotated(type, term)); } var typed = Execute(environment, term); if (command.Identifier != null) { if (environment.Maps(command.Identifier)) { Console.WriteLine("Shadowing is not allowed!"); } else { environment = environment.Push(command.Identifier, typed); } } return(typed); } throw new ArgumentException("Command line must include evaluable expression."); }
private static Token[] Tokenize(string program) { return(ProgramParsing.Separated(ProgramParsing.Token()).ParseCompletely(program.ToStream())); }
private static Term Parse(Token[] tokens) { return(ProgramParsing.CompilationUnit().ParseCompletely(tokens.ToStream())); }