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:
parent
4e4b31be3f
commit
d0c844972d
8 changed files with 198 additions and 146 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ContentModelStore">
|
<component name="ContentModelStore">
|
||||||
<e p="$USER_HOME$/.cache/JetBrains/Rider2020.2/extResources" t="IncludeRecursive" />
|
<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="$PROJECT_DIR$" t="IncludeRecursive">
|
||||||
<e p="Compiler.cs" t="Include" />
|
<e p="Compiler.cs" t="Include" />
|
||||||
<e p="Compiler.csproj" t="IncludeRecursive" />
|
<e p="Compiler.csproj" t="IncludeRecursive" />
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
<e p="Exceptions" t="Include">
|
<e p="Exceptions" t="Include">
|
||||||
<e p="InvalidIdentifierException.cs" t="Include" />
|
<e p="InvalidIdentifierException.cs" t="Include" />
|
||||||
<e p="MissingSemicolonException.cs" t="Include" />
|
<e p="MissingSemicolonException.cs" t="Include" />
|
||||||
|
<e p="MissingTokenException.cs" t="Include" />
|
||||||
<e p="UnexpectedTokenException.cs" t="Include" />
|
<e p="UnexpectedTokenException.cs" t="Include" />
|
||||||
<e p="WrongTypeException.cs" t="Include" />
|
<e p="WrongTypeException.cs" t="Include" />
|
||||||
</e>
|
</e>
|
||||||
|
|
|
||||||
136
Compiler/.idea/.idea.Compiler/.idea/workspace.xml
generated
136
Compiler/.idea/.idea.Compiler/.idea/workspace.xml
generated
|
|
@ -20,8 +20,13 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="a54bb6de-191c-4bd1-91ab-3953adfc5dfb" name="Default Changelist" comment="">
|
<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/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$/.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" />
|
<change beforePath="$PROJECT_DIR$/Parser/Parser.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Parser.cs" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
|
@ -33,24 +38,24 @@
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
|
||||||
</component>
|
</component>
|
||||||
<component name="HighlightingSettingsPerFile">
|
<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/Node.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/Parser/Nodes/ReturnNode.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/UnexpectedTokenException.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/Parser/Exceptions/WrongTypeException.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/InvalidIdentifierException.cs" root0="FORCE_HIGHLIGHTING" />
|
||||||
<setting file="file://$PROJECT_DIR$/Parser/Exceptions/MissingSemicolonException.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>
|
||||||
<component name="IdeDocumentHistory">
|
<component name="IdeDocumentHistory">
|
||||||
<option name="CHANGED_PATHS">
|
<option name="CHANGED_PATHS">
|
||||||
|
|
@ -75,17 +80,18 @@
|
||||||
<option value="$PROJECT_DIR$/Parser/Exceptions.cs" />
|
<option value="$PROJECT_DIR$/Parser/Exceptions.cs" />
|
||||||
<option value="$PROJECT_DIR$/Parser/Nodes/FunctionNode.cs" />
|
<option value="$PROJECT_DIR$/Parser/Nodes/FunctionNode.cs" />
|
||||||
<option value="$PROJECT_DIR$/Parser/Exceptions/InvalidIdentifierException.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/Exceptions/MissingSemicolonException.cs" />
|
||||||
<option value="$PROJECT_DIR$/Parser/Nodes/ConstantNode.cs" />
|
<option value="$PROJECT_DIR$/Parser/Nodes/ConstantNode.cs" />
|
||||||
<option value="$PROJECT_DIR$/Parser/Exceptions/WronghTypeException.cs" />
|
<option value="$PROJECT_DIR$/Parser/Exceptions/WronghTypeException.cs" />
|
||||||
<option value="$PROJECT_DIR$/Parser/Exceptions/WrongTypeException.cs" />
|
<option value="$PROJECT_DIR$/Parser/Exceptions/WrongTypeException.cs" />
|
||||||
<option value="$PROJECT_DIR$/Lexer/Token.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/Node.cs" />
|
||||||
<option value="$PROJECT_DIR$/Parser/Nodes/ReturnNode.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" />
|
<option value="$PROJECT_DIR$/Parser/Parser.cs" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
|
|
@ -101,8 +107,8 @@
|
||||||
<component name="PropertiesComponent">
|
<component name="PropertiesComponent">
|
||||||
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
|
<property name="ASKED_ADD_EXTERNAL_FILES" value="true" />
|
||||||
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
<property name="ASKED_SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||||
<property name="DebuggerViewTab_PTCS_FirstProportionKey" value="0.350057" />
|
<property name="DebuggerViewTab_PTCS_FirstProportionKey" value="0.3500272" />
|
||||||
<property name="DebuggerViewTab_PTCS_LastProportionKey" value="0.299886" />
|
<property name="DebuggerViewTab_PTCS_LastProportionKey" value="0.29994556" />
|
||||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
||||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
||||||
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||||
|
|
@ -146,6 +152,8 @@
|
||||||
<workItem from="1597508003307" duration="9480000" />
|
<workItem from="1597508003307" duration="9480000" />
|
||||||
<workItem from="1597604480117" duration="13146000" />
|
<workItem from="1597604480117" duration="13146000" />
|
||||||
<workItem from="1597620399423" duration="389000" />
|
<workItem from="1597620399423" duration="389000" />
|
||||||
|
<workItem from="1597650936637" duration="537000" />
|
||||||
|
<workItem from="1597695400525" duration="4145000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|
@ -179,94 +187,94 @@
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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 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" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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="289" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363912" />
|
||||||
<state width="1868" height="383" key="GridCell.Tab.0.center" timestamp="1597619266025">
|
<state width="1868" height="289" key="GridCell.Tab.0.center" timestamp="1597699363912">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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="289" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363912" />
|
||||||
<state width="1868" height="383" key="GridCell.Tab.0.left" timestamp="1597619266025">
|
<state width="1868" height="289" key="GridCell.Tab.0.left" timestamp="1597699363911">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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="289" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597699363911" />
|
||||||
<state width="1868" height="383" key="GridCell.Tab.0.right" timestamp="1597619266025">
|
<state width="1868" height="289" key="GridCell.Tab.0.right" timestamp="1597699363912">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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="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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.1.bottom" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.1.center" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.1.left" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.1.right" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.2.bottom" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.2.center" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.2.left" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.2.right" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.3.bottom" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.3.center" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.3.left" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.3.right" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.4.bottom" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.4.center" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.4.left" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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.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="1597619266025">
|
<state width="1868" height="383" key="GridCell.Tab.4.right" timestamp="1597698294797">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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">
|
<state x="1989" y="220" width="806" height="524" key="Rider.ProjectTemplateDialog.Size" timestamp="1597507532464">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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="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" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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">
|
<state x="2233" y="185" width="1031" height="724" key="SettingsEditor" timestamp="1597620460972">
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
|
|
@ -275,10 +283,10 @@
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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 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" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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">
|
<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" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</state>
|
||||||
|
|
@ -291,5 +299,9 @@
|
||||||
<screen x="1920" y="0" width="1920" height="1080" />
|
<screen x="1920" y="0" width="1920" height="1080" />
|
||||||
</state>
|
</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="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>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -1,37 +1,49 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using Compiler.Lexer;
|
using Compiler.Lexer;
|
||||||
using Compiler.Parser;
|
using Compiler.Parser;
|
||||||
|
using Compiler.Parser.Nodes;
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
{
|
{
|
||||||
public class Compiler
|
public static class Compiler
|
||||||
{
|
{
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
List<List<Token>> tokensValid = TestLexer("../../../../tests/week_1/valid");
|
string[] validFiles = Directory.GetFiles("../../../../tests/week_1/valid");
|
||||||
List<List<Token>> tokensInvalid = TestLexer("../../../../tests/week_1/invalid");
|
string[] invalidFiles = Directory.GetFiles("../../../../tests/week_1/invalid");
|
||||||
|
|
||||||
TestParser(tokensValid[0]);
|
foreach (string filepath in validFiles)
|
||||||
TestParser(tokensInvalid[0]);
|
{
|
||||||
|
List<Token> tokens = TestLexer(filepath, 0);
|
||||||
|
TestParser(tokens, filepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<List<Token>> TestLexer(String path)
|
foreach (string filepath in invalidFiles)
|
||||||
{
|
{
|
||||||
List<List<Token>> tokenLists = new List<List<Token>>();
|
List<Token> tokens = TestLexer(filepath, 0);
|
||||||
String[] files = Directory.GetFiles(path);
|
TestParser(tokens, filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Token> TestLexer(string path, int debug)
|
||||||
|
{
|
||||||
|
//List<List<Token>> tokenLists = new List<List<Token>>();
|
||||||
|
//string[] files = Directory.GetFiles(path);
|
||||||
Lexer.Lexer lexer = new Lexer.Lexer();
|
Lexer.Lexer lexer = new Lexer.Lexer();
|
||||||
|
|
||||||
foreach (String filename in files)
|
|
||||||
{
|
StreamReader file = new StreamReader(path);
|
||||||
StreamReader file = new StreamReader(filename);
|
string contents = file.ReadToEnd();
|
||||||
String contents = file.ReadToEnd();
|
|
||||||
|
|
||||||
List<Token> tokens = lexer.Lex(contents);
|
List<Token> tokens = lexer.Lex(contents);
|
||||||
tokenLists.Add(tokens);
|
Console.WriteLine("Lexed \"" + path.Split("/").Last() + "\"");
|
||||||
|
|
||||||
Console.WriteLine("-----------" + filename + "-----------");
|
if (debug > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("-----------" + path + "-----------");
|
||||||
foreach (Token token in tokens)
|
foreach (Token token in tokens)
|
||||||
{
|
{
|
||||||
Console.WriteLine(token.ToString());
|
Console.WriteLine(token.ToString());
|
||||||
|
|
@ -40,14 +52,24 @@ namespace Compiler
|
||||||
Console.WriteLine("--------------------------------------");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,8 +10,8 @@ namespace Compiler.Lexer
|
||||||
public List<Token> Lex(String inputString)
|
public List<Token> Lex(String inputString)
|
||||||
{
|
{
|
||||||
//strip newlines
|
//strip newlines
|
||||||
inputString = inputString.Replace("\n", "");
|
inputString = inputString.Replace("\n", " ");
|
||||||
inputString = inputString.Replace("\r", "");
|
inputString = inputString.Replace("\r", " ");
|
||||||
|
|
||||||
//initialize Token List
|
//initialize Token List
|
||||||
List<Token> tokens = new List<Token>();
|
List<Token> tokens = new List<Token>();
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ namespace Compiler.Lexer
|
||||||
IntegerLiteralToken,
|
IntegerLiteralToken,
|
||||||
|
|
||||||
//special Token to represent invalid matches
|
//special Token to represent invalid matches
|
||||||
InvalidToken
|
InvalidToken,
|
||||||
|
|
||||||
|
//empty toke
|
||||||
|
NullToken
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
15
Compiler/Parser/Exceptions/MissingTokenException.cs
Normal file
15
Compiler/Parser/Exceptions/MissingTokenException.cs
Normal 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.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,16 +5,11 @@ namespace Compiler.Parser.Exceptions
|
||||||
{
|
{
|
||||||
public class UnexpectedTokenException : Exception
|
public class UnexpectedTokenException : Exception
|
||||||
{
|
{
|
||||||
public TokenType expected { get; set; }
|
|
||||||
public TokenType got { get; set; }
|
|
||||||
|
|
||||||
public override string Message { get; }
|
public override string Message { get; }
|
||||||
|
|
||||||
public UnexpectedTokenException(TokenType expected, TokenType got)
|
public UnexpectedTokenException(TokenType expected, TokenType got)
|
||||||
{
|
{
|
||||||
this.expected = expected;
|
this.Message = "Unexpected Token " + got + ", expected: " + expected + ".";
|
||||||
this.got = got;
|
|
||||||
this.Message = "Unexpected Token " + got + ". Expected: " + expected;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9,11 +9,30 @@ namespace Compiler.Parser
|
||||||
{
|
{
|
||||||
public class Parser
|
public class Parser
|
||||||
{
|
{
|
||||||
public Node Parse(ref List<Token> tokenList, NodeType nodeType)
|
private readonly List<Token> _tokenList;
|
||||||
{
|
|
||||||
var t = tokenList.FirstOrDefault();
|
|
||||||
|
|
||||||
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;
|
Node n;
|
||||||
switch (nodeType)
|
switch (nodeType)
|
||||||
{
|
{
|
||||||
|
|
@ -21,32 +40,31 @@ namespace Compiler.Parser
|
||||||
n = new ProgramNode();
|
n = new ProgramNode();
|
||||||
|
|
||||||
//if this node is a program node, the next one must be a function node
|
//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);
|
n.Children.Add(childNode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NodeType.FunctionNode:
|
case NodeType.FunctionNode:
|
||||||
n = new 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
|
//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
|
else
|
||||||
{
|
{
|
||||||
throw new UnexpectedTokenException(TokenType.IdentifierToken, signature[1].TokenType);
|
throw new UnexpectedTokenException(TokenType.IdentifierToken, _tokenList[0].TokenType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -54,64 +72,48 @@ namespace Compiler.Parser
|
||||||
throw new InvalidIdentifierException(null);
|
throw new InvalidIdentifierException(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signature[2].TokenType != TokenType.OpenParenthesisToken)
|
//remove <id>
|
||||||
{
|
_tokenList.RemoveAt(0);
|
||||||
throw new UnexpectedTokenException(TokenType.OpenParenthesisToken, signature[1].TokenType);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signature[3].TokenType != TokenType.CloseParenthesisToken)
|
CheckFirstTokenAndRemove(TokenType.OpenParenthesisToken);
|
||||||
{
|
CheckFirstTokenAndRemove(TokenType.CloseParenthesisToken);
|
||||||
throw new UnexpectedTokenException(TokenType.CloseParenthesisToken, signature[1].TokenType);
|
CheckFirstTokenAndRemove(TokenType.OpenBraceToken);
|
||||||
}
|
|
||||||
|
|
||||||
if (signature[4].TokenType != TokenType.OpenBraceToken)
|
|
||||||
{
|
|
||||||
throw new UnexpectedTokenException(TokenType.OpenBraceToken, signature[1].TokenType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//add returned child node to AST
|
//add returned child node to AST
|
||||||
n.Children.Add(Parse(ref tokenList, NodeType.StatementNode));
|
n.Children.Add(Parse(NodeType.StatementNode));
|
||||||
|
|
||||||
//remove trailing }
|
//remove trailing }
|
||||||
if (tokenList[0].TokenType != TokenType.CloseBraceToken)
|
CheckFirstTokenAndRemove(TokenType.CloseBraceToken);
|
||||||
{
|
|
||||||
throw new UnexpectedTokenException(TokenType.CloseBraceToken, tokenList[0].TokenType);
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenList.RemoveAt(0);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NodeType.StatementNode:
|
case NodeType.StatementNode:
|
||||||
|
|
||||||
//TODO: This Type of return/statement node will probably need fixing later
|
//TODO: This Type of return/statement node will probably need fixing later
|
||||||
n = new ReturnNode();
|
n = new ReturnNode();
|
||||||
|
|
||||||
//get return token and remove it
|
//get return token and remove it
|
||||||
List<Token> returnStatement = tokenList.GetRange(0, 1);
|
CheckFirstTokenAndRemove(TokenType.ReturnToken);
|
||||||
tokenList.RemoveAt(0);
|
|
||||||
|
|
||||||
if (returnStatement[0].TokenType != TokenType.ReturnToken)
|
|
||||||
{
|
|
||||||
throw new UnexpectedTokenException(TokenType.ReturnToken, returnStatement[0].TokenType);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//add returned child node to AST
|
//add returned child node to AST
|
||||||
n.Children.Add(Parse(ref tokenList, NodeType.ExpressionNode));
|
n.Children.Add(Parse(NodeType.ExpressionNode));
|
||||||
|
|
||||||
|
|
||||||
//remove trailing ;
|
//remove trailing ;
|
||||||
|
CheckFirstTokenAndRemove(TokenType.SemicolonToken);
|
||||||
|
|
||||||
if (tokenList[0].TokenType != TokenType.SemicolonToken)
|
|
||||||
{
|
|
||||||
throw new UnexpectedTokenException(TokenType.SemicolonToken, tokenList[0].TokenType);
|
|
||||||
}
|
|
||||||
|
|
||||||
tokenList.RemoveAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NodeType.ExpressionNode:
|
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
|
//check if TokenType is right
|
||||||
if (constantToken.TokenType != TokenType.IntegerLiteralToken)
|
if (constantToken.TokenType != TokenType.IntegerLiteralToken)
|
||||||
{
|
{
|
||||||
|
|
@ -119,6 +121,9 @@ namespace Compiler.Parser
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//remove int literal token
|
||||||
|
_tokenList.RemoveAt(0);
|
||||||
|
|
||||||
//check if value Type is right
|
//check if value Type is right
|
||||||
if (constantToken.Value.GetType() != typeof(int))
|
if (constantToken.Value.GetType() != typeof(int))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue