Welcome to the Verse Interpreter repository! This is a project that showcases an interpreter written in Python for the upcoming Verse programming language. With this interpreter, you can delve into the unique features and capabilities of Verse, experiencing firsthand the potential it holds for the future of programming.
Verse is an upcoming programming language that promises to revolutionize the world of software development. Designed with simplicity, expressiveness, and performance in mind, Verse aims to provide developers with a fresh and powerful tool for crafting elegant and efficient code. With a focus on addressing modern development challenges, Verse offers a unique syntax, extensive standard library, and a range of advanced features to enable developers to build robust and scalable applications across various domains. By combining intuitive syntax with high-performance execution, Verse strives to enhance developer productivity and unlock new possibilities in the realm of programming.
The development of the Interpreter was driven by a careful selection of reliable and authoritative sources. Extensive research was conducted using language specifications, academic papers and the showcase of Verse in one of the Haskell Exchange conferences.
- The Verse Calculus: a Core Calculus for Functional LogicProgramming
- Beyond Functional Programming: The Verse Programming Language
You will need Python installed to run the Verse interpreter. Once set up, you can dive into the project's files and directories to understand the internals of the interpreter and find examples and documentation.
- Integers
- Arithmetic Calculations
- Tuples/Arrays
- Choice
- Functions
- If Statements
- For-loop
- Unification
- Strings
- Own Datatypes
The feature "to bring a variable into scope" in Verse allows for the explicit declaration or assignment of a variable within a specific block or context, making it accessible and usable within that particular scope.
x:int;
y,z:int;
It allows the user to declare a value to a specific variable that is already scoped.
x:int; x=3
y=4; y:int; y
Which means, if there is a value that is not getting scoped, during the execution, the interpreter will register it as fail and return false?
x=3
With the help of binding, it is possible to scope and set a value at the same time.
x:=3
The main structure of Verse is build around the tuple. It allows for a structured sequence of values inside a single variable.
x:=(1,2,3,4,5)
The feature of choices in Verse provides a powerful mechanism for decision-making within the code. It allows to define conditional branches based on different conditions, enabling the execution of specific code blocks based on the evaluation of these conditions.
x:=(1|2|3)
x:=(1|2|3); y:=(4|5|6); x + y
Verse also allows the use of declaring and calling functions like most common programming languages. The declaration itself is a bit unique though. To declare a Function it needs to be structured as follows:
IDENTIFIER(SCOPES):TYPE := (BLOCK)
==Block
==
: A Block stands in Verse for one or multiple expressions.
f(x:int,y:int):int := (x+y); f(2,3)
Every if
statement in Verse is followed by a then
and an else
statement. And besides the if
both resulting statements can contain a BLOCK
if(EXPRESSION) then EXPRESSION else EXPRESSION
if(EXPRESSION) then (BLOCK) else (BLOCK)
if(EXPRESSION) then {BLOCK} else {BLOCK}
if(x>0) then 1 else 0
The iterator defines a sequence or collection of elements to iterate over, while the loop variable holds the current element of each iteration. The loop body contains the code that is executed repeatedly for each element in the iterator until the iteration is complete.
for (BLOCK) do (BLOCK)
for {1..10} -> (1,2,3,4,5,5,6,7,8,9,10)
for {3|4} -> (3,4)
for {false?} -> ()
This feature is not actually presented during the conference, neither is it described in the Verse Calculus. But this interpreter uses the information gathered regarding variables and allows the use of strings.
x:="Hello World"
x:=("Hello"|"World")
Another feature that is not actually described in the papers, nor talked about in the conferencei is the own data types. Most common programming languages allow the use of custom structures defined and called inside of a program. Take Haskell for example:
data Rectangle = Rectangle
{
width :: Int,
height :: Int
}
Our implementation takes a similar approach and combines the haskell declaration with the Verse function declaration. It is basically a function declaration with a data infront.
data Rectangle(width:int,height:int); rec := Rectangle(7,3); rec.width | rec.height
-> (7|3)
The structure of the interpreter involves multiple components working together to process and execute code.
Tokens represent reserved characters or strings. These have certain information about what it represents. Each token has two different values:
The lexer is the first component in the interpreter structure. Its main task is to break the source code into a set of tokens that can be understood by the interpreter.
The parser is exclusively responsible for syntax analysis and follows the predefined grammar (that was derived from the paper) for this purpose. After the syntax analysis the parser generates an "Abstract Snytax Tree" (AST).
Now the interpreter can visit through the abstract syntax tree and validates for semantic correctness. Afterwards it returns the value.
There are 2 files for executing verse code or the corresponding executables.
-
First the verse_input.py script file: this file allows the user to manipulate the variable
text
and change its string content to the desired verse code: -
Second, using the Verse Console: Here you can enter verse code like a command tool:
-
Inside the Executable Directory you find 2 executables for either Windows and MacOS. Running them opens up a command console with the running script. The usability of the .EXE is the same as the Verse Console file.
The File Verse Interpreter Test contains many test cases regarding the different features.
This project is licensed under the MIT License. Feel free to use, modify, and distribute the code in accordance with the terms of the license.