A minimal viable programming language on top of liblgpp

Related tags

Miscellaneous alang
Overview

This project aims to implement a minimal viable programming language on top of liblgpp.

setup

The project requires a C++17 compiler, CMake and liblgpp to build.

$ git clone https://github.com/codr7/alang.git
$ cd alang
$ mkdir build
$ cd build
$ cmake ..
$ make
$ ./alang
Alang v0.3

Press Return on empty line to eval.
Empty eval clears stack and Ctrl+D exits.

: let fib sub(
  if (cp .< 2) _ (
    + (.- 1 cp recall)
      (sw .- 1 recall)
  )
)
      
[]
: fib(20)
 
[6765]

design

The language works more or less like a Forth, with a few minor syntactic additions.

Prefixing an identifier with a . allows it to be used infix, ie. the target will take it's first argument from the stack.

Suffixing an identifier with an argument list allows specifying arguments explicitly inline, passing _ as parameter splices a value from the stack.

The point is not that Forth is better than any other language, it's just the lowest common denominator I've found; on top of this you can build pretty much any kind of language and still reuse most of the foundation.

: + 1 2

[3]
: 1 .+ 2

[3 3]
: 5 -(_ 2)

[3 3 3]

stacks

The stack may be manipulated directly.

: 1 2 3

[1 2 3]
: sw

[1 3 2]
: cp

[1 3 2 2]
: rot

[1 2 2 3]
: d

[1 2 2]

Additional stacks may be created by enclosing any expresssion in brackets.

: [1 2 .+ 3]

[[1 5]]

conditions

=, < and > may be used to compare values.

: 42 .= 42

[T]

: 1 .> 2

[T F]

or returns its first truthy argument, or the last argument if none.

: F .or 0 .or 42
 
[42]

and returns its first falsey argument, or the last argument if none.

: T .and 0 .and 42
 
[0]

if may be used to branch on any value.

: if 0 _ F
 
[F]
: if 42 T _

[F T]
: if [] _ F
 
[F T F]
: if [42] T _
 
[F T F T]

types

Types are first class.

type may be used to get the type of any value.

: 42 .type

[Int]
: .type

[Meta]

: .type

[Meta]

isa returns T if the first argument is derived from the second, F otherwise.

: Int .isa Stack

[F]
: Int .isa Num

[F T]

bindings

Bindings may be created using let.

: let foo 42

[]
: foo

[42]

Bindings are evaluated at compile time.

: 42 let foo _

Error: Stack is empty
[]

@ may be used to evaluate any expression at compile time.

: @42 let foo _

[]
: foo

[42]

subroutines

Subroutines are first class, may be defined using sub and called by suffixing their names with an argument list.

: let foo sub(42)

[]

: foo

[(Sub 0x7fa911d04530)]

: d foo()
 
[42]

io

say may be used to print any value to standard output.

: say(42)
 
42
[]
You might also like...
Metal lathe electronic lead screw project built on top of Russian-speaking DigitalFeed ELS system by Oleg A. and contributors from ChipMaker.ru
Metal lathe electronic lead screw project built on top of Russian-speaking DigitalFeed ELS system by Oleg A. and contributors from ChipMaker.ru

This software and instructions are provided as is, without warranty of any kind. This is a hobby project. Using this might damage your equipment, caus

A pre-boot execution environment for Apple boards built on top of checkra1n

archOS A pre-boot execution environment for Apple boards built on top of checkra1n - currently based off the Checkra1n/PongoOS Repo. Building on macOS

This is a template project showing how to implement an application protocol on top of the MetaProtocol.

Manage any protocols in Istio service meshes with MetaProtocol and Aeraki! meta-protocol-awesomerpc This is a template project showing how to implemen

C++11 provides chainable and iterable object for uniform die casts. Useful for statistics or table top RPG simulations.

12/1/2018 Due to feedback about compile-time limitations, the api has been changed since release. The api now supports user-defined literals which mak

This is a template project showing how to implement an application protocol on top of the MetaProtocol.

Manage any protocols in Istio service meshes with MetaProtocol and Aeraki! meta-protocol-awesomerpc This is a template project showing how to implemen

Open source Splatoon 2 save editor for the Nintendo Switch (NX) built on top of the effective-spoon project
Open source Splatoon 2 save editor for the Nintendo Switch (NX) built on top of the effective-spoon project

Open source Splatoon 2 save editor for the Nintendo Switch (NX) built on top of the effective-spoon project

RudeWindowFixer: fix Windows taskbar always-on-top issues
RudeWindowFixer: fix Windows taskbar always-on-top issues

RudeWindowFixer: fix Windows taskbar always-on-top issues Brought to you by Etienne Dechamps - GitHub If you are looking for executables, see the GitH

Competitive Programming - Programming👨‍💻  Questions on BinarySearch💻, LeetCode💻, CodeChef💻, Codeforces💻,DSA 450
Competitive Programming - Programming👨‍💻 Questions on BinarySearch💻, LeetCode💻, CodeChef💻, Codeforces💻,DSA 450

🔆 Hacktoberfest2021 🔆 This repository is open to all members of the GitHub community. Any member can contribute. Contribute according to the steps g

J is an array programming language

J: From C to C++20 J is an array programming language created by Ken Iverson and Roger Hui (see image below).

Owner
Andreas Nilsson
Andreas Nilsson
PLP Project Programming Language | Programming for projects and computer science and research on computer and programming.

PLPv2b PLP Project Programming Language Programming Language for projects and computer science and research on computer and programming. What is PLP L

PLP Language 5 Aug 20, 2022
StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that of JavaScript's and TypeScript's

StarkScript StarkScript - or the Stark programming language - is a compiled C-based programming language that aims to offer the same usability as that

EnderCommunity 5 May 10, 2022
jai programming language starter kit (minimal modules)

jai starter kit modules jai programming language starter kit (minimal modules) Modules List sk_Window : minimal window creation and input module. sk_B

null 4 Aug 16, 2022
jai programming language starter kit (minimal modules)

jai starter kit modules jai programming language starter kit (minimal modules) Modules List sk_Window : minimal window creation and input module. sk_B

null 1 Aug 20, 2022
frost is a programming language with a focus on low-friction systems programming.

❄️ frost frost programming language About frost is a programming language with a focus on low-friction systems programming.

null 4 Nov 12, 2021
The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.

Wren is a small, fast, class-based concurrent scripting language Think Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a fami

Wren 6.1k Dec 30, 2022
cdk is a minimal cross-platform c language development kit.

Overview cdk is a minimal cross-platform c language development kit. Requirement Based on c11 standard. Compile create a build directory under the cdk

Red 22 Dec 15, 2022
Freeze OS is a cross-platform operating system emulator that runs on top of an interpreter called the Freeze interpreter.

Freeze OS is a cross-platform operating system emulator that runs on top of an interpreter called the Freeze interpreter. The operating system code is basically written in the Freeze programming language that is passed to the Freeze interpreter. The idea is to skip instances where the operating system needs to handle low level operators and focus on higher level stuff, like malware analysis, AI, and others.

null 24 May 2, 2022
Had a tough time playing Microsoft Wordament ? Well WORDament_Solver has your back. It suggests you meaningful words you can use while playing the game and help you top the leaderboard.

WORDament_Solver Had a tough time playing Microsoft Wordament ? Well WORDament_Solver has your back. It suggests you meaningful words you can use whil

Tushar Agarwal 3 Aug 19, 2021
QOI image viewer on top of the Sokol headers

qoiview A simple .qoi image file viewer on top of the sokol headers. QOI: https://github.com/phoboslab/qoi Sokol: https://github.com/floooh/sokol WASM

Andre Weissflog 107 Dec 6, 2022