diff options
author | chris.sutcliffe <ctd.sutcliffe@gmail.com> | 2021-11-29 16:46:56 +0000 |
---|---|---|
committer | chris.sutcliffe <ctd.sutcliffe@gmail.com> | 2021-11-29 16:46:56 +0000 |
commit | 33359862f5455dc7003ebbe5357c611298042cee (patch) | |
tree | 1eff075406177fb2d0feff685f24c7e306f589c8 | |
parent | 2e3be43da8761eb77b00af20f559fef7a8c6b1b8 (diff) | |
download | esotericFORTRAN-33359862f5455dc7003ebbe5357c611298042cee.tar.gz esotericFORTRAN-33359862f5455dc7003ebbe5357c611298042cee.zip |
clean repo (remove code dir, add UI dir)
46 files changed, 0 insertions, 1564 deletions
diff --git a/code/.idea/.name b/code/.idea/.name deleted file mode 100644 index 5c3a976..0000000 --- a/code/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Interpreter2
\ No newline at end of file diff --git a/code/.idea/misc.xml b/code/.idea/misc.xml deleted file mode 100644 index b1001d2..0000000 --- a/code/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK"> - <output url="file://$PROJECT_DIR$/out" /> - </component> -</project>
\ No newline at end of file diff --git a/code/.idea/modules.xml b/code/.idea/modules.xml deleted file mode 100644 index 944dd7c..0000000 --- a/code/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectModuleManager"> - <modules> - <module fileurl="file://$PROJECT_DIR$/Interpreter2.iml" filepath="$PROJECT_DIR$/Interpreter2.iml" /> - </modules> - </component> -</project>
\ No newline at end of file diff --git a/code/.idea/vcs.xml b/code/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/code/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="VcsDirectoryMappings"> - <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> - </component> -</project>
\ No newline at end of file diff --git a/code/.idea/workspace.xml b/code/.idea/workspace.xml deleted file mode 100644 index 7952f3a..0000000 --- a/code/.idea/workspace.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ChangeListManager"> - <list default="true" id="6338c043-7429-4cfe-b52b-2dbae6a3427a" name="Default Changelist" comment="" /> - <option name="SHOW_DIALOG" value="false" /> - <option name="HIGHLIGHT_CONFLICTS" value="true" /> - <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> - <option name="LAST_RESOLUTION" value="IGNORE" /> - </component> - <component name="Git.Settings"> - <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." /> - </component> - <component name="ProjectId" id="20PtOhkYAa3ilFbr4c95bfXTsk5" /> - <component name="ProjectLevelVcsManager" settingsEditedManually="true" /> - <component name="ProjectViewState"> - <option name="hideEmptyMiddlePackages" value="true" /> - <option name="showLibraryContents" value="true" /> - </component> - <component name="PropertiesComponent"> - <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> - </component> - <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> - <component name="TaskManager"> - <task active="true" id="Default" summary="Default task"> - <changelist id="6338c043-7429-4cfe-b52b-2dbae6a3427a" name="Default Changelist" comment="" /> - <created>1635958020139</created> - <option name="number" value="Default" /> - <option name="presentableId" value="Default" /> - <updated>1635958020139</updated> - </task> - <servers /> - </component> -</project>
\ No newline at end of file diff --git a/code/FORTRAN2C/Makefile b/code/FORTRAN2C/Makefile deleted file mode 100644 index 87610cf..0000000 --- a/code/FORTRAN2C/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: - java -jar ../../../sablecc-3.7/lib/sablecc.jar fortran2c.grammar - -clean: - rm -rfv fortran2c/analysis/ - rm -rfv fortran2c/lexer/ - rm -rfv fortran2c/node/ - rm -rvf fortran2c/parser/ diff --git a/code/FORTRAN2C/build/out.c b/code/FORTRAN2C/build/out.c deleted file mode 100644 index 47d2d58..0000000 --- a/code/FORTRAN2C/build/out.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> - -int main(int argc, char** argv) { - -}
\ No newline at end of file diff --git a/code/FORTRAN2C/examples/maths.txt b/code/FORTRAN2C/examples/maths.txt deleted file mode 100644 index 36726f5..0000000 --- a/code/FORTRAN2C/examples/maths.txt +++ /dev/null @@ -1 +0,0 @@ -(36/2 + 45.2) * 3
\ No newline at end of file diff --git a/code/FORTRAN2C/examples/maths2.txt b/code/FORTRAN2C/examples/maths2.txt deleted file mode 100644 index 313296b..0000000 --- a/code/FORTRAN2C/examples/maths2.txt +++ /dev/null @@ -1 +0,0 @@ -sin(45 * 2) / 3 diff --git a/code/FORTRAN2C/examples/maths3.txt b/code/FORTRAN2C/examples/maths3.txt deleted file mode 100644 index e092af1..0000000 --- a/code/FORTRAN2C/examples/maths3.txt +++ /dev/null @@ -1 +0,0 @@ -3-1+2
\ No newline at end of file diff --git a/code/FORTRAN2C/examples/maths4.txt b/code/FORTRAN2C/examples/maths4.txt deleted file mode 100644 index a922b77..0000000 --- a/code/FORTRAN2C/examples/maths4.txt +++ /dev/null @@ -1 +0,0 @@ -2 + 2 diff --git a/code/FORTRAN2C/fortran2c.grammar b/code/FORTRAN2C/fortran2c.grammar deleted file mode 100644 index 80bf2b7..0000000 --- a/code/FORTRAN2C/fortran2c.grammar +++ /dev/null @@ -1,35 +0,0 @@ -Package fortran2c; -Helpers - digit = ['0' .. '9']; -Tokens - number = digit+; - double = ((digit)+ '.' (digit)*) | ((digit)* '.' (digit)+); - plus = '+'; - minus = '-'; - mult = '*'; - div = '/'; - mod = '%'; - l_par = '('; - r_par = ')'; - sin = 'sin'; - blank = (' ' | 13 | 10)+; -Ignored Tokens - blank; -Productions - expr = - {factor} factor | - {plus} expr plus factor | - {minus} expr minus factor - ; - factor = - {term} term | - {mult} factor mult term | - {div} factor div term | - {mod} factor mod term - ; - term = - {number} number | - {double} double | - {expr} l_par expr r_par | - {sine} sin l_par expr r_par - ;
\ No newline at end of file diff --git a/code/FORTRAN2C/fortran2c/CWriter.java b/code/FORTRAN2C/fortran2c/CWriter.java deleted file mode 100644 index fec748a..0000000 --- a/code/FORTRAN2C/fortran2c/CWriter.java +++ /dev/null @@ -1,26 +0,0 @@ -package fortran2c; - -import java.io.*; -import java.util.HashSet; - -public class CWriter { - - private String filePath; - private File theFile; - private FileWriter theFileWriter; - private HashSet<String> functions; - - public CWriter(String filePath) throws IOException { - this.filePath = filePath; - File theFile = new File(filePath); - - if (theFile.createNewFile()) { - FileWriter theFileWriter = new FileWriter(filePath); - theFileWriter.write("#include <stdio.h>\n#include <stdlib.h>\n\nint main(int argc, char** argv) {\n}"); - theFileWriter.close(); - functions.add("main"); - } else { - throw new IOException("The file already exists"); - } - } -} diff --git a/code/FORTRAN2C/fortran2c/Compiler.java b/code/FORTRAN2C/fortran2c/Compiler.java deleted file mode 100644 index 7b124fa..0000000 --- a/code/FORTRAN2C/fortran2c/Compiler.java +++ /dev/null @@ -1,28 +0,0 @@ -package fortran2c; -import fortran2c.parser.*; -import fortran2c.lexer.*; -import fortran2c.node.*; -import java.io.*; - -public class Compiler -{ - public static void main(String[] args) - { - try - { - System.out.println("Using source file: " + args[0]); - // Create a Parser instance. - Parser p = new Parser(new Lexer(new PushbackReader(new InputStreamReader(new FileInputStream(args[0])), 1024))); - // Parse the input. - Start tree = p.parse(); - // Apply the translation. - CWriter cWriter = new CWriter("build/out.c"); - - tree.apply(new Translation(cWriter)); - } - catch(Exception e) - { - System.out.println(e.getMessage()); - } - } -}
\ No newline at end of file diff --git a/code/FORTRAN2C/fortran2c/Translation.java b/code/FORTRAN2C/fortran2c/Translation.java deleted file mode 100644 index f5eeaba..0000000 --- a/code/FORTRAN2C/fortran2c/Translation.java +++ /dev/null @@ -1,13 +0,0 @@ -package fortran2c; -import fortran2c.analysis.*; -import fortran2c.node.*; - -class Translation extends DepthFirstAdapter -{ - - private CWriter writer; - - public Translation(CWriter writer) { - this.writer = writer; - } -} diff --git a/code/Interpreter2.iml b/code/Interpreter2.iml deleted file mode 100644 index c90834f..0000000 --- a/code/Interpreter2.iml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module>
\ No newline at end of file diff --git a/code/Interpreter2/.idea/misc.xml b/code/Interpreter2/.idea/misc.xml deleted file mode 100644 index b1001d2..0000000 --- a/code/Interpreter2/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK"> - <output url="file://$PROJECT_DIR$/out" /> - </component> -</project>
\ No newline at end of file diff --git a/code/Interpreter2/.idea/modules.xml b/code/Interpreter2/.idea/modules.xml deleted file mode 100644 index 944dd7c..0000000 --- a/code/Interpreter2/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ProjectModuleManager"> - <modules> - <module fileurl="file://$PROJECT_DIR$/Interpreter2.iml" filepath="$PROJECT_DIR$/Interpreter2.iml" /> - </modules> - </component> -</project>
\ No newline at end of file diff --git a/code/Interpreter2/.idea/uiDesigner.xml b/code/Interpreter2/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/code/Interpreter2/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="Palette2"> - <group name="Swing"> - <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> - </item> - <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> - </item> - <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> - </item> - <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> - <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> - </item> - <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> - <initial-values> - <property name="text" value="Button" /> - </initial-values> - </item> - <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> - <initial-values> - <property name="text" value="RadioButton" /> - </initial-values> - </item> - <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> - <initial-values> - <property name="text" value="CheckBox" /> - </initial-values> - </item> - <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> - <initial-values> - <property name="text" value="Label" /> - </initial-values> - </item> - <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> - <preferred-size width="150" height="-1" /> - </default-constraints> - </item> - <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> - <preferred-size width="150" height="-1" /> - </default-constraints> - </item> - <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> - <preferred-size width="150" height="-1" /> - </default-constraints> - </item> - <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> - </item> - <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> - <preferred-size width="150" height="50" /> - </default-constraints> - </item> - <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> - <preferred-size width="200" height="200" /> - </default-constraints> - </item> - <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> - <preferred-size width="200" height="200" /> - </default-constraints> - </item> - <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> - </item> - <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> - </item> - <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> - </item> - <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> - </item> - <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> - <preferred-size width="-1" height="20" /> - </default-constraints> - </item> - <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> - <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> - </item> - <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> - <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> - </item> - </group> - </component> -</project>
\ No newline at end of file diff --git a/code/Interpreter2/.idea/vcs.xml b/code/Interpreter2/.idea/vcs.xml deleted file mode 100644 index b2bdec2..0000000 --- a/code/Interpreter2/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="VcsDirectoryMappings"> - <mapping directory="$PROJECT_DIR$/../.." vcs="Git" /> - </component> -</project>
\ No newline at end of file diff --git a/code/Interpreter2/.idea/workspace.xml b/code/Interpreter2/.idea/workspace.xml deleted file mode 100644 index f00309a..0000000 --- a/code/Interpreter2/.idea/workspace.xml +++ /dev/null @@ -1,69 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="ChangeListManager"> - <list default="true" id="d53ed2ac-d387-4e72-b30b-e936be78d097" name="Default Changelist" comment="" /> - <option name="SHOW_DIALOG" value="false" /> - <option name="HIGHLIGHT_CONFLICTS" value="true" /> - <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> - <option name="LAST_RESOLUTION" value="IGNORE" /> - </component> - <component name="Git.Settings"> - <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../.." /> - </component> - <component name="ProjectId" id="20PtUsPCm3Avx9BljmzQRhs1xbs" /> - <component name="ProjectLevelVcsManager" settingsEditedManually="true" /> - <component name="ProjectViewState"> - <option name="hideEmptyMiddlePackages" value="true" /> - <option name="showLibraryContents" value="true" /> - </component> - <component name="PropertiesComponent"> - <property name="RunOnceActivity.OpenProjectViewOnStart" value="true" /> - </component> - <component name="RunManager"> - <configuration name="Language" type="Application" factoryName="Application"> - <option name="MAIN_CLASS_NAME" value="Interpreter.Language" /> - <module name="Interpreter2" /> - <option name="PROGRAM_PARAMETERS" value="example.txt" /> - <method v="2"> - <option name="Make" enabled="true" /> - </method> - </configuration> - </component> - <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> - <component name="TaskManager"> - <task active="true" id="Default" summary="Default task"> - <changelist id="d53ed2ac-d387-4e72-b30b-e936be78d097" name="Default Changelist" comment="" /> - <created>1635958069096</created> - <option name="number" value="Default" /> - <option name="presentableId" value="Default" /> - <updated>1635958069096</updated> - </task> - <servers /> - </component> - <component name="WindowStateProjectService"> - <state x="623" y="181" width="1092" height="714" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1635958679737"> - <screen x="0" y="0" width="1920" height="1050" /> - </state> - <state x="623" y="181" width="1092" height="714" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1050/-1920.0.1920.1050@0.0.1920.1050" timestamp="1635958679737" /> - <state x="689" y="327" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1635958256418"> - <screen x="0" y="0" width="1920" height="1050" /> - </state> - <state x="689" y="327" key="#com.intellij.ide.util.TreeClassChooserDialog/0.0.1920.1050/-1920.0.1920.1050@0.0.1920.1050" timestamp="1635958256418" /> - <state width="1877" height="177" key="GridCell.Tab.0.bottom" timestamp="1635959349993"> - <screen x="0" y="0" width="1920" height="1050" /> - </state> - <state width="1877" height="177" key="GridCell.Tab.0.bottom/0.0.1920.1050/-1920.0.1920.1050@0.0.1920.1050" timestamp="1635959349993" /> - <state width="1877" height="177" key="GridCell.Tab.0.center" timestamp="1635959349992"> - <screen x="0" y="0" width="1920" height="1050" /> - </state> - <state width="1877" height="177" key="GridCell.Tab.0.center/0.0.1920.1050/-1920.0.1920.1050@0.0.1920.1050" timestamp="1635959349992" /> - <state width="1877" height="177" key="GridCell.Tab.0.left" timestamp="1635959349992"> - <screen x="0" y="0" width="1920" height="1050" /> - </state> - <state width="1877" height="177" key="GridCell.Tab.0.left/0.0.1920.1050/-1920.0.1920.1050@0.0.1920.1050" timestamp="1635959349992" /> - <state width="1877" height="177" key="GridCell.Tab.0.right" timestamp="1635959349992"> - <screen x="0" y="0" width="1920" height="1050" /> - </state> - <state width="1877" height="177" key="GridCell.Tab.0.right/0.0.1920.1050/-1920.0.1920.1050@0.0.1920.1050" timestamp="1635959349992" /> - </component> -</project>
\ No newline at end of file diff --git a/code/Interpreter2/Interpreter2.iml b/code/Interpreter2/Interpreter2.iml deleted file mode 100644 index c90834f..0000000 --- a/code/Interpreter2/Interpreter2.iml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module type="JAVA_MODULE" version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="true"> - <exclude-output /> - <content url="file://$MODULE_DIR$"> - <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> - </content> - <orderEntry type="inheritedJdk" /> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module>
\ No newline at end of file diff --git a/code/Interpreter2/example.txt b/code/Interpreter2/example.txt deleted file mode 100644 index cf6adc8..0000000 --- a/code/Interpreter2/example.txt +++ /dev/null @@ -1,12 +0,0 @@ -var :: a -a=5 -a=a+1 -print a - -a=7 -a=a*2 -print a - -var :: b -b = 10 -print a+b
\ No newline at end of file diff --git a/code/Interpreter2/src/Interpreter/Environment.java b/code/Interpreter2/src/Interpreter/Environment.java deleted file mode 100644 index d191bde..0000000 --- a/code/Interpreter2/src/Interpreter/Environment.java +++ /dev/null @@ -1,30 +0,0 @@ -package Interpreter; - -import java.util.HashMap; -import java.util.Map; - -public class Environment { - private final Map<String,Object> variableMap = new HashMap<>(); - - //Maybe check if variable is already defined? - public void defineVariable(String name,Object value){ - variableMap.put(name, value); - } - - public Object getVariable(String name){ - if(variableMap.containsKey(name)){ - return variableMap.get(name); - } - Language.displayError("Undefined Variable"); - throw new Error(); - } - - public void assignVariable(String name,Object value){ - if(variableMap.containsKey(name)){ - variableMap.put(name, value); - return; - } - Language.displayError("Variable undefined"); - throw new Error(); - } -} diff --git a/code/Interpreter2/src/Interpreter/Expression.java b/code/Interpreter2/src/Interpreter/Expression.java deleted file mode 100644 index 85ade48..0000000 --- a/code/Interpreter2/src/Interpreter/Expression.java +++ /dev/null @@ -1,84 +0,0 @@ -package Interpreter; - -abstract class Expression { - static class Binary extends Expression{ - - final Expression left; - final Expression right; - final Token op; - - Binary(Expression left, Token op, Expression right){ - this.left=left; - this.op=op; - this.right = right; - } - - @Override - public String getExpressionType() { - return "binary"; - } - - } - - static class Literal extends Expression{ - final Token value; - - Literal(Token value){ - this.value=value; - } - - - @Override - public String getExpressionType() { - return "literal"; - } - - } - - static class BracketedExpression extends Expression{ - final Expression expr; - - BracketedExpression(Expression expr){ - this.expr=expr; - } - - @Override - public String getExpressionType() { - return "bracket"; - } - - - } - - static class AssignmentExpression extends Expression{ - final Token name; - final Expression value; - - AssignmentExpression(Token name,Expression value){ - this.name=name; - this.value=value; - } - - - @Override - public String getExpressionType() { - return "assign"; - } - - } - - static class Variable extends Expression{ - - Variable(Token name){ - this.name=name; - - } - @Override - public String getExpressionType() { - return "var"; - } - final Token name; - - } - public abstract String getExpressionType(); -} diff --git a/code/Interpreter2/src/Interpreter/Interpreter.java b/code/Interpreter2/src/Interpreter/Interpreter.java deleted file mode 100644 index 65cdeb4..0000000 --- a/code/Interpreter2/src/Interpreter/Interpreter.java +++ /dev/null @@ -1,131 +0,0 @@ -package Interpreter; - -import java.util.List; - -import Interpreter.Expression.*; -import Interpreter.Statement.ExpressionStatement; -import Interpreter.Statement.PrintStatement; -import Interpreter.Statement.VariableDeclaration; - -public class Interpreter { - - private Environment environment = new Environment(); - - void interpret(List<Statement> statements){ - try{ - for (Statement statement: statements){ - evaluateStatement(statement); - } - } catch (Error e){ - - } - } - - private Object evaluateStatement(Statement statement){ - switch(statement.getStatmentType()){ - case "exprStmt": - return evalExpressionStatement((ExpressionStatement)statement); - case "vardec": - return evalVariableDeclaration((VariableDeclaration)statement); - case "print": - return evalPrintStatement((PrintStatement)statement); - default: - return null; - } - } - private Object evalExpressionStatement(ExpressionStatement stmt){ - return evaluateExpression(stmt.expr); - } - - private Object evalVariableDeclaration(VariableDeclaration vardec){ - environment.defineVariable(vardec.name.text, null); - return null; - } - - private Object evalPrintStatement(PrintStatement print){ - System.out.println(evaluateExpression(print.expr)); - return null; - } - - private Object evaluateExpression(Expression expression){ - switch(expression.getExpressionType()){ - case "binary": - return evaluateBinaryExpression((Binary)expression); - case "literal": - return evaluateLiteralExpression((Literal)expression); - case "bracket": - return evaluateBracketedExpression((BracketedExpression)expression); - case "assign": - return evaluateAssignmentExpression((AssignmentExpression)expression); - case "var": - return evaluateVariableExpression((Variable)expression); - default: - return null; - } - } - - private Object evaluateBinaryExpression(Binary expr){ - Object leftEval = evaluateExpression(expr.left); - Object rightEval = evaluateExpression(expr.right); - switch (expr.op.type){ - case PLUS: - if (checkOperandsNum(leftEval, leftEval)){ - return (double)leftEval + (double)rightEval; - } - case STAR: - if (checkOperandsNum(leftEval, leftEval)){ - return (double)leftEval * (double)rightEval; - } - case MINUS: - if (checkOperandsNum(leftEval, leftEval)){ - return (double)leftEval - (double)rightEval; - } - case SLASH: - if (checkOperandsNum(leftEval, leftEval)){ - return (double)leftEval / (double)rightEval; - } - - case GREATER: - if (checkOperandsNum(leftEval, leftEval)){ - return (double)leftEval > (double)rightEval; - } - case LESS: - if (checkOperandsNum(leftEval, leftEval)){ - return (double)leftEval < (double)rightEval; - } - - case EQUALITY: - return leftEval.equals(rightEval); - default: - break; - } - return null; - } - - private Object evaluateLiteralExpression(Literal expr){ - return expr.value.value; - } - - private Object evaluateBracketedExpression(BracketedExpression expr){ - return evaluateExpression(expr.expr); - } - - private Object evaluateAssignmentExpression(AssignmentExpression expr){ - Object assignedValue = evaluateExpression(expr.value); - environment.assignVariable(expr.name.text, assignedValue); - return null; - } - - private Object evaluateVariableExpression(Variable expr){ - return environment.getVariable(expr.name.text); - } - - private boolean checkOperandsNum(Object left, Object right){ - if (left instanceof Double && right instanceof Double){ - return true; - } else { - Language.displayError("Operands must be numbers"); - throw new Error(); - } - } -} diff --git a/code/Interpreter2/src/Interpreter/Language.java b/code/Interpreter2/src/Interpreter/Language.java deleted file mode 100644 index 80aa1e3..0000000 --- a/code/Interpreter2/src/Interpreter/Language.java +++ /dev/null @@ -1,63 +0,0 @@ -package Interpreter; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; -import java.util.Scanner; - -//Base class for the interpreter -public class Language { - static boolean hadError = false; - public static void main(String[] args){ - - //Allow users to input a single line of code - //Still needs some work to re-ask for input after each line - if (args.length < 1){ - Scanner input = new Scanner(System.in); - String sourceCode = "1"; - while (sourceCode!=""){ - System.out.print("Code: "); - sourceCode = input.nextLine(); - runInterpreter(sourceCode); - hadError=false; - } - input.close(); - - //Allow users to provide a path to a file as an argument - } else if (args.length==1){ - try { - String sourcecode = Files.readString(Paths.get(args[0])); //Maybe should set charset here - runInterpreter(sourcecode); - } catch (IOException exception){ - System.out.println("File not found"); - } - - } else { - System.out.println("Error, argument should be file path"); - System.exit(64); - } - } - - //Extract and print each token - private static void runInterpreter(String sourceCode){ - TokenScanner scanner = new TokenScanner(); - List<Token> tokens = scanner.extractTokens(sourceCode); - //for (Token token : tokens) { - // System.out.println(token); - //} - if (hadError) return; - //Parse into AST - Parser parser = new Parser(tokens); - List<Statement> ast = parser.parse(); - if (hadError) return; - Interpreter interpreter = new Interpreter(); - interpreter.interpret(ast); - } - - static void displayError(String message){ - hadError=true; - System.out.println("An error was encountered"); - System.out.println(message); - } -} diff --git a/code/Interpreter2/src/Interpreter/Parser.java b/code/Interpreter2/src/Interpreter/Parser.java deleted file mode 100644 index 6b55299..0000000 --- a/code/Interpreter2/src/Interpreter/Parser.java +++ /dev/null @@ -1,179 +0,0 @@ -package Interpreter; - -import java.util.ArrayList; -import java.util.List; - -public class Parser { - private final List<Token> tokens; - private int currentToken = 0; - - Parser(List<Token> tokens){ - this.tokens=tokens; - } - - List<Statement> parse(){ - List<Statement> statements = new ArrayList<>(); - while (!checkEOF()){ - statements.add(declaration()); - } - return statements; - - } - - private Statement declaration(){ - try{ - if (matchAndAdvance(TokenType.VAR)){ - if (matchOrError(TokenType.DEFINE, ":: Required for variable definition")){ - if (matchOrError(TokenType.IDENTIFIER,"Expected variable name.")){ - Token varName = getPreviousToken(); - return new Statement.VariableDeclaration(varName); - } - } - } - return statement(); - } catch (Error e){ - currentToken++; - return null; - } - } - - private Statement statement(){ - if (matchAndAdvance(TokenType.PRINT)){ - Expression expression = expression(); - return new Statement.PrintStatement(expression); - } - return expressionStatement(); - } - - - - private Statement expressionStatement(){ - Expression expression = assignment(); - return new Statement.ExpressionStatement(expression); - } - - private Expression assignment(){ - Expression variable = expression(); - if (matchAndAdvance(TokenType.EQUALS)){ - Expression assignedvalue = expression(); - - if (variable instanceof Expression.Variable){ - return new Expression.AssignmentExpression(((Expression.Variable)variable).name,assignedvalue); - } - throw error("Incorrect assignment operation"); - } - return variable; - } - - private Expression expression(){ - Expression createdExpression = equality(); - return createdExpression; - } - - private Expression equality(){ - Expression createdExpression = comparison(); - while (matchAndAdvance(TokenType.EQUALITY)){ - Token op = getPreviousToken(); - Expression right = comparison(); - createdExpression = new Expression.Binary(createdExpression, op, right); - } - return createdExpression; - } - - private Expression comparison(){ - Expression createdExpression = term(); - while (matchAndAdvance(TokenType.GREATER)||matchAndAdvance(TokenType.LESS)){ - Token op = getPreviousToken(); - Expression right = term(); - createdExpression = new Expression.Binary(createdExpression, op, right); - } - return createdExpression; - } - - private Expression term(){ - Expression createdExpression = factor(); - while (matchAndAdvance(TokenType.PLUS)||matchAndAdvance(TokenType.MINUS)){ - Token op = getPreviousToken(); - Expression right = factor(); - createdExpression = new Expression.Binary(createdExpression, op, right); - } - return createdExpression; - } - - private Expression factor(){ - Expression createdExpression = primary(); - while (matchAndAdvance(TokenType.STAR)||matchAndAdvance(TokenType.SLASH)){ - Token op = getPreviousToken(); - Expression right = primary(); - createdExpression = new Expression.Binary(createdExpression, op, right); - } - return createdExpression; - } - - private Expression primary(){ - if (matchAndAdvance(TokenType.NUMBER)){ - return new Expression.Literal(getPreviousToken()); - } - - if (matchAndAdvance(TokenType.IDENTIFIER)) { - - return new Expression.Variable(getPreviousToken()); - } - - if (matchAndAdvance(TokenType.LEFT_PAREN)){ - Expression expr = expression(); - if (matchAndAdvance(TokenType.RIGHT_PAREN)){ - return new Expression.BracketedExpression(expr); - } - else{ - throw error("Expected ')"); - } - } - throw error("Expected Expression"); - } - - private void advanceToken(){ - if (!checkEOF()) { - currentToken++; - }; - } - - private boolean matchAndAdvance(TokenType type){ - if (checkToken(type)) { - advanceToken(); - return true; - } - return false; - } - - private boolean matchOrError(TokenType type,String errorMessage){ - if (matchAndAdvance(type)){ - return true; - } - throw error(errorMessage); - } - - private boolean checkToken(TokenType type){ - if (checkEOF()) return false; - return getCurrentToken().type == type; - } - - private boolean checkEOF(){ - return tokens.get(currentToken).type==TokenType.EOF; - } - - private Token getCurrentToken(){ - return tokens.get(currentToken); - } - - private Token getPreviousToken(){ - return tokens.get(currentToken - 1); - } - - private Error error(String message){ - Language.displayError(message); - return new Error(); - } - - -} diff --git a/code/Interpreter2/src/Interpreter/Statement.java b/code/Interpreter2/src/Interpreter/Statement.java deleted file mode 100644 index 5a9aef7..0000000 --- a/code/Interpreter2/src/Interpreter/Statement.java +++ /dev/null @@ -1,49 +0,0 @@ -package Interpreter; - -abstract class Statement { - - static class ExpressionStatement extends Statement{ - ExpressionStatement(Expression expr){ - this.expr = expr; - } - - - final Expression expr; - - @Override - public String getStatmentType() { - return "exprStmt"; - } - } - - - static class VariableDeclaration extends Statement{ - VariableDeclaration(Token name){ - this.name=name; - } - - - final Token name; - - @Override - public String getStatmentType() { - return "vardec"; - } - - } - - static class PrintStatement extends Statement{ - PrintStatement(Expression expr){ - this.expr=expr; - } - final Expression expr; - - @Override - public String getStatmentType() { - return "print"; - } - } - - - public abstract String getStatmentType(); -} diff --git a/code/Interpreter2/src/Interpreter/Token.java b/code/Interpreter2/src/Interpreter/Token.java deleted file mode 100644 index 0129b78..0000000 --- a/code/Interpreter2/src/Interpreter/Token.java +++ /dev/null @@ -1,23 +0,0 @@ -package Interpreter; - -public class Token { - - - //Stores the token type, the actual text and the runtime object - public final TokenType type; - final String text; - final Object value; - - - Token(TokenType type, String text, Object value){ - this.type=type; - this.text=text; - this.value=value; - - } - - @Override - public String toString() { - return type + " " + text + " " + value; - } -} diff --git a/code/Interpreter2/src/Interpreter/TokenScanner.java b/code/Interpreter2/src/Interpreter/TokenScanner.java deleted file mode 100644 index c9249a4..0000000 --- a/code/Interpreter2/src/Interpreter/TokenScanner.java +++ /dev/null @@ -1,179 +0,0 @@ -package Interpreter; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TokenScanner { - private String sourceCode; - List<Token> tokens = new ArrayList<>(); - private int tokenStart=0; - private int currentLoc=0; - - //Extract tokens from the source code by reading character by character - List<Token> extractTokens(String sourceCode){ - this.sourceCode=sourceCode; - while (!checkEOF()){ - tokenStart=currentLoc; - readToken(); - } - tokens.add(new Token(TokenType.EOF, "", null)); - return tokens; - } - - //Extract a single token - private void readToken(){ - char checkChar = sourceCode.charAt(currentLoc); - switch(checkChar){ - - case ' ':break; - case '\n':break; - case '\r':break; - case '\t': - break; - - case '(': createTokenNull(TokenType.LEFT_PAREN); break; - case ')': createTokenNull(TokenType.RIGHT_PAREN); break; - case '+': createTokenNull(TokenType.PLUS); break; - case '-': createTokenNull(TokenType.MINUS); break; - case '*': createTokenNull(TokenType.STAR); break; - case '/': createTokenNull(TokenType.SLASH); break; - case ';': createTokenNull(TokenType.SEMI_COLON); break; - - //Some tokens are multiple characters long (==, <=) etc - //so need to check next char as well - case '=': - if (checkNextChar('=')){ - createTokenNull(TokenType.EQUALITY); - break; - } else { - createTokenNull(TokenType.EQUALS); - break; - } - case ':': - if (checkNextChar(':')){ - createTokenNull(TokenType.DEFINE); - break; - } else { - createTokenNull(TokenType.COLON); - break; - } - case '<': - if (checkNextChar('=')){ - createTokenNull(TokenType.LESS_EQUAL); - break; - } else { - createTokenNull(TokenType.LESS); - break; - } - case '>': - if (checkNextChar('=')){ - createTokenNull(TokenType.GREATER_EQUAL); - break; - } else { - createTokenNull(TokenType.GREATER); - break; - } - default: - - //Check for numer - if (checkIsDigit(checkChar)){ - while (checkIsDigit(lookAhead())){ - currentLoc++; - } - //Check if number contains a decimal point - if (lookAhead()=='.' && checkIsDigit(lookTwoAhead())){ - currentLoc++; - while (checkIsDigit(lookAhead())){ - currentLoc++; - } - } - createToken(TokenType.NUMBER, Double.parseDouble(sourceCode.substring(tokenStart, currentLoc+1))); - } - else if (checkIsAlpha(checkChar)){ - while (checkIsAlpha(lookAhead())){ - currentLoc++; - } - String text = sourceCode.substring(tokenStart, currentLoc+1); - TokenType type = keywords.get(text); - if(type == null){ - createToken(TokenType.IDENTIFIER, text); - } else{ - createToken(type, text); - } - - } else { - Language.displayError("Unexpected Character"); - } - } - currentLoc++; - - } - - //Test for end of file - private boolean checkEOF(){ - return currentLoc>=sourceCode.length(); - } - - //Create a token without a value - private void createTokenNull(TokenType type){ - createToken(type, null); - } - - //Create token - private void createToken(TokenType type, Object value){ - String tokenText = sourceCode.substring(tokenStart, currentLoc+1); - tokens.add(new Token(type, tokenText, value)); - } - - //Check if the next char matches a given char - private boolean checkNextChar(char matchChar){ - if (checkEOF()){ - return false; - } - if (sourceCode.charAt(currentLoc+1)==matchChar){ - currentLoc++; - return true; - } - return false; - } - - //Look at the next char in the source code - private char lookAhead(){ - if (currentLoc+1>=sourceCode.length()){ - return ' '; - - } else { - return sourceCode.charAt(currentLoc+1); - } - } - - //Look 2 chars ahead in the source code - private char lookTwoAhead(){ - if (currentLoc+2>=sourceCode.length()){ - return ' '; - - } else { - return sourceCode.charAt(currentLoc+2); - } - } - - //Check if a given char is a digit - private boolean checkIsDigit(char checkChar){ - return checkChar>='0' && checkChar<='9'; - } - - private boolean checkIsAlpha(char checkChar){ - return ('a'<=checkChar && checkChar<='z')|| - ('A'<=checkChar && checkChar<='Z'); - } - - private static final Map<String, TokenType> keywords; - - static { - keywords = new HashMap<>(); - keywords.put("var", TokenType.VAR); - keywords.put("print", TokenType.PRINT); - } -} diff --git a/code/Interpreter2/src/Interpreter/TokenType.java b/code/Interpreter2/src/Interpreter/TokenType.java deleted file mode 100644 index 756fab6..0000000 --- a/code/Interpreter2/src/Interpreter/TokenType.java +++ /dev/null @@ -1,17 +0,0 @@ -package Interpreter; - -public enum TokenType { - EQUALS, LEFT_PAREN, RIGHT_PAREN, - PLUS, MINUS, SLASH, STAR, SEMI_COLON, - COLON, - - EQUALITY, GREATER, LESS, - GREATER_EQUAL, LESS_EQUAL, - DEFINE, - - NUMBER,IDENTIFIER, - - VAR,PRINT, - - EOF -} diff --git a/code/simpleSableCCCalulator/Makefile b/code/simpleSableCCCalulator/Makefile deleted file mode 100644 index 477422b..0000000 --- a/code/simpleSableCCCalulator/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -all: - java -jar ../../../sablecc-3.7/lib/sablecc.jar sableCCCalculator.grammar - javac sableCCCalculator/*.java - javac sableCCCalculator/types/*.java - - -clean: - rm -vf sableCCCalculator/*.class - rm -vf sableCCCalculator/types/*class - rm -rfv sableCCCalculator/analysis/ - rm -rfv sableCCCalculator/lexer/ - rm -rfv sableCCCalculator/node/ - rm -rvf sableCCCalculator/parser/ diff --git a/code/simpleSableCCCalulator/README.md b/code/simpleSableCCCalulator/README.md deleted file mode 100644 index 4878685..0000000 --- a/code/simpleSableCCCalulator/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# simpleSableCCCalculator - -sableCC is a too used to parse .grammar files (containing a BNF, and lexer information) -into a lexer and parser. We can do a depth first traversal of the produced abstract syntax tree -to parse in the correct order. This is in the file `Translation.java`. - -You produce a lexer and parser by running the sablecc .jar file you can download [here](http://downloads.sourceforge.net/sablecc/sablecc-3.7.zip). Then run it with the first argument as the grammar file: - -`java -jar sablecc-3.7/lib/sablecc.jar sableCCCalculator.grammar` - -(changing the paths as appropriate). The produced java files are not included in git since they're unnessicary. We compile the compiler, program stack and translator: - -`javac sableCCCalculator/*.java` - -I setup a makefil that can be used. First make sure that sablecc is extracted in the directory below `EsotericProject` and just run `make`. - -Then we can run the program. For now it only works by reading files. There are some example maths questions in the examples folder: - -`java sableCCCalculator.Compiler examples/maths.txt` - - - diff --git a/code/simpleSableCCCalulator/examples/maths.txt b/code/simpleSableCCCalulator/examples/maths.txt deleted file mode 100644 index 36726f5..0000000 --- a/code/simpleSableCCCalulator/examples/maths.txt +++ /dev/null @@ -1 +0,0 @@ -(36/2 + 45.2) * 3
\ No newline at end of file diff --git a/code/simpleSableCCCalulator/examples/maths2.txt b/code/simpleSableCCCalulator/examples/maths2.txt deleted file mode 100644 index 313296b..0000000 --- a/code/simpleSableCCCalulator/examples/maths2.txt +++ /dev/null @@ -1 +0,0 @@ -sin(45 * 2) / 3 diff --git a/code/simpleSableCCCalulator/examples/maths3.txt b/code/simpleSableCCCalulator/examples/maths3.txt deleted file mode 100644 index e092af1..0000000 --- a/code/simpleSableCCCalulator/examples/maths3.txt +++ /dev/null @@ -1 +0,0 @@ -3-1+2
\ No newline at end of file diff --git a/code/simpleSableCCCalulator/examples/maths4.txt b/code/simpleSableCCCalulator/examples/maths4.txt deleted file mode 100644 index a922b77..0000000 --- a/code/simpleSableCCCalulator/examples/maths4.txt +++ /dev/null @@ -1 +0,0 @@ -2 + 2 diff --git a/code/simpleSableCCCalulator/sableCCCalculator/Compiler.java b/code/simpleSableCCCalulator/sableCCCalculator/Compiler.java deleted file mode 100644 index 7430cfe..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/Compiler.java +++ /dev/null @@ -1,27 +0,0 @@ -package sableCCCalculator; -import sableCCCalculator.parser.*; -import sableCCCalculator.lexer.*; -import sableCCCalculator.node.*; -import java.io.*; - -public class Compiler -{ - public static void main(String[] args) - { - try - { - System.out.println("Using source file: " + args[0]); - // Create a Parser instance. - Parser p = new Parser(new Lexer(new PushbackReader(new InputStreamReader(new FileInputStream(args[0])), 1024))); - // Parse the input. - Start tree = p.parse(); - // Apply the translation. - tree.apply(new Translation()); - System.out.println(""); - } - catch(Exception e) - { - System.out.println(e.getMessage()); - } - } -}
\ No newline at end of file diff --git a/code/simpleSableCCCalulator/sableCCCalculator/ProgramStack.java b/code/simpleSableCCCalulator/sableCCCalculator/ProgramStack.java deleted file mode 100644 index b49c0d1..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/ProgramStack.java +++ /dev/null @@ -1,31 +0,0 @@ -package sableCCCalculator; -import sableCCCalculator.SymbolTable.SymbolTableIndex; -import sableCCCalculator.types.*; -import java.util.Stack; - -public class ProgramStack extends Stack<SymbolTableIndex> { - - public String toString(SymbolTable table) { - String out = "Stack is now: ["; - for (int i = 0; i < this.size(); i++) { - // String theStr = this.elementAt(i).toString(); - // out += String.format("%s, ", theStr.substring(0, theStr.length() - 1)); - out += String.format("%s, ", table.get(this.elementAt(i))); - } - return out.substring(0, out.length() - 2) + "]"; - } - - public static void main(String[] args) { - ProgramStack myStack = new ProgramStack(); - SymbolTable table = new SymbolTable(); - myStack.add(table.addConstant(new Int(2))); - myStack.add(table.addConstant(new Int(4))); - myStack.add(table.addConstant(new Int(6))); - myStack.add(table.addConstant(new Int(0))); - myStack.add(table.addConstant(new Int(1))); - myStack.add(table.addConstant(new Decimal(24601.10642))); - - System.out.println(table.get(myStack.pop())); - System.out.println(myStack.toString(table)); - } -} diff --git a/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java b/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java deleted file mode 100644 index 992e873..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java +++ /dev/null @@ -1,63 +0,0 @@ -package sableCCCalculator; -import java.util.HashMap; -import sableCCCalculator.types.*; - -public class SymbolTable { - - public interface SymbolTableIndex {} - - public abstract class Name implements SymbolTableIndex { - // can be used for functions too hopefully one day... - protected String name; - - String getName() { - return this.name; - } - } - - public class Constant implements SymbolTableIndex { - int index; - - public Constant(int index) { - this.index = index; - } - } - - public class Variable extends Name { - public Variable(String name) { - this.name = name; - } - } - - private HashMap<SymbolTableIndex, Type> theSymbolTable = new HashMap<>(); - - public SymbolTableIndex addConstant(Type item) { - SymbolTableIndex index = new Constant(item.hashCode()); - theSymbolTable.put(index, item); - return index; - } - - public SymbolTableIndex addVariable(Type item, String name) { - SymbolTableIndex index = new Variable(name); - theSymbolTable.put(index, item); - return index; - } - - public void updateVariable(Type newItem, SymbolTableIndex index) { - theSymbolTable.replace(index, newItem); - } - - public Type get(SymbolTableIndex index) { - return theSymbolTable.get(index); - } - - public static void main(String[] args) { - SymbolTable symbolTable = new SymbolTable(); - symbolTable.addConstant(new Int(3)); - SymbolTableIndex i_var = symbolTable.addVariable(new Int(0), "i"); - System.out.println(symbolTable.get(i_var)); - symbolTable.updateVariable(symbolTable.get(i_var).add(new Int(1)), i_var); - System.out.println(symbolTable.get(i_var)); - } -} -
\ No newline at end of file diff --git a/code/simpleSableCCCalulator/sableCCCalculator/Translation.java b/code/simpleSableCCCalulator/sableCCCalculator/Translation.java deleted file mode 100644 index 43041c4..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/Translation.java +++ /dev/null @@ -1,89 +0,0 @@ -package sableCCCalculator; -import sableCCCalculator.analysis.*; -import sableCCCalculator.types.*; -import sableCCCalculator.node.*; - -class Translation extends DepthFirstAdapter -{ - private ProgramStack programStack = new ProgramStack(); - private SymbolTable symbolTable = new SymbolTable(); - - public void caseTNumber(TNumber node) - { - System.out.println("Pushing " + Integer.parseInt(node.getText()) + " to stack"); - programStack.push(symbolTable.addConstant(new Int(node.getText()))); - System.out.println(programStack.toString(symbolTable)); - } - - public void caseTDouble(TDouble node) - { - System.out.println("Pushing a double: " + Double.parseDouble(node.getText())); - programStack.push(symbolTable.addConstant(new Decimal(node.getText()))); - System.out.println(programStack.toString(symbolTable)); - } - - public void outASineTerm(ASineTerm node) - { - Double num = Double.parseDouble(symbolTable.get(programStack.pop()).toString()); - System.out.println("Popped " + num); - Double out = Math.sin(Math.toRadians(num)); - programStack.push(symbolTable.addConstant(new Decimal(out))); - System.out.println("Pushed sin(" + num + ") = " + out + " to stack"); - System.out.println(programStack.toString(symbolTable)); - } - - public void outAPlusExpr(APlusExpr node) - { - Type op2 = symbolTable.get(programStack.pop()); - Type op1 = symbolTable.get(programStack.pop()); - System.out.println("Popped " + op1 + " and " + op2 + " from stack"); - Type out = op1.add(op2); - programStack.push(symbolTable.addConstant(out)); - System.out.println("Pushed " + op1 + "+" + op2 + "=" + out + " to stack"); - System.out.println(programStack.toString(symbolTable)); - } - - public void outAMinusExpr(AMinusExpr node) - { - Type op2 = symbolTable.get(programStack.pop()); - Type op1 = symbolTable.get(programStack.pop()); - System.out.println("Popped " + op1 + " and " + op2 + " from stack"); - Type out = op1.sub(op2); - programStack.push(symbolTable.addConstant(out)); - System.out.println("Pushed " + op1 + "-" + op2 + "=" + out + " to stack"); - System.out.println(programStack.toString(symbolTable)); - } - - public void outAMultFactor(AMultFactor node) - { - Type op2 = symbolTable.get(programStack.pop()); - Type op1 = symbolTable.get(programStack.pop()); - System.out.println("Popped " + op1 + " and " + op2 + " from stack"); - Type out = op1.mult(op2); - programStack.push(symbolTable.addConstant(out)); - System.out.println("Pushed " + op1 + "*" + op2 + "=" + out + " to stack"); - System.out.println(programStack.toString(symbolTable)); - } - - public void outADivFactor(ADivFactor node) - { - Type op2 = symbolTable.get(programStack.pop()); - Type op1 = symbolTable.get(programStack.pop()); - System.out.println("Popped " + op1 + " and " + op2 + " from stack"); - Type out = op1.div(op2); - programStack.push(symbolTable.addConstant(out)); - System.out.println("Pushed " + op1 + "/" + op2 + "=" + out + " to stack"); - System.out.println(programStack.toString(symbolTable)); - } - - public void outAModFactor(AModFactor node) - { - Type op2 = symbolTable.get(programStack.pop()); - Type op1 = symbolTable.get(programStack.pop()); - System.out.println("Popped " + op1 + " and " + op2 + " from stack"); - Type out = op1.mod(op2); - programStack.push(symbolTable.addConstant(out)); - System.out.println("Pushed " + op1 + "%" + op2 + "=" + out + " to stack"); - System.out.println(programStack.toString(symbolTable)); - } -} diff --git a/code/simpleSableCCCalulator/sableCCCalculator/types/Decimal.java b/code/simpleSableCCCalulator/sableCCCalculator/types/Decimal.java deleted file mode 100644 index 5836ff1..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/types/Decimal.java +++ /dev/null @@ -1,57 +0,0 @@ -package sableCCCalculator.types; - -public class Decimal extends Type { - - public Decimal(Double toDecimal) { - javaObject = (Double)toDecimal; - } - - public Decimal(String toDecimal) { - javaObject = (Double)Double.parseDouble(toDecimal); - } - - public Decimal add(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Decimal")) { - return new Decimal((Double)this.javaObject + (double)toAdd.javaObject); - } else { - return new Decimal((Double)this.javaObject + Double.parseDouble(String.format("%d", (int)toAdd.javaObject))); - } - } - - public Decimal sub(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Decimal")) { - return new Decimal((Double)this.javaObject - (double)toAdd.javaObject); - } else { - return new Decimal((Double)this.javaObject - Double.parseDouble(String.format("%d", (int)toAdd.javaObject))); - } - } - - public Decimal mult(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Decimal")) { - return new Decimal((Double)this.javaObject * (double)toAdd.javaObject); - } else { - return new Decimal((Double)this.javaObject * Double.parseDouble(String.format("%d", (int)toAdd.javaObject))); - } - } - - public Decimal div(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Decimal")) { - return new Decimal((Double)this.javaObject / (double)toAdd.javaObject); - } else { - return new Decimal((Double)this.javaObject / Double.parseDouble(String.format("%d", (int)toAdd.javaObject))); - } - } - - public Decimal mod(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Decimal")) { - return new Decimal((Double)this.javaObject % (double)toAdd.javaObject); - } else { - return new Decimal((Double)this.javaObject % Double.parseDouble(String.format("%d", (int)toAdd.javaObject))); - } - } - - public static void main(String[] args) { - Decimal aDec = new Decimal(3.1); - System.out.println(aDec.sub(new Int(2))); - } -} diff --git a/code/simpleSableCCCalulator/sableCCCalculator/types/Int.java b/code/simpleSableCCCalulator/sableCCCalculator/types/Int.java deleted file mode 100644 index 1ccd20e..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/types/Int.java +++ /dev/null @@ -1,60 +0,0 @@ -package sableCCCalculator.types; - -public class Int extends Type { - - public Int(int toInt) { - javaObject = (Integer)toInt; - } - - public Int(String toInt) { - javaObject = (Integer)Integer.parseInt(toInt); - } - - public Type add(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Int")) { - return new Int((int)this.javaObject + (int)toAdd.javaObject); - } else { - return new Decimal(Double.parseDouble(String.format("%d", (int)this.javaObject)) + (Double)toAdd.javaObject); - } - } - - public Type sub(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Int")) { - return new Int((int)this.javaObject - (int)toAdd.javaObject); - } else { - return new Decimal(Double.parseDouble(String.format("%d", (int)this.javaObject)) - (Double)toAdd.javaObject); - } - } - - public Type mult(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Int")) { - return new Int((int)this.javaObject * (int)toAdd.javaObject); - } else { - return new Decimal(Double.parseDouble(String.format("%d", (int)this.javaObject)) * (Double)toAdd.javaObject); - } - } - - public Type div(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Int")) { - return new Int((int)this.javaObject / (int)toAdd.javaObject); - } else { - return new Decimal(Double.parseDouble(String.format("%d", (int)this.javaObject)) / (Double)toAdd.javaObject); - } - } - - public Type mod(Type toAdd) { - if (toAdd.getClass().getSimpleName().equals("Int")) { - return new Int((int)this.javaObject % (int)toAdd.javaObject); - } else { - return new Decimal(Double.parseDouble(String.format("%d", (int)this.javaObject)) % (Double)toAdd.javaObject); - } - } - - public static void main(String[] args) { - Int int1 = new Int(3); - System.out.println(int1.add(new Int(4))); - - Int int2 = new Int(3); - System.out.println(int2.mult(new Decimal(2.2))); - } -} diff --git a/code/simpleSableCCCalulator/sableCCCalculator/types/Type.java b/code/simpleSableCCCalulator/sableCCCalculator/types/Type.java deleted file mode 100644 index 359f2b8..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/types/Type.java +++ /dev/null @@ -1,22 +0,0 @@ -package sableCCCalculator.types; - -// not happy with the amount of polymorphism -// using generics would be better but idk how that'd work in this context... -public abstract class Type { - - protected Object javaObject; - - public abstract Type add(Type toAdd); - public abstract Type sub(Type toSub); - public abstract Type mult(Type toMult); - public abstract Type div(Type toDiv); - public abstract Type mod(Type toMod); - - public String toString() { - return javaObject.toString(); - } - - public String getText() { - return this.toString(); - } -}
\ No newline at end of file diff --git a/code/.gitkeep b/src/UI/.gitkeep index e69de29..e69de29 100644 --- a/code/.gitkeep +++ b/src/UI/.gitkeep |