diff --git a/ConsoleDemo/ConsoleDemo.csproj b/ConsoleDemo/ConsoleDemo.csproj index 1346ca7..a40909a 100644 --- a/ConsoleDemo/ConsoleDemo.csproj +++ b/ConsoleDemo/ConsoleDemo.csproj @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/ConsoleDemo/Program.cs b/ConsoleDemo/Program.cs index b46404d..8f74c47 100644 --- a/ConsoleDemo/Program.cs +++ b/ConsoleDemo/Program.cs @@ -1,52 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using Parser; +using Semantics; +using System; using System.IO; using System.Linq; -using Parser; -using ProjectConsole; -using Semantics; +using Repl; namespace ConsoleDemo { - internal class TreeRenderer - { - private static void RenderToken(SyntaxToken token, string indent, bool isLast) - { - Console.Write(indent + (isLast ? "└── " : "├── ")); - Console.Write($"<{token.Kind}>"); - Console.Write($" {token.Text}"); - Console.WriteLine(); - } - - private static void RenderNode(SyntaxNode node, string indent, bool isLast) - { - Console.Write(indent); - Console.Write(isLast ? "└── " : "├── "); - Console.Write($"<{node.Kind}>"); - Console.WriteLine(); - var children = node.GetChildNodesAndTokens(); - var last = children.Count - 1; - indent += isLast ? " " : "│ "; - for (var index = 0; index <= last; index++) - { - var child = children[index]; - if (child.IsNode) - { - RenderNode(child.AsNode(), indent, index == last); - } else if (child.IsToken) - { - RenderToken(child.AsToken(), indent, index == last); - } - } - } - - public static void RenderTree(SyntaxTree tree) - { - RenderNode(tree.Root, "", true); - } - } - class Program { private static readonly string BaseDirectory; @@ -156,9 +116,16 @@ namespace ConsoleDemo printer.Visit(tree.Root); } + public static void ReplDemo() + { + var repl = new MRepl(); + repl.Run(); + } + public static void Main(string[] args) { - ParserDemo(); + ReplDemo(); + //ParserDemo(); //SemanticsDemo(); //ContextDemo(); //DumbPrinterDemo(); diff --git a/Repl/MRepl.cs b/Repl/MRepl.cs new file mode 100644 index 0000000..36a6fe4 --- /dev/null +++ b/Repl/MRepl.cs @@ -0,0 +1,60 @@ +using System; +using Parser; + +namespace Repl +{ + public class MRepl + { + public void Run() + { + while (true) + { + Console.Write("> "); + var line = Console.ReadLine(); + var window = new TextWindowWithNull(line); + var parser = new MParser(window); + var tree = parser.Parse(); + TreeRenderer.RenderTree(tree); + } + } + } + + public class TreeRenderer + { + private static void RenderToken(SyntaxToken token, string indent, bool isLast) + { + Console.Write(indent + (isLast ? "└── " : "├── ")); + Console.Write($"<{token.Kind}>"); + Console.Write($" {token.Text}"); + Console.WriteLine(); + } + + private static void RenderNode(SyntaxNode node, string indent, bool isLast) + { + Console.Write(indent); + Console.Write(isLast ? "└── " : "├── "); + Console.Write($"<{node.Kind}>"); + Console.WriteLine(); + var children = node.GetChildNodesAndTokens(); + var last = children.Count - 1; + indent += isLast ? " " : "│ "; + for (var index = 0; index <= last; index++) + { + var child = children[index]; + if (child.IsNode) + { + RenderNode(child.AsNode(), indent, index == last); + } + else if (child.IsToken) + { + RenderToken(child.AsToken(), indent, index == last); + } + } + } + + public static void RenderTree(SyntaxTree tree) + { + RenderNode(tree.Root, "", true); + } + } +} diff --git a/Repl/Repl.csproj b/Repl/Repl.csproj new file mode 100644 index 0000000..b6b87fa --- /dev/null +++ b/Repl/Repl.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/Solution.sln b/Solution.sln index ff0098a..ed306a0 100644 --- a/Solution.sln +++ b/Solution.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2026 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28315.86 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleDemo", "ConsoleDemo\ConsoleDemo.csproj", "{5025FD8F-0F1A-43E5-A996-7753BC703D62}" EndProject @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution README.md = README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repl", "Repl\Repl.csproj", "{8FEDFE5D-3320-418F-88A6-09C1B51C4441}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -45,6 +47,10 @@ Global {4595633B-7F9A-4771-B348-F12BB9DD7ABC}.Debug|Any CPU.Build.0 = Debug|Any CPU {4595633B-7F9A-4771-B348-F12BB9DD7ABC}.Release|Any CPU.ActiveCfg = Release|Any CPU {4595633B-7F9A-4771-B348-F12BB9DD7ABC}.Release|Any CPU.Build.0 = Release|Any CPU + {8FEDFE5D-3320-418F-88A6-09C1B51C4441}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8FEDFE5D-3320-418F-88A6-09C1B51C4441}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8FEDFE5D-3320-418F-88A6-09C1B51C4441}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8FEDFE5D-3320-418F-88A6-09C1B51C4441}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE