A simple Pascal interpreter written in rust.

Overview

rascal

A simple Pascal interpreter written in rust.

Usage

Download the latest rascal executable from the release page.

Run the executable.

rascal.exe <name-of-pascal-file>.pas

Features

Types and Variable Declarations

program exampleVariables;
var
    intOne, intTwo: integer;
    realOne, realTwo, realThree: real;
    stringOne, stringTwo: string;
    boolOne: boolean;
begin
    intOne := 5;
    realOne := 5.5;
    stringOne := 'foobar';
    boolOne := true;
end.

Functions and Procedures

program exampleProcedure;
    procedure printSum(a, b: integer);
    var
        sum: integer;
    begin
        sum := a + b;
        writeln(IntToString(a) + ' + ' + IntToString(b) + ' = ' + IntToString(sum));
    end
begin
    printSum(5, 10);
end.
program exampleFunction;
var
    mySum: integer;
    
    function sum(a, b: integer): integer;
    var
        sum: integer;
    begin
        sum := a + b;
    end
begin
    mySum := sum(5, 10);
end.

Control Flow

program exampleControlFlow;
begin
    if 20 = 5 then
        begin
            writeln('unreachable');
        end
    else if 5 + 7 < 30 then
        begin
            writeln('this will print');
        end
    else if not true then
        begin
            writeln('this will not print');
        end
    else if 20 <> 5 then
        begin
            writeln('<> means not equal');
        end
    else
        begin
            writeln('this will not print');
        end
end.

Expressions

program exampleExpressions;
var
    foo: integer;
    bar: real;
    baz: boolean;
begin
    foo := 5 * ( 7 - -2) div 5;
    bar := 5.5 * (7.0 - -2.5) / 10.0;
    baz := true and (true or false) and (10 < foo or 9 = foo); 
end.

BuiltIn Functions

program exampleBuiltIns;
var
    my_int: integer;
    my_real: real;
    my_string: string;
begin
    my_int := 5;
    my_string := IntToString(my_int);
    
    my_real := 5.5;
    my_string := RealToString(my_real);
    
    my_string := '5';
    my_int := StringToInt(my_string);
    
    my_string := '5.5';
    my_real := StringToReal(my_string);
    
    write('print without a newline');
    writeln('print with a newline');
    
    my_string := readln();
end.

Example Programs

hello world

program helloworld;
begin
    writeln('hello world!');
end.

fibonacci

note: This program is not very efficient. You should probably stick to integers less than 20.

program fibonacci;
var
    input: integer;
    
    function fib(n:integer): integer;
    var
        val: integer;
        return: integer;
    begin
        if (n <= 2) then
            begin
                val := 1;
            end
        else
            begin
                val := fib(n-1) + fib(n-2);
            end
        return := val;
    end
begin
    writeln('Welcome to fibonacci!');
    write('Please enter an integer: ');
    input := StringToInt(readln());
    writeln('fib of ' + IntToString(input) + ' is ' + IntToString(fib(input)));
end.

Resources

Pascal basic syntax can be read about here.

Bear in mind that this interpreter does not implement every feature of pascal.

You might also like...
A simple library to allow for easy use of python from rust.

Rustpy A simple library to allow for easy use of python from rust. Status Currently this library has not received much love (pull requests welcome for

Simple devcontainer for Rust + WASM development

Devcontainer WASM-Rust Simple devcontainer for Rust development Usage Github Codespaces Just click the button: Visual Studio Code Note this assumes th

Program analysis playground for a simple, imperative language
Program analysis playground for a simple, imperative language

Proggers Proggers is a program analysis playground for a simple, imperative language. Features Numerical analysis using abstract interpretation Type-c

A simple mandelbrot-computation.
A simple mandelbrot-computation.

Mandelbrot set We consider the sequence $z_{n+1} = z_n^2 + c$, with $z_0=0$, where $c$ is a complex number. The Mandelbrot set are all $c$ such that t

Ethereal - a general-purpose programming language that is designed to be fast and simple
Ethereal - a general-purpose programming language that is designed to be fast and simple

Ethereal is a general-purpose programming language that is designed to be fast and simple. Heavly inspired by Monkey and written in Rust

A simple code for checking crate 'prost' on WebAssembly (πŸ¦€ + πŸ•ΈοΈ = πŸ’–)

rust-wasm-prost This repository is a simple code for checking crate 'prost' on WebAssembly ( πŸ¦€ + πŸ•ΈοΈ = πŸ’– ). What is prost? prost is a Protocol Buffe

zzhack-cli is a Command Tool to help you quickly generate a WASM WebApp with simple configuration and zero code
zzhack-cli is a Command Tool to help you quickly generate a WASM WebApp with simple configuration and zero code

English | δΈ­ζ–‡ζ–‡ζ‘£ zzhack-cli is a Command Tool that can help you quickly generate a WASM WebApp with simple configuration and zero code. It's worth menti

A simple image uploader and caching/optimizing proxy

yeet (β•―Β°β–‘Β°)β•―οΈ΅ ┻━┻ yeet is an image caching and optimizing proxy, with support for uploading. I built it for ellie.wtf Upload images to S3 with curl Ca

Native Ruby extensions written in Rust

Ruru (Rust + Ruby) Native Ruby extensions in Rust Documentation Website Have you ever considered rewriting some parts of your slow Ruby application? J

Releases(v1.2.0)
Owner
null
RustPython - A Python Interpreter written in Rust

RustPython A Python-3 (CPython >= 3.9.0) Interpreter written in Rust ?? ?? ?? . Usage Check out our online demo running on WebAssembly. RustPython req

null 13.3k Jan 2, 2023
Rust bindings for the Python interpreter

PyO3 Rust bindings for Python. This includes running and interacting with Python code from a Rust binary, as well as writing native Python modules. Us

PyO3 7.2k Jan 4, 2023
Pyo3 - Rust bindings for the Python interpreter

PyO3 Rust bindings for Python, including tools for creating native Python extension modules. Running and interacting with Python code from a Rust bina

PyO3 7.2k Jan 2, 2023
Rust bindings for the Wasm spec interpreter.

wasm-spec-interpreter This project shows how to use ocaml-interop to call into the Wasm spec interpreter. There are several steps to making this work:

Bytecode Alliance 9 Aug 23, 2022
A memory safe Lua interpreter

Hematita Da Lua Hematita Da Lua is an interpreter for the scripting language Lua, written entirely in 100% safe Rust. Hematita is the portugese word f

Daniel 149 Dec 29, 2022
An interpreter for the esoteric programming language, Brainf*ck.

Brainf*ck Interpreter This is just a normal Brainf*ck interpreter written in Rust. If you don't know what Brainf*ck is, you can check out the wikipedi

Callum Irving 0 Dec 23, 2021
WebAssembly (Wasm) interpreter.

Continuous Integration Test Coverage Documentation Crates.io wasmi- WebAssembly (Wasm) Interpreter wasmi was conceived as a component of parity-ethere

Parity Technologies 1k Jan 4, 2023
Lisp interpreter that might be fast someday maybe?

ehlisp Pronunciation I'm not really sure. Maybe like an incorrect pronunciation of "ellipse", like "ellisp"? Also maybe like "a lisp". I named it this

Eddie Hatfield 3 Oct 6, 2022
A simple programming language made for scripting inspired on rust and javascript.

FnXY Programming Language Quick move: CONTRIBUTING | LICENSE What? FnXY is a simple programming language made for scripting inspired on rust and javas

null 2 Nov 27, 2021
πŸš€ Fast and simple Node.js version manager, built in Rust

Fast Node Manager (fnm) ?? Fast and simple Node.js version manager, built in Rust Features ?? Cross-platform support (macOS, Windows, Linux) ✨ Single

Gal Schlezinger 9.8k Jan 2, 2023