private static void Process(string line) { if (_replOptions.HasFlag(ReplOptions.PrintLexedTokens)) { var lexer = new Lexer(line); var tokens = lexer.Lex(); Console.WriteLine("=== Lexed Tokens ==="); foreach (var token in tokens) { Console.WriteLine(token.ToString()); } Console.WriteLine(); } var parser = new Parser(line); var syntaxTree = parser.Parse(); if (_replOptions.HasFlag(ReplOptions.PrintSyntaxTokens)) {
private static void Main(string[] args) { var text = new StringBuilder(); while (true) { if (text.Length == 0) { Console.Write("> "); } else { Console.Write("· "); } var line = Console.ReadLine(); if (string.IsNullOrEmpty(line)) { continue; } if (line.StartsWith('/')) { switch (line.ToUpperInvariant()) { case "/Q": case "/EXIT": return; case "/CLS": Console.Clear(); break; case "/L": case "/LEX": case "/SHOWLEX": _replOptions = SwitchFlag(ReplOptions.PrintLexedTokens); var printLexString = _replOptions.HasFlag(ReplOptions.PrintLexedTokens) ? $"#{ConsoleColor.Green}#enabled#RESET#" : $"#{ConsoleColor.Red}#disabled#RESET#"; ColoredConsole.WriteLine($"Printing lexed tokens {printLexString}."); break; case "/S": case "/SYNTAX": case "/SHOWSYNTAX": _replOptions = SwitchFlag(ReplOptions.PrintSyntaxTokens); var printSyntaxString = _replOptions.HasFlag(ReplOptions.PrintSyntaxTokens) ? $"#{ConsoleColor.Green}#enabled#RESET#" : $"#{ConsoleColor.Red}#disabled#RESET#"; ColoredConsole.WriteLine($"Printing syntax tree {printSyntaxString}."); break; case "/R": case "/RUN": Process(text.ToString()); break; case "/E": case "/EMIT": Emit(text.ToString()); break; case "/RS": case "/RESET": text.Clear(); break; default: Console.Error.WriteLine($"Unknown command: {line}."); break; } } else { text.AppendLine(line); } } }