Pseudo is a programming language inspired by the specification outlined here: https://www.ocr.org.uk/Images/260952-pseudocode-guide.pdf.
It runs on the JVM, and you will soon be able to create a standalone jar from your source code. For now, Pseudo compiles to its own archive format (.psa
), which must be executed using the Pseudo CLI.
In order to build Pseudo, simply clone the project, import it as a gradle project into your preferred IDE, run the generateGrammarSource
task, and finally the build
task.
There should now be an executable jar file in your build/libs
directory.
Here is a basic helloworld.psc
program:
print("Hello, world!")
To run this program, we can do:
java -jar pseudo.jar compile helloworld.psc --run
The compile
command will build a helloworld.psa
archive, and the --run
option tells Pseudo that we would also like to execute the program.
Precompiled archives can be executed using:
java -jar pseudo.jar run helloworld.psa
For more detailed examples, refer to the examples folder of this repository.
- If and switch statements (see selection.psc)
- For, while, and do-until loops (see loops.psc)
- Functions:
function triple(x)
return x*3
endfunction
print(triple(12))
- Classes and inheritance (see classes.psc)
- Arrays and lists (see arrays.psc and lists.psc)
- Console I/O:
print("Hello!")
name = input("What is your name? ")
- File I/O (see files.psc)
- Global variables:
global x = 10
function test()
print(x)
endfunction
test()
- Comments:
print("Hello!") // Greet the user
- Ternary expressions
print(if a > b then a else b)
- A wide range of mathematical and logical operators (refer to the specification)
Pseudo's parser and lexer are written in ANTLR, and the rest of the language is written in Kotlin.
It compiles to Java Bytecode (see JvmCompiler.kt), with the help of ObjectWeb's bytecode generation framework ASM and half-cambodian-hacker-man's Kotlin DSL Koffee.
If you would like to suggest a feature, or have found a bug, please don't hesitate to open an issue.
Pseudo uses BigDecimalUtil from javadev's "calc" for some mathematical operations, and it is included in this project as per the Apache 2.0 license.