Pretty printing

This commit is contained in:
Clemens-Dautermann 2020-08-17 23:34:10 +02:00
parent 69782dd2fa
commit 9eb90686bb
2 changed files with 30 additions and 16 deletions

View file

@ -21,7 +21,7 @@
<component name="ChangeListManager">
<list default="true" id="a54bb6de-191c-4bd1-91ab-3953adfc5dfb" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.Compiler/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Compiler/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Lexer/TokenType.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Lexer/TokenType.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Compiler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Compiler.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -85,8 +85,8 @@
<option value="$PROJECT_DIR$/Parser/Exceptions/MissingTokenException.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/UnexpectedTokenException.cs" />
<option value="$PROJECT_DIR$/Parser/Parser.cs" />
<option value="$PROJECT_DIR$/Compiler.cs" />
<option value="$PROJECT_DIR$/Lexer/TokenType.cs" />
<option value="$PROJECT_DIR$/Compiler.cs" />
</list>
</option>
</component>
@ -147,7 +147,7 @@
<workItem from="1597604480117" duration="13146000" />
<workItem from="1597620399423" duration="389000" />
<workItem from="1597650936637" duration="537000" />
<workItem from="1597695400525" duration="4359000" />
<workItem from="1597695400525" duration="4637000" />
</task>
<servers />
</component>
@ -181,22 +181,22 @@
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2169" y="170" width="430" height="508" key="FileChooserDialogImpl/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597507670532" />
<state width="1868" height="289" key="GridCell.Tab.0.bottom" timestamp="1597699568550">
<state width="1868" height="289" key="GridCell.Tab.0.bottom" timestamp="1597700036417">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="289" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699568550" />
<state width="1868" height="289" key="GridCell.Tab.0.center" timestamp="1597699568550">
<state width="1868" height="289" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597700036417" />
<state width="1868" height="289" key="GridCell.Tab.0.center" timestamp="1597700036417">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="289" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699568550" />
<state width="1868" height="289" key="GridCell.Tab.0.left" timestamp="1597699568550">
<state width="1868" height="289" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597700036417" />
<state width="1868" height="289" key="GridCell.Tab.0.left" timestamp="1597700036417">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="289" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699568550" />
<state width="1868" height="289" key="GridCell.Tab.0.right" timestamp="1597699568550">
<state width="1868" height="289" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597700036417" />
<state width="1868" height="289" key="GridCell.Tab.0.right" timestamp="1597700036417">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="289" key="GridCell.Tab.0.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699568550" />
<state width="1868" height="289" key="GridCell.Tab.0.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597700036417" />
<state width="1868" height="383" key="GridCell.Tab.1.bottom" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>

View file

@ -18,17 +18,26 @@ namespace Compiler
foreach (string filepath in validFiles)
{
List<Token> tokens = TestLexer(filepath, 0);
TestParser(tokens, filepath);
TestParser(tokens, filepath, 1);
}
foreach (string filepath in invalidFiles)
{
List<Token> tokens = TestLexer(filepath, 0);
TestParser(tokens, filepath);
TestParser(tokens, filepath, 1);
}
}
static List<Token> TestLexer(string path, int debug)
static void PrettyPrint(Node root, string indent)
{
Console.WriteLine(indent + root.NodeType);
foreach (Node child in root.Children)
{
PrettyPrint(child, indent + " ");
}
}
static List<Token> TestLexer(string path, int debugLevel)
{
//List<List<Token>> tokenLists = new List<List<Token>>();
//string[] files = Directory.GetFiles(path);
@ -41,7 +50,7 @@ namespace Compiler
List<Token> tokens = lexer.Lex(contents);
Console.WriteLine("Lexed \"" + path.Split("/").Last() + "\"");
if (debug > 0)
if (debugLevel > 0)
{
Console.WriteLine("-----------" + path + "-----------");
foreach (Token token in tokens)
@ -56,13 +65,18 @@ namespace Compiler
return tokens;
}
static void TestParser(List<Token> tokenList, string path)
static void TestParser(List<Token> tokenList, string path, int debugLevel)
{
Parser.Parser p = new Parser.Parser(tokenList);
try
{
Node programNode = p.Parse(NodeType.ProgramNode);
if (debugLevel > 0)
{
PrettyPrint(programNode, "");
}
Console.WriteLine("Parsed \"" + path.Split("/").Last() + "\"");
}
catch (Exception e)