Giter Club home page Giter Club logo

spl's Introduction

SPL - Simple Programming Language

image

Introduction

SPL is an interpreted programming language (which requires interpreter software to run), the language was made to be extremely simple, containing the minimum necessary to be called a programming language (if it can be called, lol).

Hello World

Of course every language must start with the good old Hello World, you can do this in SPL with the following line:

print "Hello World!";

Very simple!

The language

As it was designed to be extremely simple, it only contains a few basic functions. Examples:

  • PRINT: Used to print a string or value on the screen
  • SET: Used to define variables
  • WAIT: Pauses the program temporarily until the user presses enter

More functions can be found in the documentation.

The Interpreter

SPL Interpreter works something like this: You have an spl file, which is nothing more than a text file. This file will be read as a string by the interpreter, which will do the following:

First it will separate the source code into several blocks separated by ;, each block of which is an instruction. Instructions are commands that you pass to the interpreter.

Then, it will separate these instructions by Tokens, which are "words", each token is responsible for something. Examples of tokens are: PRINT, SUM, SET, EQUALS, etc.

The interpreter will analyze these tokens and see if the source code token combinations make sense, if they do then it will execute the provided instructions. If the user has made an error, SPL Interpreter will print an error message on the screen (At the moment, the messages are very generic, and it is not possible to see exactly the line in which the error was generated)

Documentation

Arithmetic Operations

The language supports the following arithmetic operations:

  • sum: Adds two or more numbers. Example: sum 1 2; (adds 1 and 2)
  • sub: Subtracts two or more numbers. Example: sub 10 5; (subtracts 5 from 10)
  • mult: Multiplies two or more numbers. Example: mult 3 4; (multiplies 3 and 4)
  • div: Divides two numbers. Example: div 10 2; (divides 10 by 2)

Boolean Operations

The language supports the equals operation, which checks if two values are equal. Example: equals 10 10; (checks if 10 is equal to 10)

Variable Assignments

You can assign values to variables using the set command. Example: set x 10; (assigns the value 10 to the variable x)

Printing Values

You can print values using the print command. Example: print x; (prints the value of the variable x)

Comments

You can add comments to your code using the // syntax. Anything after // on a line will be ignored by the interpreter. Example: sum 1 2; // This is a comment

More examples can be found in the samples folder!

Notes

It's worth saying that I built this interpreter in a few hours, and when I started building it it was 1 am and I didn't feel like going to sleep, I implemented some things and when I saw it it was already 3 am, so I decided to go sleep and then create the repository on GitHub. The code is a bit messy and needs refactoring, I'll probably write a real language some other time, feel free to modify the code though!

spl's People

Contributors

lukazof avatar

Stargazers

 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.