diff --git a/README.md b/README.md index 2ad8d5a..22ca1c1 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,8 @@ go [here](https://nanobot567.github.io/potscr) ### how to parse potatoscript -* download the latest version of python from [the website](https://python.org/downloads/) -* clone the latest version of potscr -* open command prompt and change your directory to wherever you downloaded potscr-main to -* type ```python potscr.py (potatoscript file path)``` -* your output will be showed in command prompt! - -### to-do - -- add an interactive shell -- add more stuff to the cli -- unlimited char numeric addition \ No newline at end of file +1. download the latest version of python from [the website](https://python.org/downloads/) +2. clone the latest version of potscr +3. open command prompt and change your directory to wherever you downloaded potscr-main to +4. type ```python potscr.py (potatoscript file path)``` +5. your output will be showed in command prompt! \ No newline at end of file diff --git a/examples/long_script.potscr b/examples/long_script.potscr new file mode 100644 index 0000000..c50af98 --- /dev/null +++ b/examples/long_script.potscr @@ -0,0 +1 @@ +~-Please type an integer: _%#%//-That integer plus, minus, times, and divided by 5: _/+%^`%`%^+%>%^&%&%^~ \ No newline at end of file diff --git a/files/shell.py b/files/shell.py new file mode 100644 index 0000000..6fa41e4 --- /dev/null +++ b/files/shell.py @@ -0,0 +1,128 @@ +from sys import stdout +from time import sleep + +storednum = 0 + +def shell(): + global storednum + txtfound = "" + curnum = 0 + lookinfortxt = "" + firstTime = True + stored = "" + shellver = 1.0 + + while True: + curnum = 0 + shellIn = "" + if firstTime: + print(f"potscr shell v{shellver}\n") + print("type 'quit' to exit.") + firstTime = False + + shellIn = input("> ") + if shellIn == "quit" or shellIn == "q" or shellIn == "bye" or shellIn == "exit": + exit() + + # code in potscr.py starts here + + def mathsomethin(type): + global storednum + try: + if shellIn[curnum+1] == "%": + if shellIn[curnum+2].isnumeric(): + if type == "+": + storednum += int(shellIn[curnum+2]) + elif type == "-": + storednum -= int(shellIn[curnum+2]) + elif type == "*": + storednum = storednum * int(shellIn[curnum+2]) + elif type == "/": + storednum = storednum / int(shellIn[curnum+2]) + else: + if type == "+": + storednum += 5 + elif type == "-": + storednum -= 5 + elif type == "*": + storednum = storednum * 5 + elif type == "/": + storednum = storednum / 5 + except IndexError: + if type == "+": + storednum += 1 + elif type == "-": + storednum -= 1 + elif type == "*": + storednum = storednum * 1 + elif type == "/": + storednum = storednum / 1 + + + + for i in range(0,shellIn.__len__()): + char = shellIn[curnum] + if char == "-": # start of print + lookinfortxt = True + elif char == "_": # end of print + lookinfortxt = False + try: + if shellIn[curnum+1] == "%": # percentage after means an alt version of the command, in this case no newline + stdout.write(txtfound[1:]) + stdout.flush() + txtfound = "" + else: + print(txtfound[1:]) + txtfound = "" + except IndexError: + print(txtfound[1:]) + txtfound = "" + elif char == "#": # get input + temp = input() + try: + if temp.isnumeric() and shellIn[curnum+1] == "%": + storednum = int(temp) + elif shellIn[curnum+1] == "%" and not temp.isnumeric(): + print("ERROR: Input must be an integer!") + exit() + else: + stored = temp + except: + stored = temp + + elif char == "$": # print stored var + print(stored,end="") + elif char == "/": # newline + print("") + elif char == "*": # reset stored number + storednum = 0 + elif char == "+": # number + + mathsomethin("+") + elif char == "`": # number - + mathsomethin("-") + elif char == ">": # number multiplied + mathsomethin("*") + elif char == "&": # number divided + mathsomethin("/") + elif char == "^": # print stored num + try: + if shellIn[curnum+1] == "%": + print(storednum,end="") + else: + print(storednum) + except IndexError: + print(storednum) + + elif char == "@": # sleep + try: + sleep(int(shellIn[curnum+1])) + except ValueError: + print(f"\nERROR: Char {curnum}: An integer is required for sleeping") + exit() + + + + if lookinfortxt: + txtfound += char + + curnum += 1 \ No newline at end of file diff --git a/index.html b/index.html index a775bd8..7c876b5 100644 --- a/index.html +++ b/index.html @@ -1,23 +1,21 @@ potatoscript - home - + + -

potatoscript

+ +

potatoscript is an esoteric programming language, similar to unlambda.

- potatoscript programming guide +

- cli usage guide + \ No newline at end of file diff --git a/potscr.py b/potscr.py index 7544c05..886a2dc 100644 --- a/potscr.py +++ b/potscr.py @@ -1,34 +1,37 @@ #! python -from sys import argv -import sys +from sys import argv, stdout from time import sleep -import os +from os import remove +from files.shell import shell +from shutil import rmtree -ver = "2.18" # format: major potscr release number (dot) commit number +ver = "3.19" # format: major potscr release number (dot) commit number using_py = False script_ok = False lookinfortxt = False +shell_ok = False logit = False len = 0 curnum = 0 +storednum = 0 txtfound = "" stored = "" logpath = "" -storednum = 0 helptxt = f""" potatoscript parser v{ver} -usage: potscr [-h] (input file) [-l (log file)] +usage: potscr [-s] [-h] (input file) [-l (log file)] arguments: -h,--help: shows help -l,--logpath (log file): sets a path for the log file - +-s,--shell: interactive potatoscript shell + """ noargtxt = f""" @@ -38,6 +41,7 @@ """ +rmtree("files\__pycache__") if argv[0] == "potscr" or argv[0] == "potscr.py": using_py = True @@ -70,14 +74,18 @@ if i == "--logpath" or i == "-l": logit = True try: - print(argv[tempnum+1]) logpath = argv[tempnum+1] logfile = open(logpath,"x") except FileExistsError: - os.remove(logpath) - print(argv[tempnum+1]) + remove(logpath) logpath = argv[tempnum+1] logfile = open(logpath,"x") + except IndexError: + print("ERROR: no path specified for log file") + +if "-s" in argv or "--shell" in argv: + shell_ok = True + if using_py: if argv[1].endswith(".potscr") or argv[1].endswith(".potato") or argv[1].endswith(".pscr"): @@ -85,114 +93,185 @@ readit = file.read() if not readit.startswith("~"): print("ERROR: This is not a potatoscript file! Did you forget the ~ in the beginning?") + exit() else: if not readit.endswith("~"): print("ERROR: This file has no ending indicator!") - else: - script_ok = True + exit() + else: if argv[0].endswith(".potscr") or argv[0].endswith(".potato") or argv[0].endswith(".pscr"): file = open(argv[0],"r") readit = file.read() if not readit.startswith("~"): print("ERROR: This is not a potatoscript file! Did you forget the ~ in the beginning?") + exit() else: if not readit.endswith("~"): print("ERROR: This file has no ending indicator!") - else: - script_ok = True - -if not script_ok: - exit() - -for c in readit: - len += 1 - -for i in range(0,len): - char = readit[curnum] - if char == "-": # start of print - lookinfortxt = True - if logit: - logfile.write("LOG: print start\n") - elif char == "_": # end of print - lookinfortxt = False - if readit[curnum+1] == "%": # percentage after means an alt version of the command, in this case no newline - sys.stdout.write(txtfound[1:]) - sys.stdout.flush() - if logit: - logfile.write("LOG: print end (no newline)\n") - logfile.write(f"LOG: printed {txtfound[1:]}\n") - txtfound = "" - else: - print(txtfound[1:]) - if logit: - logfile.write("LOG: print end\n") - logfile.write(f"LOG: printed {txtfound[1:]}\n") - txtfound = "" - elif char == "#": # get input - temp = input() - if temp.isnumeric() and readit[curnum+1] == "%": - storednum = int(temp) - if logit: - logfile.write("LOG: got input from user\n") - logfile.write(f"LOG: storednum = {storednum}\n") - else: - stored = temp - if logit: - logfile.write("LOG: got input from user\n") - logfile.write(f"LOG: stored = {stored}\n") - - elif char == "$": # print stored var - print(stored,end="") - if logit: - logfile.write(f"LOG: printed stored ({stored})\n") - elif char == "/": # newline - print("") - if logit: - logfile.write("LOG: printed newline\n") - elif char == "*": # reset stored number - storednum = 0 - if logit: - logfile.write("LOG: storednum reset\n") - elif char == "+": # number +1 + exit() + + + +if shell_ok: + shell() + + + +# when this is updated, copy-paste into shell.py + +if not shell_ok: + def mathsomethin(type): + global storednum if readit[curnum+1] == "%": if readit[curnum+2].isnumeric(): - storednum += int(readit[curnum+2]) + if type == "+": + storednum += int(readit[curnum+2]) + elif type == "-": + storednum -= int(readit[curnum+2]) + elif type == "*": + storednum = storednum * int(readit[curnum+2]) + elif type == "/": + storednum = storednum / int(readit[curnum+2]) + + if logit: + if type == "+": + logfile.write(f"LOG: added {int(readit[curnum+2])} to storednum (now {storednum})\n") + elif type == "-": + logfile.write(f"LOG: subtracted {int(readit[curnum+2])} from storednum (now {storednum})\n") + elif type == "*": + logfile.write(f"LOG: multiplied {int(readit[curnum+2])} by storednum (now {storednum})\n") + elif type == "/": + logfile.write(f"LOG: divided {int(readit[curnum+2])} by storednum (now {storednum})\n") else: - storednum += 5 - if logit: - logfile.write(f"LOG: added five to storednum (now {storednum})\n") + if type == "+": + storednum += 5 + elif type == "-": + storednum -= 5 + elif type == "*": + storednum = storednum * 5 + elif type == "/": + storednum = storednum / 5 + + if logit: + if type == "+": + logfile.write(f"LOG: added 5 to storednum (now {storednum})\n") + elif type == "-": + logfile.write(f"LOG: subtracted 5 from storednum (now {storednum})\n") + elif type == "*": + logfile.write(f"LOG: multiplied 5 by storednum (now {storednum})\n") + elif type == "/": + logfile.write(f"LOG: divided 5 by storednum (now {storednum})\n") else: - storednum += 1 + if type == "+": + storednum += 1 + elif type == "-": + storednum -= 1 + elif type == "*": + storednum = storednum * 1 + elif type == "/": + storednum = storednum / 1 + if logit: - logfile.write(f"LOG: added one to storednum (now {storednum})\n") - - elif char == "`": # number -1 - if readit[curnum+1] == "%": - if readit[curnum+2].isnumeric(): - storednum -= int(readit[curnum+2]) + if type == "+": + logfile.write(f"LOG: added 1 to storednum (now {storednum})\n") + elif type == "-": + logfile.write(f"LOG: subtracted 1 from storednum (now {storednum})\n") + elif type == "*": + logfile.write(f"LOG: multiplied 1 by storednum (now {storednum})\n") + elif type == "/": + logfile.write(f"LOG: divided 1 by storednum (now {storednum})\n") + + + + for i in range(0,readit.__len__()): + char = readit[curnum] + if char == "-": # start of print + lookinfortxt = True + if logit: + logfile.write("LOG: print start\n") + elif char == "_": # end of print + lookinfortxt = False + try: + if readit[curnum+1] == "%": # percentage after means an alt version of the command, in this case no newline + stdout.write(txtfound[1:]) + stdout.flush() + if logit: + logfile.write("LOG: print end (no newline)\n") + logfile.write(f"LOG: printed {txtfound[1:]}\n") + txtfound = "" + else: + print(txtfound[1:]) + if logit: + logfile.write("LOG: print end\n") + logfile.write(f"LOG: printed {txtfound[1:]}\n") + txtfound = "" + except IndexError: + print(txtfound[1:]) + if logit: + logfile.write("LOG: print end\n") + logfile.write(f"LOG: printed {txtfound[1:]}\n") + txtfound = "" + elif char == "#": # get input + temp = input() + if temp.isnumeric() and readit[curnum+1] == "%": + storednum = int(temp) + if logit: + logfile.write("LOG: got input from user\n") + logfile.write(f"LOG: storednum = {storednum}\n") + elif readit[curnum+1] == "%" and not temp.isnumeric(): + print("ERROR: Input must be an integer!") + if logit: + logfile.write("ERROR: Input must be an integer!") + exit() else: - storednum -= 5 + stored = temp + if logit: + logfile.write("LOG: got input from user\n") + logfile.write(f"LOG: stored = {stored}\n") + + elif char == "$": # print stored var + print(stored,end="") if logit: - logfile.write(f"LOG: subtracted five from storednum (now {storednum})\n") - else: - storednum -= 1 + logfile.write(f"LOG: printed stored ({stored})\n") + elif char == "/": # newline + print("") if logit: - logfile.write(f"LOG: subtracted one from storednum (now {storednum})\n") - elif char == "^": # print stored num - print(storednum,end="") - if logit: - logfile.write(f"LOG: printed storednum ({storednum})\n") - elif char == "@": # sleep - try: - sleep(int(readit[curnum+1])) + logfile.write("LOG: printed newline\n") + elif char == "*": # reset stored number + storednum = 0 if logit: - logfile.write(f"LOG: slept for {int(readit[curnum+1])} second(s)\n") - except ValueError: - print(f"\nERROR: Char {curnum}: An integer is required for sleeping") - exit() - - if lookinfortxt: - txtfound += char + logfile.write("LOG: storednum reset\n") + elif char == "+": # number + + mathsomethin("+") + elif char == "`": # number - + mathsomethin("-") + elif char == ">": # number multiplied + mathsomethin("*") + elif char == "&": # number divided + mathsomethin("/") + elif char == "^": # print stored num + if readit[curnum+1] == "%": + print(storednum,end="") + else: + print(storednum) + + if logit: + logfile.write(f"LOG: printed storednum ({storednum})\n") + elif char == "@": # sleep + try: + sleep(int(readit[curnum+1])) + if logit: + logfile.write(f"LOG: slept for {int(readit[curnum+1])} second(s)\n") + except ValueError: + print(f"\nERROR: Char {curnum}: An integer is required for sleeping") + exit() + + + + if lookinfortxt: + txtfound += char + + curnum += 1 - curnum += 1 + \ No newline at end of file diff --git a/website/cli.html b/website/cli.html index 6f4bc1e..6642f80 100644 --- a/website/cli.html +++ b/website/cli.html @@ -1,22 +1,15 @@ potatoscript - cli - + + - back +

potatoscript cli

usage

to parse a potatoscript file, follow these steps:

@@ -28,7 +21,7 @@

to parse a potatoscript file, follow these steps:

navigate to the directory where your potatoscript file is stored using cd.
  • - run "(path_to_potscr.py) (potatoscript file)"". if no errors are found, the code will excecute. + run "(path_to_potscr.py) (potatoscript file)". if no errors are found, the code will excecute.
  • arguments

    @@ -38,5 +31,7 @@

    -l or --logpath

    sets a path for a log file.

    example:

    potscr.py test_files/maths.potscr --logpath maths_log.txt +

    -s or --shell

    +

    starts the potatoscript shell prompt

    \ No newline at end of file diff --git a/website/css/style.css b/website/css/style.css new file mode 100644 index 0000000..6775588 --- /dev/null +++ b/website/css/style.css @@ -0,0 +1,35 @@ +h1{ + color:sienna; + font-family: "Segoe UI"; + font-size: 45px; + width:100%; + overflow:hidden; + } +code{ + color: sienna; + font-size: 15px; + } + +img{ + animation: slide 3s; + width: 400px; +} +button{ + background-color: sienna; + color: white; +} + + +@keyframes slide { + from { + margin-left: 20%; + opacity: 0%; + } + + to { + margin-left: 0%; + opacity: 100%; + + } + +} \ No newline at end of file diff --git a/website/guide.html b/website/guide.html index ce4bc96..6fd68f5 100644 --- a/website/guide.html +++ b/website/guide.html @@ -1,23 +1,14 @@ - + potatoscript - guide + - back +

    potatoscript guide

    basics

    @@ -72,6 +63,12 @@

    indicators

  • "`" - subtract one from the stored number
  • +
  • + ">" - multiply the stored number by the integer specified +
  • +
  • + "&" - divide the stored number by the integer specified +
  • "^" - print the stored number
  • @@ -79,18 +76,22 @@

    indicators

    "@" - sleep for the integer after the indicator
  • - "%" - alt version of command + "%" - alt version of the indicator
  • alt commands

    -

    +

    -

    depending on how you use %, the + indicator can do different things.

    -

    if % is behind an integer and is in front of +, the stored number is increased by that integer.

    -

    if not, the stored number is increased by 5.

    +

    +, -, >, and & (math indicators)

    +

    depending on how you use %, these indicators can do different things.

    +

    if % is behind an integer and is in front of a math indicator, the stored number is increased, decreased, multiplied, or divided by that integer, depending on which indicator you use.

    +

    if not, the stored number is increased, decreased, multiplied, or divided by 5.

    +

    +

    NOTE: the integer to be used can only be 1 character long for the operation to work as expected.

    +

    +

    _ (print end)

    +

    if % is in front of _, the string printed has no newline printed at the end.

    -

    NOTE: the integer to be added can only be 1 character long for the addition to work properly.

    -

    -

    -

    the same commands as + are preformed if % is in front of -.

    +

    # (get input)

    +

    if % is used, the input gathered from the user is stored as an integer.

    \ No newline at end of file diff --git a/website/favicon.png b/website/img/favicon.png similarity index 100% rename from website/favicon.png rename to website/img/favicon.png diff --git a/website/img/potscr.png b/website/img/potscr.png new file mode 100644 index 0000000..92fa35d Binary files /dev/null and b/website/img/potscr.png differ