# mathors/Stone-language

Two-week homemade scripting language with daily detailed notes and source code. If you feel good, you can give a Star.
Latest commit 3ac19c3 Dec 27, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
Code Dec 23, 2018
Eighteenth Day Dec 14, 2018
Eighth Day Dec 19, 2018
Eleventh Day Dec 22, 2018
Fifteenth Day Dec 14, 2018
Fifth Day Dec 15, 2018
First Day Dec 13, 2018
Fourteenth Day Dec 27, 2018
Fourth Day Dec 15, 2018
Nineteenth Day Dec 14, 2018
Ninth Day Dec 20, 2018
Second Day Dec 14, 2018
Seventh Day Dec 19, 2018
Sixteenth Day Dec 14, 2018
Sixth Day Dec 19, 2018
Tenth Day Dec 20, 2018
Third Day Dec 16, 2018
Thirteenth Day Dec 22, 2018
Twelfth Day Dec 22, 2018
README.md Dec 23, 2018

Welcome to pull request/fork/star, thanks~

Maybe you just finished compiling the principle, or not, but you want to make a programming language of your own, then look at this project is right, I will design a simple scripting language in 14 days.

## How To Use

First, download Stone.jar from the Code directory and import it into your IDE.

Then run the JavaRunner.java code in the chap14 package.

Stone language support function, like this

``````def fib(n) {
if n < 2 {
n
} else  {
fib(n - 1) + fib(n - 2)
}
}
fib 33
``````

Branches, loop statements are also essential

``````odd = 0
even = 0
i = 1
while i < 11 {
if i % 2 == 0 {
even = even + i
} else {
odd = odd + i
}
i = i + 1
}
even + odd
``````

Also supports object-oriented syntax, like this

``````class Position {
x = y = 0
def move(nx,ny) {
x = nx; y = ny
}
}
p = Position.new
p.move(3, 4)
p.x = 10
print p.x + p.y
``````

There are also many language-supported grammars in the Stone language, such as arrays, object inheritance, etc.

``````a = [2,3,4]
print a[1]
a[1] = "three"
print "a[1]: " + a[1]
b = [["one",1],["two",2]]
print b[1][0] + ": " + b[1][1]
``````
``````class Position {
x = y = 0
def move(nx,ny) {
x = nx; y = ny
}
}
class Pos3D extends Position {
z = 0
def set(nx,ny,nz) {
x = nx;y = ny;z = nz
}
}
p = Pos3D.new
p.move(3,4)
print p.x
p.set(5,6,7)
print p.z
``````

## Directory

### Part 1 Basics

#### First Day

Introduction to machine language, assembly language, language processor overview

#### Second Day

Design the Stone language to determine what grammar functions the Stone language needs

#### Third Day

Design a lexical analyzer to introduce methods for lexical analysis through regular expressions

#### Fourth Day

Explain the abstract syntax tree and express the syntax of the Stone language through BNF

#### Fifth Day

Create a grammar interpreter with a very simple parser combination sublibrary

#### Sixth Day

Design a very basic interpreter. The interpreter will be able to actually execute programs written in the Stone language

#### Seventh Day

Enhance the functionality of the interpreter so that it can execute functions in the program and support closure syntax

#### Eighth Day

Adding call support for static methods to the interpreter, enabling the Stone language to call static methods like the Java language

#### Ninth Day

New class and object syntax for the Stone language

#### Tenth Day

Add array functionality to the Stone language

### Part 2 Performance Optimization

#### Eleventh Day

Programs should not search for variable names each time they access variables, but should first search for previously assigned numbers to improve access performance.

#### Twelfth Day

Similarly, when a program calls a method of an object or references a field in it, it should not search its name directly, but search for the number. In addition, inline cache is added to the Stone language interpreter to further optimize performance.

#### Thirteenth Day

The Stone language interpreter also uses the mechanism of intermediate code interpretation (or virtual machine). The program written in the Stone language will be first converted to intermediate code (binary code), and the interpreter executes the converted intermediate code.

#### Fourteenth Day

Finally, to improve performance, the Stone language needs to support static data types and further optimize performance based on data types. When executing a Stone language program with a static data type, the compiler can first convert it to Java binary code and execute the program directly from the Java virtual machine. It also adds type checking to the compiler, checks for type errors before executing the program, and provides type prediction. In this way, even if the program does not explicitly declare the data type, the Stone language interpreter can speculate and specify the appropriate type.

### Part 3 Advanced (self-study)

#### Fifteenth Day

The Stone language lexer is implemented by Java's regular expression library, and will no longer be used this way to manually design a lexer. Specifically, here will introduce the string matching program design for regular expressions.

#### Sixteenth Day

The parser was previously implemented using a simple library of parser combinatorial sub-libraries. From now on, some basic algorithms for parsing will be introduced. Based on LL parsing, a simple parser will be designed by hand.

#### Seventeenth Day

Briefly introduce the internal structure of the parser combination sub-library, and analyze the source code of the library

#### Eighteenth Day

The Stone language interpreter is implemented using the GluonJ system, which allows the Java language to perform functions similar to the open class in the Ruby language. Here are some trivial considerations when using GluonJ.

#### Nineteenth Day

Introduce the advantages and disadvantages of using design patterns to implement abstract syntax trees, and compare them with GluonJ.

## TODO

I will modify the syntax of the Stone language to make it support Chinese scripting language, similar to easy language.

You can’t perform that action at this time.