public void Interpret(Cmd cmd) { try { if (!map.ContainsKey(cmd.Name.Lexeme)) { throw new InterpretationError($"Command '{cmd.Name.Lexeme}' does not exist"); } Execute(map[cmd.Name.Lexeme], cmd); } catch (InterpretationError e) { clti.WriteError(e.Message); } }
public Cmd?Parse(List <Token> ts) { tokens = ts; try { return(ParseCommand()); } catch (ParseError e) { clti.WriteError(e.Message); return(null); } }
// Lex: string -> List<Token> public List <Token> Lex(string s) { xs = s; try { Scan(); tokens.Print(); return(tokens); } catch (LexError e) { clti.WriteError(e.Message); return(new List <Token>()); } }