Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bosslang

A basic Python source-to-source compiler and interpreter for a Pascal-like language.

Usage

$ python exe.py source.boss
$ python -c "from exe import runsource; runsource('program test; begin end.')"

Description

exe.py breaks down the Bosslang source into an Abstract Syntax Tree (AST), reinterprets the output as a syntactically valid Python source and executes it.

Syntax

Program structure

PROGRAM NONAME00;
    VAR a : INTEGER;
BEGIN
    { just a comment }
    a := 1;
END.

Note: Reserved keywords are non-case-sensitive
Note: Variable and function names are alphameric

Supported types

  • int() and float() only
var x, y : integer;
var r : real;
  • Vectors and matrices also supported!
program matrix;
var mat : integer;
begin
    mat[0][0] := 1;
    mat[0][1] := 2;
    mat[1=1][1=0] := 3;
    mat[CALL(max, 0, 1)][CALL(pow, 1, 1)] := 4;
    CALL(print, mat[1]); { prints mat[1][0] -> 3 }
end.

Note: arrays and matrices have an indefinite size
Note: strings not supported
Note: type checking is ommited

Language constructs

  • if statements
if r <> 0 then begin
    if x = 0 then x := 1
    else x := -1;
end;
  • while loops
while x > 0 then begin
    CALL(print, x);
    x := x - 1;
end;

Operator precendence

Precedence Operator Description
1 [ ] Array subscripting
2 + - Unary plus/minus
3 * / DIV Multiplication, division, integer division
4 + - Binary plus/minus
5 = <> < <= > >= Relational operators
6 := Assignment

Todo: add logical expressions

Functions

returnval := CALL(<function_name> [, args...]);
  • Any builtin python or compiler-defined function is callable.

Note: user-defined functions not supported
Note: type incompatible functions return int(0)

About

ALGOL-like language compiler and interpreter.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages