Error Fixes

- Lexer discarding all newlines (now replaces it with spaces)
- Cleanup of Type check and remove function in parser
- Cleanup in Compiler.cs
This commit is contained in:
Clemens-Dautermann 2020-08-17 23:26:53 +02:00
parent 4e4b31be3f
commit d0c844972d
8 changed files with 198 additions and 146 deletions

View file

@ -2,7 +2,7 @@
<project version="4">
<component name="ContentModelStore">
<e p="$USER_HOME$/.cache/JetBrains/Rider2020.2/extResources" t="IncludeRecursive" />
<e p="$USER_HOME$/.cache/JetBrains/Rider2020.2/resharper-host/local/Transient/Rider/v202/SolutionCaches/_Compiler.1953847606.00" t="ExcludeRecursive" />
<e p="$USER_HOME$/.cache/JetBrains/Rider2020.2/resharper-host/local/Transient/Rider/v202/SolutionCaches/_Compiler.-1470031901.00" t="ExcludeRecursive" />
<e p="$PROJECT_DIR$" t="IncludeRecursive">
<e p="Compiler.cs" t="Include" />
<e p="Compiler.csproj" t="IncludeRecursive" />
@ -17,6 +17,7 @@
<e p="Exceptions" t="Include">
<e p="InvalidIdentifierException.cs" t="Include" />
<e p="MissingSemicolonException.cs" t="Include" />
<e p="MissingTokenException.cs" t="Include" />
<e p="UnexpectedTokenException.cs" t="Include" />
<e p="WrongTypeException.cs" t="Include" />
</e>

View file

@ -20,8 +20,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="a54bb6de-191c-4bd1-91ab-3953adfc5dfb" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/Parser/Exceptions/MissingTokenException.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.Compiler/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Compiler/.idea/contentModel.xml" afterDir="false" />
<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$/Compiler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Compiler.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Lexer/Lexer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Lexer/Lexer.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Lexer/TokenType.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Lexer/TokenType.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Parser/Exceptions/UnexpectedTokenException.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Exceptions/UnexpectedTokenException.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Parser/Parser.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Parser.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -33,24 +38,24 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/Compiler.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/714153FB-3DE5-4537-8A59-8AE8F7F7655E/44/126d3750/String.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/Lexer.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/Token.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EEDBFCB1-C56E-4F7A-8B60-B8DD27E0DC7D/86/71102cca/Enumerable.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/TokenType.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/Pattern.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Parser.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/ProgramNode.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/ConstantNode.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/NodeType.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/FunctionNode.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/Node.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/ReturnNode.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Exceptions/UnexpectedTokenException.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Exceptions/WrongTypeException.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Exceptions/InvalidIdentifierException.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Exceptions/MissingSemicolonException.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/714153FB-3DE5-4537-8A59-8AE8F7F7655E/44/126d3750/String.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/EEDBFCB1-C56E-4F7A-8B60-B8DD27E0DC7D/86/71102cca/Enumerable.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/Lexer.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/Token.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/TokenType.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Lexer/Pattern.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Parser.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Compiler.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/ProgramNode.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/ConstantNode.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/NodeType.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Parser/Nodes/FunctionNode.cs" root0="FORCE_HIGHLIGHTING" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
@ -75,17 +80,18 @@
<option value="$PROJECT_DIR$/Parser/Exceptions.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/FunctionNode.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/InvalidIdentifierException.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/UnexpectedTokenException.cs" />
<option value="$PROJECT_DIR$/Lexer/TokenType.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/MissingSemicolonException.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/ConstantNode.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/WronghTypeException.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/WrongTypeException.cs" />
<option value="$PROJECT_DIR$/Lexer/Token.cs" />
<option value="$PROJECT_DIR$/Compiler.cs" />
<option value="$PROJECT_DIR$/Lexer/Lexer.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/Node.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/ReturnNode.cs" />
<option value="$PROJECT_DIR$/Lexer/TokenType.cs" />
<option value="$PROJECT_DIR$/Compiler.cs" />
<option value="$PROJECT_DIR$/Lexer/Lexer.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/MissingTokenException.cs" />
<option value="$PROJECT_DIR$/Parser/Exceptions/UnexpectedTokenException.cs" />
<option value="$PROJECT_DIR$/Parser/Parser.cs" />
</list>
</option>
@ -101,8 +107,8 @@
<component name="PropertiesComponent">
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="DebuggerViewTab_PTCS_FirstProportionKey" value="0.350057" />
<property name="DebuggerViewTab_PTCS_LastProportionKey" value="0.299886" />
<property name="DebuggerViewTab_PTCS_FirstProportionKey" value="0.3500272" />
<property name="DebuggerViewTab_PTCS_LastProportionKey" value="0.29994556" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
@ -146,6 +152,8 @@
<workItem from="1597508003307" duration="9480000" />
<workItem from="1597604480117" duration="13146000" />
<workItem from="1597620399423" duration="389000" />
<workItem from="1597650936637" duration="537000" />
<workItem from="1597695400525" duration="4145000" />
</task>
<servers />
</component>
@ -179,94 +187,94 @@
<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="383" key="GridCell.Tab.0.bottom" timestamp="1597619266025">
<state width="1868" height="289" key="GridCell.Tab.0.bottom" timestamp="1597699363912">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.0.center" timestamp="1597619266025">
<state width="1868" height="289" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363912" />
<state width="1868" height="289" key="GridCell.Tab.0.center" timestamp="1597699363912">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.0.left" timestamp="1597619266025">
<state width="1868" height="289" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363912" />
<state width="1868" height="289" key="GridCell.Tab.0.left" timestamp="1597699363911">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.0.right" timestamp="1597619266025">
<state width="1868" height="289" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363911" />
<state width="1868" height="289" key="GridCell.Tab.0.right" timestamp="1597699363912">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.0.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.1.bottom" timestamp="1597619266025">
<state width="1868" height="289" key="GridCell.Tab.0.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363912" />
<state width="1868" height="383" key="GridCell.Tab.1.bottom" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.1.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.1.center" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.1.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.1.center" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.1.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.1.left" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.1.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.1.left" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.1.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.1.right" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.1.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.1.right" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.1.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.2.bottom" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.1.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.2.bottom" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.2.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.2.center" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.2.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.2.center" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.2.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.2.left" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.2.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.2.left" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.2.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.2.right" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.2.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.2.right" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.2.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.3.bottom" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.2.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.3.bottom" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.3.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.3.center" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.3.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.3.center" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.3.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.3.left" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.3.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.3.left" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.3.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.3.right" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.3.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.3.right" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.3.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.4.bottom" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.3.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.4.bottom" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.4.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.4.center" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.4.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.4.center" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.4.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.4.left" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.4.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.4.left" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.4.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.4.right" timestamp="1597619266025">
<state width="1868" height="383" key="GridCell.Tab.4.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state width="1868" height="383" key="GridCell.Tab.4.right" timestamp="1597698294797">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="1868" height="383" key="GridCell.Tab.4.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619266025" />
<state width="1868" height="383" key="GridCell.Tab.4.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698294797" />
<state x="1989" y="220" width="806" height="524" key="Rider.ProjectTemplateDialog.Size" timestamp="1597507532464">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="1989" y="220" width="806" height="524" key="Rider.ProjectTemplateDialog.Size/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597507532464" />
<state x="2345" y="104" width="709" height="485" key="RiderGenerateDialog" timestamp="1597619025064">
<state x="2342" y="83" width="709" height="485" key="RiderGenerateDialog" timestamp="1597696849168">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2345" y="104" width="709" height="485" key="RiderGenerateDialog/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597619025064" />
<state x="2342" y="83" width="709" height="485" key="RiderGenerateDialog/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597696849168" />
<state x="2233" y="185" width="1031" height="724" key="SettingsEditor" timestamp="1597620460972">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
@ -275,10 +283,10 @@
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2560" y="0" width="640" height="1080" key="VCS.FileHistoryDialog/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597605666894" />
<state width="480" height="540" key="XDebugger.FullValuePopup" timestamp="1597525606220">
<state width="480" height="540" key="XDebugger.FullValuePopup" timestamp="1597698247338">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state width="480" height="540" key="XDebugger.FullValuePopup/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597525606220" />
<state width="480" height="540" key="XDebugger.FullValuePopup/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698247338" />
<state x="2182" y="199" width="432" height="650" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser" timestamp="1597510086756">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
@ -291,5 +299,9 @@
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="1920" y="0" width="1920" height="1080" key="dock-window-2/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597620461385" />
<state x="2543" y="239" width="672" height="678" key="search.everywhere.popup" timestamp="1597698616567">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2543" y="239" width="672" height="678" key="search.everywhere.popup/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597698616567" />
</component>
</project>

View file

@ -1,37 +1,49 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Compiler.Lexer;
using Compiler.Parser;
using Compiler.Parser.Nodes;
namespace Compiler
{
public class Compiler
public static class Compiler
{
public static void Main()
{
List<List<Token>> tokensValid = TestLexer("../../../../tests/week_1/valid");
List<List<Token>> tokensInvalid = TestLexer("../../../../tests/week_1/invalid");
string[] validFiles = Directory.GetFiles("../../../../tests/week_1/valid");
string[] invalidFiles = Directory.GetFiles("../../../../tests/week_1/invalid");
TestParser(tokensValid[0]);
TestParser(tokensInvalid[0]);
foreach (string filepath in validFiles)
{
List<Token> tokens = TestLexer(filepath, 0);
TestParser(tokens, filepath);
}
foreach (string filepath in invalidFiles)
{
List<Token> tokens = TestLexer(filepath, 0);
TestParser(tokens, filepath);
}
}
static List<List<Token>> TestLexer(String path)
static List<Token> TestLexer(string path, int debug)
{
List<List<Token>> tokenLists = new List<List<Token>>();
String[] files = Directory.GetFiles(path);
//List<List<Token>> tokenLists = new List<List<Token>>();
//string[] files = Directory.GetFiles(path);
Lexer.Lexer lexer = new Lexer.Lexer();
foreach (String filename in files)
StreamReader file = new StreamReader(path);
string contents = file.ReadToEnd();
List<Token> tokens = lexer.Lex(contents);
Console.WriteLine("Lexed \"" + path.Split("/").Last() + "\"");
if (debug > 0)
{
StreamReader file = new StreamReader(filename);
String contents = file.ReadToEnd();
List<Token> tokens = lexer.Lex(contents);
tokenLists.Add(tokens);
Console.WriteLine("-----------" + filename + "-----------");
Console.WriteLine("-----------" + path + "-----------");
foreach (Token token in tokens)
{
Console.WriteLine(token.ToString());
@ -40,14 +52,24 @@ namespace Compiler
Console.WriteLine("--------------------------------------");
}
return tokenLists;
return tokens;
}
static void TestParser(List<Token> tokenList)
static void TestParser(List<Token> tokenList, string path)
{
Parser.Parser p = new Parser.Parser();
Parser.Parser p = new Parser.Parser(tokenList);
p.Parse(ref tokenList, NodeType.ProgramNode);
try
{
Node programNode = p.Parse(NodeType.ProgramNode);
Console.WriteLine("Parsed \"" + path.Split("/").Last() + "\"");
}
catch (Exception e)
{
Console.WriteLine("Error in file \"" + path.Split("/").Last() + "\"");
Console.WriteLine(e.Message);
}
}
}
}

View file

@ -10,8 +10,8 @@ namespace Compiler.Lexer
public List<Token> Lex(String inputString)
{
//strip newlines
inputString = inputString.Replace("\n", "");
inputString = inputString.Replace("\r", "");
inputString = inputString.Replace("\n", " ");
inputString = inputString.Replace("\r", " ");
//initialize Token List
List<Token> tokens = new List<Token>();

View file

@ -11,9 +11,11 @@ namespace Compiler.Lexer
SemicolonToken,
IdentifierToken,
IntegerLiteralToken,
//special Token to represent invalid matches
InvalidToken
InvalidToken,
//empty toke
NullToken
}
}

View file

@ -0,0 +1,15 @@
using System;
using Compiler.Lexer;
namespace Compiler.Parser.Exceptions
{
public class MissingTokenException : Exception
{
public override string Message { get; }
public MissingTokenException(TokenType expected)
{
this.Message = "Expected Token " + expected + " missing.";
}
}
}

View file

@ -5,16 +5,11 @@ namespace Compiler.Parser.Exceptions
{
public class UnexpectedTokenException : Exception
{
public TokenType expected { get; set; }
public TokenType got { get; set; }
public override string Message { get; }
public UnexpectedTokenException(TokenType expected, TokenType got)
{
this.expected = expected;
this.got = got;
this.Message = "Unexpected Token " + got + ". Expected: " + expected;
this.Message = "Unexpected Token " + got + ", expected: " + expected + ".";
}
}
}

View file

@ -9,11 +9,30 @@ namespace Compiler.Parser
{
public class Parser
{
public Node Parse(ref List<Token> tokenList, NodeType nodeType)
{
var t = tokenList.FirstOrDefault();
private readonly List<Token> _tokenList;
if (t == null) throw new Exception("Empty Token List.");
public Parser(List<Token> tokenList)
{
_tokenList = tokenList;
}
private void CheckFirstTokenAndRemove(TokenType expected)
{
if (_tokenList.Count == 0)
{
throw new MissingTokenException(expected);
}
if (_tokenList[0].TokenType != expected)
{
throw new UnexpectedTokenException(expected, _tokenList[0].TokenType);
}
_tokenList.RemoveAt(0);
}
public Node Parse(NodeType nodeType)
{
Node n;
switch (nodeType)
{
@ -21,32 +40,31 @@ namespace Compiler.Parser
n = new ProgramNode();
//if this node is a program node, the next one must be a function node
Node childNode = Parse(ref tokenList, NodeType.FunctionNode);
Node childNode = Parse(NodeType.FunctionNode);
n.Children.Add(childNode);
break;
case NodeType.FunctionNode:
n = new FunctionNode();
//retrieve signature and remove it
List<Token> signature = tokenList.GetRange(0, 5);
tokenList.RemoveRange(0, 5);
//check each element of the signature and raise corresponding errors
if (signature[0].TokenType != TokenType.IntToken)
CheckFirstTokenAndRemove(TokenType.IntToken);
if (_tokenList.Count == 0)
{
throw new UnexpectedTokenException(TokenType.IntToken, signature[1].TokenType);
throw new MissingTokenException(TokenType.IdentifierToken);
}
if (signature[1].Value != null)
if (_tokenList[0].Value != null)
{
if (signature[1].TokenType == TokenType.IdentifierToken)
if (_tokenList[0].TokenType == TokenType.IdentifierToken)
{
((FunctionNode) n).Name = signature[1].Value.ToString();
((FunctionNode) n).Name = _tokenList[0].Value.ToString();
}
else
{
throw new UnexpectedTokenException(TokenType.IdentifierToken, signature[1].TokenType);
throw new UnexpectedTokenException(TokenType.IdentifierToken, _tokenList[0].TokenType);
}
}
else
@ -54,64 +72,48 @@ namespace Compiler.Parser
throw new InvalidIdentifierException(null);
}
if (signature[2].TokenType != TokenType.OpenParenthesisToken)
{
throw new UnexpectedTokenException(TokenType.OpenParenthesisToken, signature[1].TokenType);
}
//remove <id>
_tokenList.RemoveAt(0);
if (signature[3].TokenType != TokenType.CloseParenthesisToken)
{
throw new UnexpectedTokenException(TokenType.CloseParenthesisToken, signature[1].TokenType);
}
if (signature[4].TokenType != TokenType.OpenBraceToken)
{
throw new UnexpectedTokenException(TokenType.OpenBraceToken, signature[1].TokenType);
}
CheckFirstTokenAndRemove(TokenType.OpenParenthesisToken);
CheckFirstTokenAndRemove(TokenType.CloseParenthesisToken);
CheckFirstTokenAndRemove(TokenType.OpenBraceToken);
//add returned child node to AST
n.Children.Add(Parse(ref tokenList, NodeType.StatementNode));
n.Children.Add(Parse(NodeType.StatementNode));
//remove trailing }
if (tokenList[0].TokenType != TokenType.CloseBraceToken)
{
throw new UnexpectedTokenException(TokenType.CloseBraceToken, tokenList[0].TokenType);
}
CheckFirstTokenAndRemove(TokenType.CloseBraceToken);
tokenList.RemoveAt(0);
break;
case NodeType.StatementNode:
//TODO: This Type of return/statement node will probably need fixing later
n = new ReturnNode();
//get return token and remove it
List<Token> returnStatement = tokenList.GetRange(0, 1);
tokenList.RemoveAt(0);
CheckFirstTokenAndRemove(TokenType.ReturnToken);
if (returnStatement[0].TokenType != TokenType.ReturnToken)
{
throw new UnexpectedTokenException(TokenType.ReturnToken, returnStatement[0].TokenType);
}
else
{
//add returned child node to AST
n.Children.Add(Parse(ref tokenList, NodeType.ExpressionNode));
//remove trailing ;
//add returned child node to AST
n.Children.Add(Parse(NodeType.ExpressionNode));
if (tokenList[0].TokenType != TokenType.SemicolonToken)
{
throw new UnexpectedTokenException(TokenType.SemicolonToken, tokenList[0].TokenType);
}
tokenList.RemoveAt(0);
}
//remove trailing ;
CheckFirstTokenAndRemove(TokenType.SemicolonToken);
break;
case NodeType.ExpressionNode:
Token constantToken = tokenList[0];
if (_tokenList.Count == 0)
{
throw new MissingTokenException(TokenType.IntegerLiteralToken);
}
Token constantToken = _tokenList[0];
//check if TokenType is right
if (constantToken.TokenType != TokenType.IntegerLiteralToken)
{
@ -119,6 +121,9 @@ namespace Compiler.Parser
}
else
{
//remove int literal token
_tokenList.RemoveAt(0);
//check if value Type is right
if (constantToken.Value.GetType() != typeof(int))
{