GithubHelp home page GithubHelp logo

marcel-to / verse-interpreter-in-python Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 64.67 MB

This repository contains an interpreter for the upcoming Verse programming language.

License: MIT License

Python 100.00%

verse-interpreter-in-python's Introduction

Verse Interpreter: Exploring the Future of Programming with Python

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.

About Verse

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.

Verse Source

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.

Getting Started

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.

What Verse Features are covered in the Interpreter?

  • Integers​
  • Arithmetic Calculations
  • Tuples/Arrays​
  • Choice​
  • Functions​
  • If Statements​
  • For-loop​
  • Unification​
  • Strings​
  • Own Datatypes

Implementation of Verse Code

To bring into Scope

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;

Set a Value

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

To Bind a Value

With the help of binding, it is possible to scope and set a value at the same time.

    x:=3

Tuples / Array

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)

Choices

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

Functions

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)

If Statements

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

For loop

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?} -> ()

String

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")

Own Data Structures

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)

Structure

The structure of the interpreter involves multiple components working together to process and execute code.

Token

Tokens represent reserved characters or strings. These have certain information about what it represents. Each token has two different values:

  • Name of the token
  • Value TokenTypes

Lexer

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.

Parser

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).

Interpreter

Now the interpreter can visit through the abstract syntax tree and validates for semantic correctness. Afterwards it returns the value.

Execution

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: main.py script

  • Second, using the Verse Console: Here you can enter verse code like a command tool: console script

  • 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.

Test Cases

The File Verse Interpreter Test contains many test cases regarding the different features.

Contributers

License

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.

verse-interpreter-in-python's People

Contributors

marcel-to avatar kariyampalli avatar

Stargazers

Cruz Wootten avatar Benjamin BOGNER avatar Cortana avatar Robert Jacobson avatar

Watchers

 avatar

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.