corrected implementation of unary operators

This commit is contained in:
Clemens-Dautermann 2020-08-20 22:37:30 +02:00
parent 202c1d2ca2
commit 07079366b8
6 changed files with 156 additions and 117 deletions

View file

@ -20,27 +20,12 @@
</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/Nodes/OperatorType.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Parser/Nodes/UnaryOperatorNode.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/invalid/missing_const.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/invalid/missing_semicolon.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/invalid/nested_missing_const.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/invalid/wrong_order.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/bitwise.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/bitwise_zero.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/neg.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/nested_ops.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/nested_ops_2.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/not_five.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/../stage_2/valid/not_zero.c" 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$/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$/Parser/Nodes/ConstantNode.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Nodes/ConstantNode.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/Nodes/NodeType.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Nodes/NodeType.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Parser/Nodes/NodeType.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Nodes/NodeType.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Parser/Nodes/UnaryOperatorNode.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Parser/Nodes/UnaryOperatorNode.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" />
<change beforePath="$PROJECT_DIR$/../grammar" beforeDir="false" afterPath="$PROJECT_DIR$/../grammar" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -72,6 +57,7 @@
<setting file="file://$PROJECT_DIR$/Parser/Nodes/FunctionNode.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://$APPLICATION_CONFIG_DIR$/resharper-host/DecompilerCache/decompiler/714153FB-3DE5-4537-8A59-8AE8F7F7655E/74/559b3670/String.cs" root0="SKIP_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" />
@ -101,7 +87,6 @@
<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/MissingSemicolonException.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/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" />
@ -114,10 +99,11 @@
<option value="$PROJECT_DIR$/Lexer/TokenType.cs" /> <option value="$PROJECT_DIR$/Lexer/TokenType.cs" />
<option value="$PROJECT_DIR$/Lexer/Lexer.cs" /> <option value="$PROJECT_DIR$/Lexer/Lexer.cs" />
<option value="$PROJECT_DIR$/../grammar" /> <option value="$PROJECT_DIR$/../grammar" />
<option value="$PROJECT_DIR$/Parser/Nodes/NodeType.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/OperatorTypes.cs" /> <option value="$PROJECT_DIR$/Parser/Nodes/OperatorTypes.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/OperatorType.cs" /> <option value="$PROJECT_DIR$/Parser/Nodes/OperatorType.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/NodeType.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/UnaryOperatorNode.cs" /> <option value="$PROJECT_DIR$/Parser/Nodes/UnaryOperatorNode.cs" />
<option value="$PROJECT_DIR$/Parser/Nodes/ConstantNode.cs" />
<option value="$PROJECT_DIR$/Parser/Parser.cs" /> <option value="$PROJECT_DIR$/Parser/Parser.cs" />
<option value="$PROJECT_DIR$/Compiler.cs" /> <option value="$PROJECT_DIR$/Compiler.cs" />
</list> </list>
@ -134,13 +120,13 @@
<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.3500272" /> <property name="DebuggerViewTab_PTCS_FirstProportionKey" value="0.56953055" />
<property name="DebuggerViewTab_PTCS_LastProportionKey" value="0.29994556" /> <property name="DebuggerViewTab_PTCS_LastProportionKey" value="0.4880425" />
<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" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="XThreadsFramesViewSplitterKey" value="0.49837133" /> <property name="XThreadsFramesViewSplitterKey" value="0.2616179" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/.." /> <property name="last_opened_file_path" value="$PROJECT_DIR$/.." />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" /> <property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component> </component>
@ -182,7 +168,8 @@
<workItem from="1597650936637" duration="537000" /> <workItem from="1597650936637" duration="537000" />
<workItem from="1597695400525" duration="4873000" /> <workItem from="1597695400525" duration="4873000" />
<workItem from="1597863017034" duration="9651000" /> <workItem from="1597863017034" duration="9651000" />
<workItem from="1597932102881" duration="4147000" /> <workItem from="1597932102881" duration="4296000" />
<workItem from="1597952695048" duration="3054000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -224,86 +211,102 @@
<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="583" key="GridCell.Tab.0.bottom" timestamp="1597935868003"> <state width="1868" height="383" key="GridCell.Tab.-1.bottom" timestamp="1597955238557">
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="1920" y="0" width="1920" height="1080" />
</state> </state>
<state width="1868" height="583" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597935868003" /> <state width="1868" height="383" key="GridCell.Tab.-1.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955238557" />
<state width="1868" height="583" key="GridCell.Tab.0.center" timestamp="1597935868002"> <state width="1868" height="383" key="GridCell.Tab.-1.center" timestamp="1597955238557">
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="1920" y="0" width="1920" height="1080" />
</state> </state>
<state width="1868" height="583" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597935868002" /> <state width="1868" height="383" key="GridCell.Tab.-1.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955238557" />
<state width="1868" height="583" key="GridCell.Tab.0.left" timestamp="1597935868002"> <state width="1868" height="383" key="GridCell.Tab.-1.left" timestamp="1597955238557">
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="1920" y="0" width="1920" height="1080" />
</state> </state>
<state width="1868" height="583" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597935868002" /> <state width="1868" height="383" key="GridCell.Tab.-1.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955238557" />
<state width="1868" height="583" key="GridCell.Tab.0.right" timestamp="1597935868002"> <state width="1868" height="383" key="GridCell.Tab.-1.right" timestamp="1597955238557">
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="1920" y="0" width="1920" height="1080" />
</state> </state>
<state width="1868" height="583" key="GridCell.Tab.0.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597935868002" /> <state width="1868" height="383" key="GridCell.Tab.-1.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955238557" />
<state width="1868" height="383" key="GridCell.Tab.1.bottom" timestamp="1597872670367"> <state width="1868" height="512" key="GridCell.Tab.0.bottom" timestamp="1597955691042">
<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="1597872670367" /> <state width="1868" height="512" key="GridCell.Tab.0.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955691042" />
<state width="1868" height="383" key="GridCell.Tab.1.center" timestamp="1597872670367"> <state width="1868" height="512" key="GridCell.Tab.0.center" timestamp="1597955691042">
<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="1597872670367" /> <state width="1868" height="512" key="GridCell.Tab.0.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955691042" />
<state width="1868" height="383" key="GridCell.Tab.1.left" timestamp="1597872670367"> <state width="1868" height="512" key="GridCell.Tab.0.left" timestamp="1597955691042">
<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="1597872670367" /> <state width="1868" height="512" key="GridCell.Tab.0.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955691042" />
<state width="1868" height="383" key="GridCell.Tab.1.right" timestamp="1597872670367"> <state width="1868" height="512" key="GridCell.Tab.0.right" timestamp="1597955691042">
<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="1597872670367" /> <state width="1868" height="512" key="GridCell.Tab.0.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955691042" />
<state width="1868" height="383" key="GridCell.Tab.2.bottom" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.1.bottom" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.1.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.2.center" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.1.center" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.1.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.2.left" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.1.left" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.1.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.2.right" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.1.right" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.1.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.3.bottom" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.2.bottom" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.2.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.3.center" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.2.center" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.2.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.3.left" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.2.left" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.2.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.3.right" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.2.right" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.2.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.4.bottom" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.3.bottom" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.3.bottom/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.4.center" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.3.center" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.3.center/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.4.left" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.3.left" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.3.left/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.4.right" timestamp="1597872670367"> <state width="1868" height="383" key="GridCell.Tab.3.right" timestamp="1597955439042">
<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="1597872670367" /> <state width="1868" height="383" key="GridCell.Tab.3.right/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597955439042" />
<state width="1868" height="383" key="GridCell.Tab.4.bottom" timestamp="1597955234640">
<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="1597955234640" />
<state width="1868" height="383" key="GridCell.Tab.4.center" timestamp="1597955234640">
<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="1597955234640" />
<state width="1868" height="383" key="GridCell.Tab.4.left" timestamp="1597955234640">
<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="1597955234640" />
<state width="1868" height="383" key="GridCell.Tab.4.right" timestamp="1597955234640">
<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="1597955234640" />
<state x="631" y="291" width="806" height="524" key="Rider.ProjectTemplateDialog.Size" timestamp="1597872082099"> <state x="631" y="291" width="806" height="524" key="Rider.ProjectTemplateDialog.Size" timestamp="1597872082099">
<screen x="0" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
@ -328,10 +331,10 @@
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="1920" y="0" width="1920" height="1080" />
</state> </state>
<state x="2182" y="199" width="432" height="650" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597510086756" /> <state x="2182" y="199" width="432" height="650" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597510086756" />
<state x="2880" y="0" width="960" height="1080" key="dock-window-1" timestamp="1597934748776"> <state x="0" y="557" width="960" height="523" key="dock-window-1" timestamp="1597952828875">
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="0" y="0" width="1920" height="1080" />
</state> </state>
<state x="2880" y="0" width="960" height="1080" key="dock-window-1/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597934748776" /> <state x="0" y="557" width="960" height="523" key="dock-window-1/1920.0.1920.1080/0.0.1920.1080@1920.0.1920.1080" timestamp="1597952828875" />
<state x="2880" y="0" width="960" height="1080" key="dock-window-2" timestamp="1597934748776"> <state x="2880" y="0" width="960" height="1080" key="dock-window-2" timestamp="1597934748776">
<screen x="1920" y="0" width="1920" height="1080" /> <screen x="1920" y="0" width="1920" height="1080" />
</state> </state>
@ -345,4 +348,23 @@
</state> </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" /> <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>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DotNet Breakpoints">
<url>file://$PROJECT_DIR$/Compiler.cs</url>
<line>138</line>
<properties documentPath="$PROJECT_DIR$/Compiler.cs" initialLine="138">
<startOffsets>
<option value="4241" />
</startOffsets>
<endOffsets>
<option value="4242" />
</endOffsets>
</properties>
<option name="timeStamp" value="3" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project> </project>

View file

@ -139,22 +139,18 @@ namespace Compiler
{ {
switch (root.NodeType) switch (root.NodeType)
{ {
case NodeType.ExpressionNode:
if (root is UnaryOperatorNode)
{
Console.WriteLine(indent + root.NodeType + ":" + ((UnaryOperatorNode) root).OperatorType);
}
if (root is ConstantNode)
{
Console.WriteLine(indent + root.NodeType + ":" + ((ConstantNode) root).value);
}
break;
case NodeType.FunctionNode: case NodeType.FunctionNode:
Console.WriteLine(indent + root.NodeType + ":" + ((FunctionNode) root).Name); Console.WriteLine(indent + root.NodeType + ":" + ((FunctionNode) root).Name);
break; break;
case NodeType.ProgramNode: case NodeType.ConstantNode:
case NodeType.ReturnStatementNode: Console.WriteLine(indent + root.NodeType + ":" + ((ConstantNode) root).value);
break;
case NodeType.UnaryOperatorNode:
Console.WriteLine(indent + root.NodeType + ":" + ((UnaryOperatorNode) root).OperatorType);
break;
default:
Console.WriteLine(indent + root.NodeType);
break; break;
} }

View file

@ -7,7 +7,7 @@ namespace Compiler.Parser.Nodes
public ConstantNode(int value) public ConstantNode(int value)
{ {
this.NodeType = NodeType.ExpressionNode; this.NodeType = NodeType.ConstantNode;
this.value = value; this.value = value;
} }
} }

View file

@ -6,6 +6,8 @@ namespace Compiler.Parser.Nodes
FunctionNode, FunctionNode,
ReturnStatementNode, ReturnStatementNode,
ExpressionNode, ExpressionNode,
ConstantNode,
UnaryOperatorNode
} }
} }

View file

@ -8,7 +8,7 @@ namespace Compiler.Parser.Nodes
public UnaryOperatorNode(OperatorType operatorType) public UnaryOperatorNode(OperatorType operatorType)
{ {
OperatorType = operatorType; OperatorType = operatorType;
NodeType = NodeType.ExpressionNode; NodeType = NodeType.UnaryOperatorNode;
} }
} }
} }

View file

@ -102,7 +102,6 @@ namespace Compiler.Parser
//remove trailing ; //remove trailing ;
CheckFirstTokenAndRemove(TokenType.SemicolonToken); CheckFirstTokenAndRemove(TokenType.SemicolonToken);
break; break;
case NodeType.ExpressionNode: case NodeType.ExpressionNode:
@ -114,53 +113,73 @@ namespace Compiler.Parser
Token expressionToken = _tokenList[0]; Token expressionToken = _tokenList[0];
//the next token might be a constant or any operator
switch (expressionToken.TokenType) switch (expressionToken.TokenType)
{ {
case TokenType.IntegerLiteralToken: case TokenType.IntegerLiteralToken:
//remove int literal token n = Parse(NodeType.ConstantNode);
_tokenList.RemoveAt(0);
//check if value Type is right
if (expressionToken.Value.GetType() != typeof(int))
{
throw new WrongTypeException(typeof(int), expressionToken.Value.GetType());
}
//return final constant node to end recursion
n = new ConstantNode((int) expressionToken.Value);
break;
case TokenType.NegationToken:
_tokenList.RemoveAt(0);
n = new UnaryOperatorNode(OperatorType.Negation);
n.Children.Add(Parse(NodeType.ExpressionNode));
break; break;
case TokenType.BitwiseComplementToken: case TokenType.BitwiseComplementToken:
_tokenList.RemoveAt(0); case TokenType.NegationToken:
n = new UnaryOperatorNode(OperatorType.BitwiseComplement);
n.Children.Add(Parse(NodeType.ExpressionNode));
break;
case TokenType.LogicalNegationToken: case TokenType.LogicalNegationToken:
_tokenList.RemoveAt(0); n = Parse(NodeType.UnaryOperatorNode);
n = new UnaryOperatorNode(OperatorType.LogicalNegation);
n.Children.Add(Parse(NodeType.ExpressionNode));
break; break;
case TokenType.IntToken:
case TokenType.OpenParenthesisToken:
case TokenType.CloseParenthesisToken:
case TokenType.OpenBraceToken:
case TokenType.CloseBraceToken:
case TokenType.ReturnToken:
case TokenType.SemicolonToken:
case TokenType.IdentifierToken:
case TokenType.InvalidToken:
throw new UnexpectedTokenException(TokenType.IntToken, expressionToken.TokenType);
default: default:
throw new UnexpectedTokenException(TokenType.IntToken, expressionToken.TokenType); throw new UnexpectedTokenException(TokenType.IntegerLiteralToken,
expressionToken.TokenType);
}
break;
case NodeType.UnaryOperatorNode:
if (_tokenList.Count == 0)
{
throw new MissingTokenException(TokenType.IntegerLiteralToken);
}
else
{
Token unaryOperator = _tokenList[0];
_tokenList.RemoveAt(0);
switch (unaryOperator.TokenType)
{
case TokenType.BitwiseComplementToken:
n = new UnaryOperatorNode(OperatorType.BitwiseComplement);
n.Children.Add(Parse(NodeType.ExpressionNode));
break;
case TokenType.NegationToken:
n = new UnaryOperatorNode(OperatorType.Negation);
n.Children.Add(Parse(NodeType.ExpressionNode));
break;
case TokenType.LogicalNegationToken:
n = new UnaryOperatorNode(OperatorType.LogicalNegation);
n.Children.Add(Parse(NodeType.ExpressionNode));
break;
default:
throw new UnexpectedTokenException(TokenType.IntegerLiteralToken,
unaryOperator.TokenType);
}
} }
break; break;
case NodeType.ConstantNode:
if (_tokenList.Count == 0)
{
throw new MissingTokenException(TokenType.IntegerLiteralToken);
}
//double check, for safety. Pbly unnecesarry
if (_tokenList[0].TokenType != TokenType.IntegerLiteralToken)
{
throw new UnexpectedTokenException(TokenType.IntegerLiteralToken, _tokenList[0].TokenType);
}
else
{
//return final constant node to end recursion
n = new ConstantNode((int) _tokenList[0].Value);
_tokenList.RemoveAt(0);
break;
}
default: default:
throw new Exception("Unknown Node Type " + nodeType); throw new Exception("Unknown Node Type " + nodeType);
} }