没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > zemscript |
zemscript
|
0 | 0 | 23 |
贡献者 | 讨论 | 代码提交 |
This project implements a simple script interpreter in Java. Its purpose is to provide a simple code base that is easy to understand and be used for learning basic techniques in writing an interpreter.
The project contains the following:
Hand written Lexer Parser that process tokens from the Lexer to check the syntax and generate an Abstract Syntax Tree An Interpreter that evaluates the abstract syntax tree by visiting the nodes. It also performs some semantic checking.
Here is an example script it successfully runs:
/*
* @author Cameron Zemek
*/
// This script is an example of a simple language.
// There are only three basic data types: numbers, strings, boolean
a_number = 3 ^ 2;
a_string = "hello";
a_bool = true;
// Operators
concat_string = "hello" ~ " " ~ "world.";
fav_string = 3 ~ " is my favourite number";
result_number = 1 + 2 - 1 * 5 / 3.2 + 2^2;
isEmail = true;
someOtherBoolean = false;
condition = isEmail && (len(a_string) > 0) || someOtherBoolean;
// if control flow
if (a_number < 3) {
println("number is less then 3");
} else if (a_number == 3) {
println("number is 3");
} else {
println("number is greater then 3");
}
// while loop
counter = 1;
length = 9;
while (counter <= end_number) {
array_push(result, number);
number = number + step;
}
return result;
};
// Calling functions
println(sum(range(1, 9)));