From 34bada5f1df57876804ca523007e5bf76e7915d1 Mon Sep 17 00:00:00 2001 From: Gavin Isgar Date: Sun, 11 Nov 2018 17:17:52 -0500 Subject: [PATCH] Commit v1.1.0 content Pushed v1.1.0 content for release. --- changelogs/v1.1.0/README.md | 13 +++ .../lexer2.py => interpreter/interpreter.py} | 89 +++++++++++++++---- src/{lexer => interpreter/outdated}/lexer.py | 3 + src/tests/hi.jee | 1 + src/tests/test.jee | 5 +- 5 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 changelogs/v1.1.0/README.md rename src/{lexer/lexer2.py => interpreter/interpreter.py} (51%) rename src/{lexer => interpreter/outdated}/lexer.py (97%) create mode 100644 src/tests/hi.jee diff --git a/changelogs/v1.1.0/README.md b/changelogs/v1.1.0/README.md new file mode 100644 index 0000000..c0069de --- /dev/null +++ b/changelogs/v1.1.0/README.md @@ -0,0 +1,13 @@ +# Changelog +### Local Debugging +* Debugging of **JeeScript** files can be done using the ``MODE DEBUG`` line at the end of the file. +### Interpreter +* Relabeled sections of interpreter-file. +* Renamed interpreter-file from ``lexer.py`` to ``interpreter.py``; ``interpreter.py`` includes the lexer, parser, and correction functions. +* Changed ``if`` statement for the debugging mode to ``elif`` to prevent command-prompt errors from occurring. +* Made the interpreter check the file being executed to see if it's a compatible **JeeScript** file. +* Added the ``funcdata`` variable for use collecting function information. +### Command-Prompt/Terminal +* Debugging can now be enabled via the command-prompt by adding ``DEBUG`` to the end of the arguments. This is the equivalent to adding ``MODE DEBUG`` within a **JeeScript** file, but this method is less-dependent on when the tokens are added to the interpreter. +### Functions +* **JeeScript's** interpreter now comes with a built-in function that can be used by typing ``LOAD`` or ``load``. This function allows developers to load separate **JeeScript** files programmatically for execution. \ No newline at end of file diff --git a/src/lexer/lexer2.py b/src/interpreter/interpreter.py similarity index 51% rename from src/lexer/lexer2.py rename to src/interpreter/interpreter.py index c0dac52..e57a14b 100644 --- a/src/lexer/lexer2.py +++ b/src/interpreter/interpreter.py @@ -1,3 +1,6 @@ +# COPYRIGHT (C) GAVIN ISGAR 2018 +# JEESCRIPT V1.1.0 INTERPRETER + from sys import * tokens = [] @@ -12,9 +15,12 @@ def lex(filecontents): token = "" stringstate = 0 isexpr = 0 + ismode = 0 + isfunc = 0 string = "" expr = "" - n = "" + funcdata = "" + filecontents = list(filecontents) for char in filecontents: token += char @@ -23,6 +29,7 @@ def lex(filecontents): token = "" else: token = " " + # NEWLINE/EOF --- elif token == "\n" or token == "": if expr != "" and isexpr == 1: tokens.append("EXPR: " + expr) @@ -31,9 +38,17 @@ def lex(filecontents): tokens.append("NUM: " + expr) expr == "" token = "" + # --------------- + # ACTIONS --- elif token == "write" or token == "WRITE": tokens.append("WRITE") token = "" + elif token == "mode" or token == "MODE": + tokens.append("MODE") + ismode = 1 + token = "" + # ----------- + # NUMBERS/EXPR/LETTERS --- elif token == "0" or token == "1" or token == "2" or token == "3" or token == "4" or token == "5" or token == "6" or token == "7" or token == "8" or token == "9": if stringstate == 1: string += token @@ -42,26 +57,51 @@ def lex(filecontents): expr += token token = "" elif token == "+" or token == "-" or token == "*" or token == "/" or token == "%" or token == "(" or token == ")": - if stringstate == 0: + if token == ")" and isfunc == 1: + tokens.append("FUNCDATA: " + funcdata[0:-1]) + funcdata = "" + isfunc = 0 + token = "" + elif stringstate == 0: isexpr = 1 expr += token token = "" + # ------------------------ + # STRINGS --- elif token == "\"": if stringstate == 0: stringstate = 1 elif stringstate == 1: - tokens.append("STRING: " + string + "\"") - string = "" - stringstate = 0 - token = "" + if isfunc == 1: + funcdata += token + token = "" + elif isfunc == 0: + tokens.append("STRING: " + string + "\"") + string = "" + stringstate = 0 + token = "" elif stringstate == 1: - string += token + if isfunc == 1: + funcdata += token + token = "" + elif isfunc == 0: + string += token + token = "" + # ----------- + # FUNCTIONS --- + elif token == "LOAD" or token == "load": + isfunc = 1 + tokens.append("FUNCTION [LOAD]") token = "" - #if token == "DEBUG": - #if not tokens: - #print("**INTERNAL ERROR** " + "Debug list is empty; no debug information to display") - #else: - #print(tokens) + # ------------- + # MODES TYPES --- + elif token == "DEBUG": + if ismode == 1: + tokens.append("DEBUG") + ismode = 0 + token = "" + # --------------- + #Debugging purposes --> print(tokens) return tokens @@ -90,12 +130,29 @@ def parse(tokens): correctPrint(tokens[i+1]) elif tokens[i+1][0:4] == "EXPR": correctPrint(tokens[i+1]) - i+=2 + elif tokens[i] + " " + tokens[i+1][0:5] == "MODE DEBUG": + if tokens[i+1][0:5] == "DEBUG": + print(tokens) + i+=2 + elif tokens[i][0:8] + " " + tokens[i+1][0:8] == "FUNCTION FUNCDATA": + if tokens[i] == "FUNCTION [LOAD]": + lex(open_file(tokens[i+1][11:])) + i+=2 + def run(): - data = open_file(argv[1]) - tokens = lex(data) - parse(tokens) + if argv[1].endswith(".jee"): + data = open_file(argv[1]) + tokens = lex(data) + # "DEBUG" method is currently a placeholder; will change if new argv arguments are added + # This method is not dependent on when the tokens are appended; the tokens are appended before this is ran + if argv.__contains__("DEBUG") or argv.__contains__("debug"): + print(tokens) + else: + print("**ARGS** No arguments are being used; placeholder for background-logging") + parse(tokens) + else: + print("**ERROR** Only JeeScript files can be executed.") run() \ No newline at end of file diff --git a/src/lexer/lexer.py b/src/interpreter/outdated/lexer.py similarity index 97% rename from src/lexer/lexer.py rename to src/interpreter/outdated/lexer.py index 9730e9b..b994321 100644 --- a/src/lexer/lexer.py +++ b/src/interpreter/outdated/lexer.py @@ -1,3 +1,6 @@ +# COPYRIGHT (C) GAVIN ISGAR 2018 +# JEESCRIPT V1.0.0 INTERPRETER + from sys import * tokens = [] diff --git a/src/tests/hi.jee b/src/tests/hi.jee new file mode 100644 index 0000000..e7810e9 --- /dev/null +++ b/src/tests/hi.jee @@ -0,0 +1 @@ +WRITE "This is a test" \ No newline at end of file diff --git a/src/tests/test.jee b/src/tests/test.jee index ff476ef..7e22b38 100644 --- a/src/tests/test.jee +++ b/src/tests/test.jee @@ -1,3 +1,4 @@ WRITE "Hello World" -write "Hi" -WRITE "200+200" \ No newline at end of file +WRITE "Hello 2" +WRITE (2+2) +LOAD("../tests/hi.jee") \ No newline at end of file