# double-basic **Repository Path**: FingerBones/double-basic ## Basic Information - **Project Name**: double-basic - **Description**: 由Rust编写的简单解释器。 - **Primary Language**: Rust - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-11-18 - **Last Updated**: 2022-12-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # English This is a toy project to learn about the principles of compliers and the rust-lang. It is a simple interpreter for a simple language, called double basic here, since it is really basic. It only supports limited function, and is not intended to be used in any serious way. For example, it doesn't even support function calls. The grammars are as follows: 1. `variable_name : variable_type = expression;` 2. `variable_name = expression;` 3. `IF expression {...};` 4. `IF expression {...} ELSE {...};` 5. `WHILE expression {...};` 6. `PUT expression;` Be aware that every keywords are capitalized, and the semicolon is required at the end of every statement, including the ones end with a block. There are only two types STRING and NUMBER. The expression can be a variable, a number, a string, or a combination of them with operators. The operators are `+`, `-`, `*`, `/`, `==`, `!=`, `>`, `<`, `>=`, `<=`, `&&`, `||`, `!`, `(`, `)`, `|`. Notice that `|` is for catenating strings, and `!` is for negating a boolean value- the bool here follows as the C language- 0 for false and all else for true. Some of the codes are generated by Github Copilot, and mostly written by myself. This is just a toy project, and I don't intend to make it a real language- but if you have troubles learning principles of compliers, you can take a look at the code and see if it helps, since the codes are short- within 1000 lines, most of which are just if else and match statements. # 中文 这是一个学习编译原理和rust语言的玩具项目。它是一个简单的解释器,用于解释一个简单的语言,叫做double basic,因为它真的很基础。它功能很少。例如,它甚至不支持函数调用。 语法如下: 1. `变量名 : 类型 = 表达式;` 2. `变量名 = 表达式;` 3. `IF 表达式 {...};` 4. `IF 表达式 {...} ELSE {...};` 5. `WHILE 表达式 {...};` 6. `PUT 表达式;` 注意,所有关键字都是大写的,每个语句的结尾都需要分号,包括以块结尾的语句。 只有两种类型:字符串和数字。 表达式可以是变量,数字,字符串,或者它们的组合,使用运算符。运算符有`+`, `-`, `*`, `/`, `==`, `!=`, `>`, `<`, `>=`, `<=`, `&&`, `||`, `!`, `(`, `)`, `|`。注意,`|`是用于连接字符串的,`!`是用于否定布尔值的-布尔值遵循C语言的规则-0为假,其他为真。 一些代码是由Github Copilot生成的,大部分是我自己写的。 这只是一个玩具项目,我不打算把它变成一个真正的语言-但是如果你在学习编译原理时遇到了困难,你可以看看代码,看看它是否有帮助,因为代码很短-在1000行以内,大部分都是if else和match语句。 (中文由github copilot翻译,看着还不错就不自己写了,肯定是有机翻腔)