Code Monkey home page Code Monkey logo

pseudo's Introduction

Pseudo

An interpreter that translates English to python code

This project was made with the help of David Gmerek, Dvir Bar, Steven Resendiz, and Marlon Gergorio. Without them, I wouldn't have thought of implementing certain features for Pseudo.


Pseudo is an interpreter language built on top of the Python language. It is presented as a GUI/IDE. Pseudo aims to teach you how to code like a programmer by writing down plain English. With Pseudo, learning how to code will be more simple than looking up tutorials of how to make your first "Hello World" program.

Pseudo works by writing down English words with some Python syntax to create Python code. How we achieve this is by the use of Keywords, words that start from the beginning of a line will indicate what code will be generated to a python file. All documentation of Keywords is encapuslated into it.

Its most prominent feature is its ability to dynamically read Keyword files and intergrate it into the framework. This means that if you want to add or expand more keywords, you are allowed to do so. Keywords are python files in the "interlib" folder used to translate lines of Pseudo code to Python code. The "interlib" folder is required to actually run the Pseudo program successfully and it needs to be in the same directory as the program. Download it to try out the basic Keywords we implmeneted to get the general idea of using Pseudo.

For building the program yourself, it requires pyinstaller to build the binary in the console. The command to build it is: pyinstaller.exe --windowed --noconsole --onefile --name="Pseudo" gui.py

  • Just note that pyinstaller does not work with python 3.8 yet. Python 3.7.x and lower should be supported.

The Python language that we are using to build Pseudo is not that bad of a language for getting your feet wet in the world of programming. It's very easy to learn and the libraries are simple enough to get your head around. That's why we are using Python. Once you are comfortable with Pseudo, you can read the source code and familarize yourself with the features it implements.

This project was inspired by a Minecraft Plugin called Skript that allowed players to develop Minecraft Plugins without learning how to write Java code or managing a plugin project. Its intuitive syntax of writing down English phrases to usable code in the game is the same idea that Pseudo will have for users who will be writing down Pseudo code.

Let's explain how we write down Pseudo code.


Each beginning word is a 'Keyword'. Keywords are commands that you tell the Pseudo program to execute. The basic ones are Create, the aritmetic operators (Add, Subtract, Multply, and Divide), and Display.

Create:

The Create keyword will create a variable with the values you specify. How you would write it is like so:

Create [a/an] <data type> named <variable name> with [a/an] (value/values) <value>

Now this might seem confusing at first, so let us try to decode what all this means.

  • Brackets []: Brackets mean that the words inside of them are OPTIONAL. This means that they can be omitted from the phrase and still be sucessfully executed.

  • Parentheses (): Parentheses mean that the words inside of them are MANDATORY, but you can only chose ONE of them. If you omit them from the phrase, the Pseudo interpreter will complain.

  • Slash /: What the slashes means is that you can choose any one of the options within [] or (), but you must ONLY chose one.

  • <data type> : Is an internal mechanism that Pseudo does to keep track of data. For now, the only valid s are variable, list, and table. More s will be implemented later.

  • "variable": A "variable" can contain a number or a piece of text (Technically, it can hold either an integer, float, or a string).

  • "list": A "list" is what you expect a list to be. A sequence of items in the order you put them in (More info on creating lists later).

  • "table": You can think of a "table" like an excel sheet. One entry of a table is used for one value (More info on creating tables later).

Side note: "list" and "table" can contain other "list" and "table" values as well.

  • <variable name>: This the name that will represent the data. This name is one word only, if you want to have two words for a variable name use underscores.

    • E.g: this variable is not a valid name, but this_variable is.
  • <value>: If the is a "variable", then the only data you can store are numbers and text. If the is a list, then you can store list values. If the is a table, then table values are valid.

  • number: This can be an integer or a rational number.

    • E.g: 1, 20, or 1.23212
  • text: These values must be inbetween quotation marks (can be single or double quotation marks).

    • E.g.: Both 'Text' or "Text" will be valid values for a text.
  • list: A valid list value is surrounded by brackets [] with comma separeted values.

    • E.g: [1, 2, "Text"]

Side note: The brackets for a list value are different from the brackets for the keywords. The brackets here are to differentiate from strings and tables so that they are directly parsed to python (When you translate your pseudo code, you'll see what we mean).

  • table: A valid table value is surrounded by braces {} with each entry separated by commas and a pair of values with colons inbetween.
    • E.g: { "A": 1, "B": 2, "C": 3 }

Let's try an example


Say you want to create a variable named x with a value. We would type into the input window in the GUI like so:

Create a variable named x with a value 1

Look at that! We just thought of what we wanted to do and then we just wrote it down in easy to understand english syntax. It's just that easy. Let's do it agian with more examples:

Create a variable named some_text with value "This is some text"

Create a variable named some_number with a value 10.2

Create a list named list_1 with values ["This", "is", "a", "list"]

Create a table named table_1 with a values {"Entry_1": 1, "Entry_2": 2}

Create table named table_2 with value {"List": list_1, "Table:": table_1}

  • This table will contain a list and a table inside of it

Add and Multiply: This will allow you to add or multiply either numbers or variables that contain numbers together and store the result into a variable. Both of the keyword's syntax are:

(Add/Multiply) (<variable name>/<number>) and (<variable name>/<number>), store [it/the result] into <variable name>

If you want to add two numbers, you can do it like so (given that you already created the variable to store it in.)

Create a variable named x with a value 0 Add 1 and 2, store the result into x

This will mean that x will hold the value 3. You can also mix variables and numbers together like so:

Create a variable named x with a value 2 Multiply x and 10, store it into x

This will update x to be 20. The evaluation of the result will happen first, and then storing the result will happen after.

Subtract: This syntax is very similar to the Add and Multiply syntax. Only one word is changed:

Subtract (<variable name>/<number>) from (<variable name>/<number>), store [it/the result] into <variable name>

How the subtraction is handled is that the first (/) will be taken from the second (/). For example:

Create a variable named x with a value 0 Subtract 1 from 2, store it into x

If we were to write this in an equation format, it would look like this: 2 - 1 = x

Divide: This syntax is very similar to the Add and Multiply syntax. Only one word is changed:

Divide (<variable name>/<number>) by (<variable name>/<number>), store [it/the result] into <variable name>

The divide statement is very similar to how fraction division looks like.

Create a variable named x with a value 0 Divide 20 by 10, store into x

In an equation it'll look like this: 20 / 10 = x

Display: This keyword will display things out to the output section of Pseudo (If running the interpreter through the console, then it would output things to the console. If you are using the GUI, then otuput to the GUI). Its syntax is:

Display (<variable name>/<text>)[, (<variable name>/<text>)][, (<variable name>/<text>)][...]

What the syntax represents are comma separated values with a variable or text at each value. So let's say we want to display our result of the addition between two numbers. We would do it like so:

Create a variable named result with value 0 Add 1 and 2, store it into result Display result

This will display 3 to the output section of the console/GUI. If you want to display multiple pieces of text to the output, then you would do it like so:

Create a variable named world with a value "World" Display "Hello ", world, "!"

Remember that any text value needs to have quotation marks surrounding the text you want to print out.

With this knowledge of how Pseudo works, you can now begin to code your frist "Hello World" program!

HELLO WORLD


This is pretty easy. All Pseudo code needs to be written to the test.pseudo file (there are already some preloaded pseudo code in there for testing purposes, but feel free to look and delete everything if you want to). Knowing that you can display text to the console/GUI with the "Display" keyword you can do it like so:

Display "Hello World"

Run the interpreter program and you should see your console/GUI output the text. The interpreter also writes the output to a file called output.txt Actually, the interpreter writes the output to the output.txt file first, then the interpreter reads the output.txt file and prints it to the console. And that's not all, all of your Pseudo code gets translated into Python code as well. You can view the equivalent code in a file called outfile.py. Just open it with a text editor (like notepad) and you can see what each line of code is equivalent to. Just ignore the 'if __name__ == "__main__": ' part since that is required by python to start the code.

pseudo's People

Contributors

d-programming-man avatar dgmerek avatar dbaru avatar marlongregorio avatar stresend avatar

Stargazers

Kloe avatar

Watchers

 avatar  avatar  avatar

pseudo's Issues

Odd Timings

On rare occasions, the "Live Update" feature does not update the code when a user is done writing down code in the input box.

Not sure if this is fixable since we would have to check if the user has stopped writing code down when the GUI is interpreting, meaning that we will need to check for that in the interpret() function.

This isn't really a high order issue, so I don't mind if we leave this alone for now.

Live Updating on scroll bug

Currently when Live Update is enabled every action scrolling the input window will also update it. This might be an issue with the method for detecting updates being too broad but I'm not sure.

If we want this to be a feature feel free to close this issue.

Cannot distinguish between list and table

The "Create" keyword cannot distinguish between list and table data types.
Looking at the how we are determining what is a table and a list though, I think from the very beginning I had the wrong idea of how we should interpret list and tables. The "Create" keyword might need a whole new rework.

The point of the Create keyword, in respects to list and tables, is that we can let python evaluate if the list or table is valid instead of letting the keyword validate it. So what needs to happen is that we can just lazily check if the last character is of the matching type and assume that it is a valid list or table. In some sense, we don't need to add anything to the "value" key, we just only need the "data_type".

"Create" keyword cannot parse float values

When using the "Create" keyword and assign a float value to a variable name, the interpreter will create an error exception. For example:

Create a variable named x with a value 1.1

It thinks that the float value is a variable rather than an actual number. I have a hint on what is causing the interpreter to raise that exception so I'll get on to that fix.

Copy-Paste bug

Copy and pasting text into the pseudo causes a runtime error.

Execute Bug

Pressing "execute" doesn't interpret the code and prints new changes until the second execute call.

Initialize a variable to be 0

"Create a variable named x with a value 0"

It seems like when any variable that has its value initialized to 0 does not correctly parse that line and so the python file does not print any line after that statement. Will fix this.

Making a pseudo into a comment and then turning it back into Pseudo code doesn't correct highlight

For example: Make a pseudo statement

Create a variable named x with a value 1

Turn it into a comment, making the whole line green

# Create a variable named x with a value 1

Then turning it back into a pseudo code:

Create a variable named x with a value 1

But then the code statement is still highlighted green, even when translating
It only corrects its color when reloading the pseudo file.

Live Update doesn't seem to update to the most recent error

When using the live update feature, it will only output errors from the previous state of the input text box.
For example: If we have something like this:

Create 

The line of the pseudo code will display it as:

Line ##: Create

But when you update that line with this:

Create a

The same error message will appear:

Line ##: Create

But if we update it again with this line:

Create a variable

It would now display this error line:

Line ##: Create a

This is the previous error message we should've gotten from the past input box state. I'm thinking that it has something to do with the changed state of the input box when the threading.Timer thread joins back to the main thread. I'll have to keep out for this.

Import functions not from import file

When having more than 2 levels of imports will get the functions from those import levels, eg:

### main.pseudo
import helper
Run function test

### helper.pseudo
import helper2
Define function test:
  Display "Hello"

### helper2.pseudo
Define function test2:
  Display "World"

But when translating the main.pseudo file to python:

### main.py
from helper import test
from helper import test2
if __name__ == "__main__":
  test()

Clearly, the function test2 does not belong into the helper.pseudo file, but is imported like it was. Look at the import.py file and the utility.py file for insight on how to solve this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.