All Projects → hijkzzz → Mini Interpreter

hijkzzz / Mini Interpreter

A Simple Scripting Language

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Mini Interpreter

Red
Red is a next-generation programming language strongly inspired by Rebol, but with a broader field of usage thanks to its native-code compiler, from system programming to high-level scripting and cross-platform reactive GUI, while providing modern support for concurrency, all in a zero-install, zero-config, single 1MB file!
Stars: ✭ 4,725 (+6462.5%)
Mutual labels:  compiler, interpreter
Cfl
a Compileable statically typed Functional programming Language
Stars: ✭ 7 (-90.28%)
Mutual labels:  compiler, interpreter
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (+686.11%)
Mutual labels:  compiler, interpreter
Enso
Hybrid visual and textual functional programming.
Stars: ✭ 5,238 (+7175%)
Mutual labels:  compiler, interpreter
Cymbal
Yet another Rust implementation of the Monkey language from "Writing an Interpreter in Go" and "Writing a Compiler in Go"
Stars: ✭ 49 (-31.94%)
Mutual labels:  compiler, interpreter
Ph7
An Embedded Implementation of PHP (C Library)
Stars: ✭ 422 (+486.11%)
Mutual labels:  compiler, interpreter
Bic
A C interpreter and API explorer.
Stars: ✭ 719 (+898.61%)
Mutual labels:  compiler, interpreter
Umka Lang
Umka: a statically typed embeddable scripting language
Stars: ✭ 308 (+327.78%)
Mutual labels:  compiler, interpreter
U6a
Implementation of Unlambda, an esoteric programming language.
Stars: ✭ 46 (-36.11%)
Mutual labels:  compiler, interpreter
Antlr4 Calculator
Simple antlr4 calculator.
Stars: ✭ 40 (-44.44%)
Mutual labels:  compiler, interpreter
Passerine
A small extensible programming language designed for concise expression with little code.
Stars: ✭ 341 (+373.61%)
Mutual labels:  compiler, interpreter
Tiny Lisp
A tiny lisp compiler written in JS
Stars: ✭ 58 (-19.44%)
Mutual labels:  compiler, interpreter
V8
The official mirror of the V8 Git repository
Stars: ✭ 18,808 (+26022.22%)
Mutual labels:  compiler, interpreter
Renjin
JVM-based interpreter for the R language for the statistical analysis.
Stars: ✭ 466 (+547.22%)
Mutual labels:  compiler, interpreter
Craftinginterpreters
Repository for the book "Crafting Interpreters"
Stars: ✭ 4,298 (+5869.44%)
Mutual labels:  compiler, interpreter
Tiny Compiler
A tiny evaluator and compiler of arithmetic expressions.
Stars: ✭ 680 (+844.44%)
Mutual labels:  compiler, interpreter
Lbforth
Self-hosting metacompiled Forth, bootstrapping from a few lines of C; targets Linux, Windows, ARM, RISC-V, 68000, PDP-11, asm.js.
Stars: ✭ 293 (+306.94%)
Mutual labels:  compiler, interpreter
Enso Archive
Looking for Enso, the visual programming language? ➡️ https://github.com/enso-org/enso
Stars: ✭ 305 (+323.61%)
Mutual labels:  compiler, interpreter
Rascal
A simple Pascal interpreter written in rust.
Stars: ✭ 38 (-47.22%)
Mutual labels:  compiler, interpreter
Mir
A light-weight JIT compiler based on MIR (Medium Internal Representation)
Stars: ✭ 1,075 (+1393.06%)
Mutual labels:  compiler, interpreter

stone

A Scripting Language based on Golang

Specification

Types

comments		Comments are ignored by the interpreter
				// ...

int				The set of all signed 32-bit integers (-2147483648 to 2147483647)
				i = 123

string				A string type represents the set of string values
				s = "HelloWorld"

function 			A function type denotes the set of all functions with the same parameter and result types
				The return value is the result of the last statement
				
				add = func(a, b) { a + b } [ Anonymous function ]
				
				def max (a, b) {
                			if a > b {
                    				a
                			} else {
                    				b
                			}
				}

array				An array is a numbered sequence of elements of a single type
				a = [1, 2, 3, 4, 5]

object				See "Object Oriented Programming"

Operators

+				A string can be added to an integer and returned as a string
				"HelloWorld" + 123 == "HelloWorld123"
				
-				Only integer types are supported
*				Only integer types are supported
/				Only integer types are supported
>				Only integer types are supported
<				Only integer types are supported

==				Returns true if the variable name points to the same object
                		If operands are the basic data type, it depends on whether the values are equal or not

=				Initialize the variable

Statements

if				if a > b {
  					max = a
				} else {
                  			max = b
				}

while				while a > b {
  					print "HelloWorld!"
				}

Clousure

def add(c) {
	func(x) {c + x}
}

c1 = add(1)
print(c1(2))
print("\n")
print(c1(1))

Output:
3
4

Parameter Passing

The base data type is passed as a value
Arrays and objects are passed as references

Object Oriented Programming

class			def Animal {
				age = 0
				def getAge {
                    			"Animal age = " + age
				}
			}
				
			def Dog extends Animal {
                		sex = "girl"
                		def getAge {
                    			"Dog age == " + age
                		}
                		def getSex {
                    			"Dog sex == " + sex
                		}
			}
				
			d = Dog.new
			d.sex = "boy"
			print(d.getAge())
			print("\n")
			print(d.getSex())

			Output:
			"Dog age == 0"
			"Dog sex == boy"

Built-in functions

read() string				Read a word from terminal
print(any[any type]) int		Show "any" in terminal
size(s[string])	int			Return length of string
atoi(s[string]) int			Convert string to int
itoa(i[int]) string			Convert int to string
timestamp() int				Return UNIX timpstamp

Requirement

  • Golang

Build

cp -r stone $GOPATH/src
cd $GOPATH/src/stone
go build

Usage

./stone [source file name]

TODO

  • Virtual Machine

References

  • 两周自制脚本语言
  • The Go Programming Language
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].