From c282739c54c3568b6b2e928750333946b21c6e49 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Sat, 22 Jul 2023 10:42:57 +0800 Subject: 👻add something else MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/ltex.disabledRules.en-US.txt | 1 + .vscode/ltex.hiddenFalsePositives.en-US.txt | 5 + .vscode/settings.json | 3 + psi/exception.py | 0 psi/interpreter.py | 0 psi/lexer.py | 0 psi/mathmatics.py | 0 psi/parser.py | 0 psi/readme.md | 395 ++++++++++++++++++++++++++++ psi/type.py | 0 readme.md | 395 ---------------------------- readme.rst | 94 +++++++ 12 files changed, 498 insertions(+), 395 deletions(-) create mode 100644 .vscode/ltex.disabledRules.en-US.txt create mode 100644 .vscode/ltex.hiddenFalsePositives.en-US.txt create mode 100644 .vscode/settings.json create mode 100644 psi/exception.py create mode 100644 psi/interpreter.py create mode 100644 psi/lexer.py create mode 100644 psi/mathmatics.py create mode 100644 psi/parser.py create mode 100644 psi/readme.md create mode 100644 psi/type.py delete mode 100644 readme.md create mode 100644 readme.rst diff --git a/.vscode/ltex.disabledRules.en-US.txt b/.vscode/ltex.disabledRules.en-US.txt new file mode 100644 index 0000000..460aa2b --- /dev/null +++ b/.vscode/ltex.disabledRules.en-US.txt @@ -0,0 +1 @@ +MORFOLOGIK_RULE_EN_US diff --git a/.vscode/ltex.hiddenFalsePositives.en-US.txt b/.vscode/ltex.hiddenFalsePositives.en-US.txt new file mode 100644 index 0000000..8bd355f --- /dev/null +++ b/.vscode/ltex.hiddenFalsePositives.en-US.txt @@ -0,0 +1,5 @@ +{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q词法分析器(Lexer)模块*:这个模块的主要任务是将输入的源代码(字符串)转换为一个个的标记(Token)。例如,它可以将字符串 \"list colors = red, blue, green\" 转换为以下的标记序列:[LIST, IDENTIFIER, EQUALS, IDENTIFIER, COMMA, IDENTIFIER, COMMA, IDENTIFIER]。\\E$"} +{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q语法分析器(Parser)模块*:这个模块的主要任务是将Lexer模块生成的标记序列转换为一个抽象语法树(AST)。AST是一种树形数据结构,它以一种更接近于编程语言的语法结构来表示源代码。\\E$"} +{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q内置类型模块*:这个模块定义了psi语言的内置类型,如列表和字典。它应该提供一些函数,用于创建和操作这些类型的实例。\\E$"} +{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q执行环境模块*:这个模块定义了psi语言的执行环境,包括变量的作用域和生命周期等。它应该提供一些函数,用于在执行环境中定义和查找变量。\\E$"} +{"rule":"MORFOLOGIK_RULE_EN_US","sentence":"^\\Q解释器模块*:这个模块的主要任务是遍历AST,并在执行环境中执行相应的操作。\\E$"} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a7d0fc7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "esbonio.sphinx.confDir": "" +} \ No newline at end of file diff --git a/psi/exception.py b/psi/exception.py new file mode 100644 index 0000000..e69de29 diff --git a/psi/interpreter.py b/psi/interpreter.py new file mode 100644 index 0000000..e69de29 diff --git a/psi/lexer.py b/psi/lexer.py new file mode 100644 index 0000000..e69de29 diff --git a/psi/mathmatics.py b/psi/mathmatics.py new file mode 100644 index 0000000..e69de29 diff --git a/psi/parser.py b/psi/parser.py new file mode 100644 index 0000000..e69de29 diff --git a/psi/readme.md b/psi/readme.md new file mode 100644 index 0000000..9264857 --- /dev/null +++ b/psi/readme.md @@ -0,0 +1,395 @@ +# psi + +*** + +- [ ] 模块导入 + +我们可以使用 "import" 和 "export" 命令来实现模块化 + +import: module_name +export: function_name + +*** + +- [ ] 循环结构 + +可以使用 "loop" 命令来创建循环,然后使用数字来指定循环的次数。 + +loop 5: reply: "你好" + +添加 `break` 和 `continue` 命令,以便在需要时跳出循环或跳过当前迭代。 + +`loop 5: ? i == 3: break` + +*** + +- [ ] 选择结构 + +用"?"代替if,用"!"代替else。 + +? x == y: x += 1 +! y += 1 + +*** + +- [ ] 函数定义 + +使用def关键字定义函数,再用函数本身调用。 + +def greet(name): reply: Hello, {name}! +greet: baimianxiao + +*** + +- [ ] 类型定义 + +定义列表和字典 + +list colors = red, blue, green +dict person = name: baimianxiao, age: 18 + +*** + +- [ ] 错误处理 + +使用try…catch… + +try: riskyOperation +catch: reply: 这是错误处理 + +*** + +- [ ] 并行执行 + +使用&开启线程 + +task1 & task2: reply: 两个任务执行 ing + +*** + +- [ ] 延迟执行 + +使用~<秒数>延迟进程 + +~5: reply: 延迟五秒回复 + +*** + +- [ ] 条件执行 + +|这个是条件执行,前面执行失败才会执行后面 + +riskyOperation | reply: 执行失败 + +*** + +- [ ] 导入包 + +使用import关键字 + +import: extraFeatures + +*** + +- [ ] 注释语句 + +单行注释#,多行"""...""" + +# 这是一条注释 + +""" +多行 +注释 +""" + +*** + +- [ ] 数据流 + +我们可以使用 ">>" 和 "<<" 符号来表示数据流 + +input >> process >> output + +*** + +- [ ] 事件监听 + +然后我们可以使用 "@" 符号来表示事件监听 + +@newMessage: reply: 一条新消息 + +*** + +- [ ] 模式匹配 + +我们可以使用 "~=" 符号来进行模式匹配 + +? message ~= "hello*": reply: 你好 + +*** + +- [ ] 断言 + +我们可以使用 "assert" 命令来进行断言 + +assert answer = correct: reply: Correct answer! + +*** + +- [ ] 重复执行 + +*3: reply: 重复三次 + +*** + +- [ ] 别名 + +alias r := reply +r: 这是一个别名 + +*** + +- [ ] 模块版本 + +在导入模块时,我们可以添加一个可选的版本号,以确保我们使用的是正确的模块版本。 + +`import: module_name@1.0.0` + +*** + +- [ ] 函数参数 + +在函数定义中,我们可以添加对默认参数和可变参数的支持 + +`def greet(name = "World"): reply: Hello, {name}!` + +*** + +- [ ] 列表和字典操作 + +我们可以添加一些命令来操作列表和字典 + +`push`, `pop`, `get`, `set` 等 + +*** + +- [ ] 错误类型 + +在错误处理中,我们可以添加对不同错误类型的支持,以便进行更精细的错误处理。 + +`try: riskyOperation catch ValueError: reply: 这是一个值错误` + +*** + +- [ ]并行控制 + +在并行执行中,我们可以添加一些命令来控制并行任务,例如 `wait`, `cancel` 等。 + +*** + +- [ ] 时间操作 + +我们可以添加一些命令来操作时间,例如 `now`, `addDays`, `format` 等。 + +*** + +- [ ] 文件操作 + +我们可以添加一些命令来操作文件,例如 `read`, `write`, `delete` 等。 + +*** + +- [ ] 网络操作 + +我们可以添加一些命令来进行网络操作,例如 `get`, `post`, `download` 等。 + +*** + +- [ ] 数据库操作 + +我们可以添加一些命令来操作数据库,例如 `select`, `insert`, `update`, `delete` 等。 + +*** + +- [ ] 字符串操作 + +我们可以添加一些命令来操作字符串,例如 `concat`, `substring`, `replace` 等。 + +`concat: "Hello, ", name` + +*** + +- [ ] 数学运算 + + +我们可以添加一些命令来进行数学运算,例如 `add`, `subtract`, `multiply`, `divide` 等。 + +`add: x, y` + +*** + +**逻辑运算**:我们可以添加一些命令来进行逻辑运算,例如 `and`, `or`, `not` 等。例如:`? x > 0 and y > 0: reply: Both numbers are positive`。 + +4. **类型转换**:我们可以添加一些命令来进行类型转换,例如 `toInt`, `toFloat`, `toString` 等。例如:`toInt: "123"`。 + +5. **正则表达式**:我们可以添加一些命令来使用正则表达式,例如 `match`, `search`, `replace` 等。例如:`? message match "^hello": reply: Hello!`。 + +6. **排序和过滤**:我们可以添加一些命令来排序和过滤列表,例如 `sort`, `filter` 等。例如:`sort: numbers, desc`。 + +7. **范围操作**:我们可以添加一些命令来创建和操作范围,例如 `range`, `in` 等。例如:`range: 1, 10`。 + +8. **异步操作**:我们可以添加一些命令来进行异步操作,例如 `async`, `await` 等。例如:`async: longRunningTask`。 + +9. **环境变量**:我们可以添加一些命令来获取和设置环境变量,例如 `getEnv`, `setEnv` 等。例如:`getEnv: "PATH"`。 + +10. **调试工具**:我们可以添加一些命令来进行调试,例如 `log`, `debug`, `trace` 等。例如:`log: "Starting task"`。 + +这些都只是一些初步的想法,实际的设计可能需要更多的考虑和测试。但我相信,通过不断的迭代和优化,我们可以创建一个强大而易用的脚本语言。 + +No relevant search results found. + +很高兴看到你对这个项目的热情!让我们继续探索更多的可能性: + +1. **模块别名**:在导入模块时,我们可以添加一个可选的别名,以便在代码中更方便地引用。例如:`import: complex_module as cm`。 + +2. **枚举类型**:我们可以添加对枚举类型的支持,以便更好地表示一组固定的值。例如:`enum Color = Red, Green, Blue`。 + +3. **元组和集合**:我们可以添加对元组和集合的支持,以便处理更复杂的数据结构。例如:`tuple point = (1, 2)`, `set numbers = 1, 2, 3`。 + +4. **生成器和迭代器**:我们可以添加对生成器和迭代器的支持,以便更高效地处理大量数据。例如:`def numbers(): yield 1, yield 2, yield 3`。 + +5. **装饰器**:我们可以添加对装饰器的支持,以便更方便地修改函数的行为。例如:`@log def greet(name): reply: Hello, {name}!`。 + +6. **上下文管理**:我们可以添加对上下文管理的支持,以便更好地处理资源的分配和释放。例如:`with open("file.txt") as f: reply: {f.read()}`。 + +7. **元编程**:我们可以添加对元编程的支持,以便在运行时动态地创建或修改代码。例如:`def make_greet(name): return def(): reply: Hello, {name}!`。 + +8. **并发和同步**:我们可以添加对并发和同步的支持,以便更好地处理多线程和多进程。例如:`lock l: l.acquire(), doSomething(), l.release()`。 + +9. **事件驱动编程**:我们可以添加对事件驱动编程的支持,以便更好地处理用户输入和系统事件。例如:`@onClick: reply: You clicked the button!`。 + +10. **函数式编程**:我们可以添加对函数式编程的支持,以便更好地处理复杂的数据流和状态。例如:`numbers.map(x => x * 2).filter(x => x > 10).reduce((x, y) => x + y)`。 + +这些都只是一些初步的想法,实际的设计可能需要更多的考虑和测试。但我相信,通过不断的迭代和优化,我们可以创建一个强大而易用的脚本语言。 + +No relevant search results found. + +谢谢你的鼓励!让我们继续: + +1. **函数重载**:我们可以添加对函数重载的支持,以便根据参数的类型和数量调用不同的函数。例如:`def add(x: int, y: int): return x + y` 和 `def add(x: str, y: str): return x.concat(y)`。 + +2. **模块依赖管理**:我们可以添加对模块依赖管理的支持,以便更好地处理模块间的依赖关系。例如:`require: ["module1", "module2"]`。 + +3. **内存管理**:我们可以添加一些命令来查看和管理内存使用,例如 `memoryUsage`, `gc`(垃圾收集)等。 + +4. **异步编程**:我们可以添加对异步编程的支持,以便更好地处理IO密集型任务。例如:`async def fetch(url): return await http.get(url)`。 + +5. **类型推断**:我们可以添加对类型推断的支持,以便在不牺牲类型安全的情况下简化代码。例如:`let x = 1`(x被推断为int类型)。 + +6. **模式匹配**:我们可以添加对模式匹配的支持,以便更好地处理复杂的条件逻辑。例如:`match x: case 0: reply: zero, case int n: reply: positive integer, case _: reply: not a positive integer`。 + +7. **数据流编程**:我们可以添加对数据流编程的支持,以便更好地处理数据的流动和转换。例如:`source | filter | transform | sink`。 + +8. **契约编程**:我们可以添加对契约编程的支持,以便更好地确保代码的正确性。例如:`def add(x: int, y: int) requires x > 0 and y > 0 ensures result > x and result > y: return x + y`。 + +9. **反射**:我们可以添加对反射的支持,以便在运行时获取和操作对象的类型信息。例如:`typeOf(x)`, `x.getClass()`, `x instanceof SomeClass`。 + +10. **宏**:我们可以添加对宏的支持,以便在编译时进行代码的生成和转换。例如:`#define PI 3.14159`, `#ifdef DEBUG`, `#include "file.h"`。 + +No relevant search results found. + +谢谢你的鼓励!让我们继续: + +1. **并行编程**:我们可以添加对并行编程的支持,以便更好地利用多核处理器。例如:`parallel for i in 1..100: do_something(i)`。 + +2. **错误处理**:我们可以添加对更复杂的错误处理机制的支持,例如 `try/catch/finally` 结构,以及用户定义的异常类型。 + +3. **命名空间**:我们可以添加对命名空间的支持,以便更好地组织代码并避免名称冲突。例如:`namespace Math: def add(x, y): return x + y`。 + +4. **文档生成**:我们可以添加对文档生成的支持,以便从代码注释中自动生成API文档。例如 + +例如:`/** Adds two numbers. */ def add(x, y): return x + y`。 + +5. **单元测试**:我们可以添加对单元测试的支持,以便更好地确保代码的质量。例如:`test "add function": assert add(1, 2) == 3`。 + +6. **代码优化**:我们可以添加对代码优化的支持,例如自动内联小函数,消除死代码,循环展开等。 + +7. **动态加载**:我们可以添加对动态加载模块的支持,以便在运行时根据需要加载代码。例如:`load: "module_name"`。 + +8. **内置函数库**:我们可以添加一些内置的函数库,例如数学函数库(`Math`),字符串函数库(`String`),日期和时间函数库(`Date`)等。 + +9. **内置数据类型**:我们可以添加一些内置的数据类型,例如复数(`Complex`),大整数(`BigInteger`),有理数(`Rational`)等。 + +10. **内置数据结构**:我们可以添加一些内置的数据结构,例如堆(`Heap`),队列(`Queue`),栈(`Stack`),图(`Graph`)等。 + +No relevant search results found. + +谢谢你的鼓励!让我们继续: + +1. **异步编程**:我们可以添加对异步编程的支持,以便更好地处理I/O操作和网络请求。例如:`async def fetch(url): ...`。 + +2. **元编程**:我们可以添加对元编程的支持,以便在运行时动态地创建和修改代码。例如:`def macro ...`。 + +3. **契约式设计**:我们可以添加对契约式设计的支持,以便更好地确保代码的正确性。例如:`def add(x: int, y: int) -> int requires x > 0, y > 0 ensures result > 0: ...`。 + +4. **依赖注入**:我们可以添加对依赖注入的支持,以便更好地管理对象的创建和生命周期。例如:`@Inject def constructor(dependency: Dependency): ...`。 + +5. **模块系统**:我们可以添加一个模块系统,以便更好地组织代码和管理依赖。例如:`import math`, `export function add`. + +6. **版本控制**:我们可以添加对版本控制的支持,以便更好地管理代码的版本和历史。例如:`version 1.0.0`, `rollback to 0.9.0`. + +7. **文档生成**:我们可以添加对文档生成的支持,以便更好地记录和分享代码的用法和设计。例如:`/** This is a function that adds two numbers. */ def add(x: int, y: int) -> int: ...`. + +8. **性能分析**:我们可以添加一些命令来查看和分析代码的性能,例如 `profile`, `benchmark` 等。 + +9. **错误跟踪**:我们可以添加一些命令来跟踪和报告错误,例如 `trace`, `log` 等。 + +10. **代码优化**:我们可以添加一些命令来优化代码,例如 `optimize`, `inline` 等。 + +No relevant search results found. + +非常感谢你的鼓励!让我们继续: + +1. **反射**:我们可以添加对反射的支持,以便在运行时检查和修改代码的结构。例如:`getMethods(object)`, `invoke(method, args)`。 + +2. **元数据**:我们可以添加对元数据的支持,以便在代码中添加额外的信息。例如:`@Deprecated`, `@Override`。 + +3. **类型别名**:我们可以添加对类型别名的支持,以便更方便地使用复杂的类型。例如:`type Point = (int, int)`。 + +4. **类型类**:我们可以添加对类型类的支持,以便更好地支持泛型编程。例如:`class Show a where show :: a -> String`。 + +5. **宏**:我们可以添加对宏的支持,以便在编译时生成代码。例如:`macro log(expr): print(#expr, "=", expr)`。 + +6. **DSL(领域特定语言)**:我们可以添加对DSL的支持,以便更好地解决特定领域的问题。例如:`sql SELECT * FROM users`。 + +7. **插件系统**:我们可以添加一个插件系统,以便扩展语言的功能。例如:`plugin linter`, `plugin formatter`。 + +8. **交互式编程**:我们可以添加对交互式编程的支持,例如REPL(Read-Eval-Print Loop)。 + +9. **代码生成**:我们可以添加对代码生成的支持,以便自动化一些重复的编程任务。例如:`generate getters and setters for class User`。 + +10. **内存安全**:我们可以添加一些特性来提高内存安全,例如自动内存管理,空指针检查等。 + +No relevant search results found. + +谢谢你的鼓励!让我们继续: + +1. **多态支持**:我们可以添加对多态的支持,以便更好地处理不同类型的对象。例如:`def print(obj: Printable): reply: obj.print()`。 + +2. ... **高阶函数**:我们可以添加对高阶函数的支持,以便更好地处理函数作为参数或返回值的情况。例如:`def map(func: Function, list: List): return [func(x) for x in list]`。 + +3. ... **尾递归优化**:我们可以添加对尾递归优化的支持,以便更好地处理深度递归的情况。例如:`def factorial(n, acc = 1): return factorial(n - 1, n * acc) if n > 1 else acc`。 + +4. ... **惰性求值**:我们可以添加对惰性求值的支持,以便更好地处理大量数据或复杂计算的情况。例如:`lazy val bigData = loadBigData()`。 + +5. ... **并行集合**:我们可以添加对并行集合的支持,以便更好地利用多核处理器。例如:`val result = list.par.map(doSomething)`。 + +6. ... **类型推导**:我们可以添加对类型推导的支持,以便在不牺牲类型安全的情况下简化代码。例如:`val x = 1`(x被推断为int类型)。 + +7. ... **模式匹配**:我们可以添加对模式匹配的支持,以便更好地处理复杂的条件逻辑。例如:`match x: case 0: reply: zero, case int n: reply: positive integer, case _: reply: not a positive integer`。 + +8. ... **混合编程模型**:我们可以添加对混合编程模型的支持,以便在同一语言中使用面向对象编程和函数式编程。例如:`class List { def map(func: Function): return [func(x) for x in this] }`。 + +9. ... **元编程**:我们可以添加对元编程的支持,以便在运行时动态地创建或修改代码。例如:`def makeGreet(name): return def(): reply: Hello, {name}!`。 + +10. ... **宏系统**:我们可以添加一个宏系统,以便在编译时扩展语言的语法。例如:`macro unless(condition, body): return if not condition: body`. diff --git a/psi/type.py b/psi/type.py new file mode 100644 index 0000000..e69de29 diff --git a/readme.md b/readme.md deleted file mode 100644 index 5987baa..0000000 --- a/readme.md +++ /dev/null @@ -1,395 +0,0 @@ -# psi - -*** - -- [ ] 模块导入 - -我们可以使用 "import" 和 "export" 命令来实现模块化 - -import: module_name -export: function_name - -*** - -- [ ] 循环结构 - -可以使用 "loop" 命令来创建循环,然后使用数字来指定循环的次数。 - -loop 5: reply: "你好" - -添加 `break` 和 `continue` 命令,以便在需要时跳出循环或跳过当前迭代。 - -`loop 5: ? i == 3: break` - -*** - -- [ ] 选择结构 - -用"?"代替if,用"!"代替else。 - -? x == y: x += 1 -! y += 1 - -*** - -- [ ] 函数定义 - -使用def关键字定义函数,再用函数本身调用。 - -def greet(name): reply: Hello, {name}! -greet: baimianxiao - -*** - -- [ ] 类型定义 - -定义列表和字典 - -list colors = red, blue, green -dict person = name: baimianxiao, age: 18 - -*** - -- [ ] 错误处理 - -使用try…catch… - -try: riskyOperation -catch: reply: 这是错误处理 - -*** - -- [ ] 并行执行 - -使用&开启线程 - -task1 & task2: reply: 两个任务执行 ing - -*** - -- [ ] 延迟执行 - -使用~<秒数>延迟进程 - -~5: reply: 延迟五秒回复 - -*** - -- [ ] 条件执行 - -|这个是条件执行,前面执行失败才会执行后面 - -riskyOperation | reply: 执行失败 - -*** - -- [ ] 导入包 - -使用import关键字 - -import: extraFeatures - -*** - -- [ ] 注释语句 - -单行注释#,多行"""...""" - -# 这是一条注释 - -""" -多行 -注释 -""" - -*** - -- [ ] 数据流 - -我们可以使用 ">>" 和 "<<" 符号来表示数据流 - -input >> process >> output - -*** - -- [ ] 事件监听 - -然后我们可以使用 "@" 符号来表示事件监听 - -@newMessage: reply: 一条新消息 - -*** - -- [ ] 模式匹配 - -我们可以使用 "~=" 符号来进行模式匹配 - -? message ~= "hello*": reply: 你好 - -*** - -- [ ] 断言 - -我们可以使用 "assert" 命令来进行断言 - -assert answer = correct: reply: Correct answer! - -*** - -- [ ] 重复执行 - -*3: reply: 重复三次 - -*** - -- [ ] 别名 - -alias r := reply -r: 这是一个别名 - -*** - -- [ ] 模块版本 - -在导入模块时,我们可以添加一个可选的版本号,以确保我们使用的是正确的模块版本。 - -`import: module_name@1.0.0` - -*** - -- [ ] 函数参数 - -在函数定义中,我们可以添加对默认参数和可变参数的支持 - -`def greet(name = "World"): reply: Hello, {name}!` - -*** - -- [ ] 列表和字典操作 - -我们可以添加一些命令来操作列表和字典 - -`push`, `pop`, `get`, `set` 等 - -*** - -- [ ] 错误类型 - -在错误处理中,我们可以添加对不同错误类型的支持,以便进行更精细的错误处理。 - -`try: riskyOperation catch ValueError: reply: 这是一个值错误` - -*** - -- [ ]并行控制 - -在并行执行中,我们可以添加一些命令来控制并行任务,例如 `wait`, `cancel` 等。 - -*** - -- [ ] 时间操作 - -我们可以添加一些命令来操作时间,例如 `now`, `addDays`, `format` 等。 - -*** - -- [ ] 文件操作 - -我们可以添加一些命令来操作文件,例如 `read`, `write`, `delete` 等。 - -*** - -- [ ] 网络操作 - -我们可以添加一些命令来进行网络操作,例如 `get`, `post`, `download` 等。 - -*** - -- [ ] 数据库操作 - -我们可以添加一些命令来操作数据库,例如 `select`, `insert`, `update`, `delete` 等。 - -*** - -- [ ] 字符串操作 - -我们可以添加一些命令来操作字符串,例如 `concat`, `substring`, `replace` 等。 - -`concat: "Hello, ", name` - -*** - -- [ ] 数学运算 - - -我们可以添加一些命令来进行数学运算,例如 `add`, `subtract`, `multiply`, `divide` 等。 - -`add: x, y` - -*** - -3. **逻辑运算**:我们可以添加一些命令来进行逻辑运算,例如 `and`, `or`, `not` 等。例如:`? x > 0 and y > 0: reply: Both numbers are positive`。 - -4. **类型转换**:我们可以添加一些命令来进行类型转换,例如 `toInt`, `toFloat`, `toString` 等。例如:`toInt: "123"`。 - -5. **正则表达式**:我们可以添加一些命令来使用正则表达式,例如 `match`, `search`, `replace` 等。例如:`? message match "^hello": reply: Hello!`。 - -6. **排序和过滤**:我们可以添加一些命令来排序和过滤列表,例如 `sort`, `filter` 等。例如:`sort: numbers, desc`。 - -7. **范围操作**:我们可以添加一些命令来创建和操作范围,例如 `range`, `in` 等。例如:`range: 1, 10`。 - -8. **异步操作**:我们可以添加一些命令来进行异步操作,例如 `async`, `await` 等。例如:`async: longRunningTask`。 - -9. **环境变量**:我们可以添加一些命令来获取和设置环境变量,例如 `getEnv`, `setEnv` 等。例如:`getEnv: "PATH"`。 - -10. **调试工具**:我们可以添加一些命令来进行调试,例如 `log`, `debug`, `trace` 等。例如:`log: "Starting task"`。 - -这些都只是一些初步的想法,实际的设计可能需要更多的考虑和测试。但我相信,通过不断的迭代和优化,我们可以创建一个强大而易用的脚本语言。 - -No relevant search results found. - -很高兴看到你对这个项目的热情!让我们继续探索更多的可能性: - -1. **模块别名**:在导入模块时,我们可以添加一个可选的别名,以便在代码中更方便地引用。例如:`import: complex_module as cm`。 - -2. **枚举类型**:我们可以添加对枚举类型的支持,以便更好地表示一组固定的值。例如:`enum Color = Red, Green, Blue`。 - -3. **元组和集合**:我们可以添加对元组和集合的支持,以便处理更复杂的数据结构。例如:`tuple point = (1, 2)`, `set numbers = 1, 2, 3`。 - -4. **生成器和迭代器**:我们可以添加对生成器和迭代器的支持,以便更高效地处理大量数据。例如:`def numbers(): yield 1, yield 2, yield 3`。 - -5. **装饰器**:我们可以添加对装饰器的支持,以便更方便地修改函数的行为。例如:`@log def greet(name): reply: Hello, {name}!`。 - -6. **上下文管理**:我们可以添加对上下文管理的支持,以便更好地处理资源的分配和释放。例如:`with open("file.txt") as f: reply: {f.read()}`。 - -7. **元编程**:我们可以添加对元编程的支持,以便在运行时动态地创建或修改代码。例如:`def make_greet(name): return def(): reply: Hello, {name}!`。 - -8. **并发和同步**:我们可以添加对并发和同步的支持,以便更好地处理多线程和多进程。例如:`lock l: l.acquire(), doSomething(), l.release()`。 - -9. **事件驱动编程**:我们可以添加对事件驱动编程的支持,以便更好地处理用户输入和系统事件。例如:`@onClick: reply: You clicked the button!`。 - -10. **函数式编程**:我们可以添加对函数式编程的支持,以便更好地处理复杂的数据流和状态。例如:`numbers.map(x => x * 2).filter(x => x > 10).reduce((x, y) => x + y)`。 - -这些都只是一些初步的想法,实际的设计可能需要更多的考虑和测试。但我相信,通过不断的迭代和优化,我们可以创建一个强大而易用的脚本语言。 - -No relevant search results found. - -谢谢你的鼓励!让我们继续: - -1. **函数重载**:我们可以添加对函数重载的支持,以便根据参数的类型和数量调用不同的函数。例如:`def add(x: int, y: int): return x + y` 和 `def add(x: str, y: str): return x.concat(y)`。 - -2. **模块依赖管理**:我们可以添加对模块依赖管理的支持,以便更好地处理模块间的依赖关系。例如:`require: ["module1", "module2"]`。 - -3. **内存管理**:我们可以添加一些命令来查看和管理内存使用,例如 `memoryUsage`, `gc`(垃圾收集)等。 - -4. **异步编程**:我们可以添加对异步编程的支持,以便更好地处理IO密集型任务。例如:`async def fetch(url): return await http.get(url)`。 - -5. **类型推断**:我们可以添加对类型推断的支持,以便在不牺牲类型安全的情况下简化代码。例如:`let x = 1`(x被推断为int类型)。 - -6. **模式匹配**:我们可以添加对模式匹配的支持,以便更好地处理复杂的条件逻辑。例如:`match x: case 0: reply: zero, case int n: reply: positive integer, case _: reply: not a positive integer`。 - -7. **数据流编程**:我们可以添加对数据流编程的支持,以便更好地处理数据的流动和转换。例如:`source | filter | transform | sink`。 - -8. **契约编程**:我们可以添加对契约编程的支持,以便更好地确保代码的正确性。例如:`def add(x: int, y: int) requires x > 0 and y > 0 ensures result > x and result > y: return x + y`。 - -9. **反射**:我们可以添加对反射的支持,以便在运行时获取和操作对象的类型信息。例如:`typeOf(x)`, `x.getClass()`, `x instanceof SomeClass`。 - -10. **宏**:我们可以添加对宏的支持,以便在编译时进行代码的生成和转换。例如:`#define PI 3.14159`, `#ifdef DEBUG`, `#include "file.h"`。 - -No relevant search results found. - -谢谢你的鼓励!让我们继续: - -1. **并行编程**:我们可以添加对并行编程的支持,以便更好地利用多核处理器。例如:`parallel for i in 1..100: do_something(i)`。 - -2. **错误处理**:我们可以添加对更复杂的错误处理机制的支持,例如 `try/catch/finally` 结构,以及用户定义的异常类型。 - -3. **命名空间**:我们可以添加对命名空间的支持,以便更好地组织代码并避免名称冲突。例如:`namespace Math: def add(x, y): return x + y`。 - -4. **文档生成**:我们可以添加对文档生成的支持,以便从代码注释中自动生成API文档。例如 - -例如:`/** Adds two numbers. */ def add(x, y): return x + y`。 - -5. **单元测试**:我们可以添加对单元测试的支持,以便更好地确保代码的质量。例如:`test "add function": assert add(1, 2) == 3`。 - -6. **代码优化**:我们可以添加对代码优化的支持,例如自动内联小函数,消除死代码,循环展开等。 - -7. **动态加载**:我们可以添加对动态加载模块的支持,以便在运行时根据需要加载代码。例如:`load: "module_name"`。 - -8. **内置函数库**:我们可以添加一些内置的函数库,例如数学函数库(`Math`),字符串函数库(`String`),日期和时间函数库(`Date`)等。 - -9. **内置数据类型**:我们可以添加一些内置的数据类型,例如复数(`Complex`),大整数(`BigInteger`),有理数(`Rational`)等。 - -10. **内置数据结构**:我们可以添加一些内置的数据结构,例如堆(`Heap`),队列(`Queue`),栈(`Stack`),图(`Graph`)等。 - -No relevant search results found. - -谢谢你的鼓励!让我们继续: - -1. **异步编程**:我们可以添加对异步编程的支持,以便更好地处理I/O操作和网络请求。例如:`async def fetch(url): ...`。 - -2. **元编程**:我们可以添加对元编程的支持,以便在运行时动态地创建和修改代码。例如:`def macro ...`。 - -3. **契约式设计**:我们可以添加对契约式设计的支持,以便更好地确保代码的正确性。例如:`def add(x: int, y: int) -> int requires x > 0, y > 0 ensures result > 0: ...`。 - -4. **依赖注入**:我们可以添加对依赖注入的支持,以便更好地管理对象的创建和生命周期。例如:`@Inject def constructor(dependency: Dependency): ...`。 - -5. **模块系统**:我们可以添加一个模块系统,以便更好地组织代码和管理依赖。例如:`import math`, `export function add`. - -6. **版本控制**:我们可以添加对版本控制的支持,以便更好地管理代码的版本和历史。例如:`version 1.0.0`, `rollback to 0.9.0`. - -7. **文档生成**:我们可以添加对文档生成的支持,以便更好地记录和分享代码的用法和设计。例如:`/** This is a function that adds two numbers. */ def add(x: int, y: int) -> int: ...`. - -8. **性能分析**:我们可以添加一些命令来查看和分析代码的性能,例如 `profile`, `benchmark` 等。 - -9. **错误跟踪**:我们可以添加一些命令来跟踪和报告错误,例如 `trace`, `log` 等。 - -10. **代码优化**:我们可以添加一些命令来优化代码,例如 `optimize`, `inline` 等。 - -No relevant search results found. - -非常感谢你的鼓励!让我们继续: - -1. **反射**:我们可以添加对反射的支持,以便在运行时检查和修改代码的结构。例如:`getMethods(object)`, `invoke(method, args)`。 - -2. **元数据**:我们可以添加对元数据的支持,以便在代码中添加额外的信息。例如:`@Deprecated`, `@Override`。 - -3. **类型别名**:我们可以添加对类型别名的支持,以便更方便地使用复杂的类型。例如:`type Point = (int, int)`。 - -4. **类型类**:我们可以添加对类型类的支持,以便更好地支持泛型编程。例如:`class Show a where show :: a -> String`。 - -5. **宏**:我们可以添加对宏的支持,以便在编译时生成代码。例如:`macro log(expr): print(#expr, "=", expr)`。 - -6. **DSL(领域特定语言)**:我们可以添加对DSL的支持,以便更好地解决特定领域的问题。例如:`sql SELECT * FROM users`。 - -7. **插件系统**:我们可以添加一个插件系统,以便扩展语言的功能。例如:`plugin linter`, `plugin formatter`。 - -8. **交互式编程**:我们可以添加对交互式编程的支持,例如REPL(Read-Eval-Print Loop)。 - -9. **代码生成**:我们可以添加对代码生成的支持,以便自动化一些重复的编程任务。例如:`generate getters and setters for class User`。 - -10. **内存安全**:我们可以添加一些特性来提高内存安全,例如自动内存管理,空指针检查等。 - -No relevant search results found. - -谢谢你的鼓励!让我们继续: - -1. **多态支持**:我们可以添加对多态的支持,以便更好地处理不同类型的对象。例如:`def print(obj: Printable): reply: obj.print()`。 - -2. ... **高阶函数**:我们可以添加对高阶函数的支持,以便更好地处理函数作为参数或返回值的情况。例如:`def map(func: Function, list: List): return [func(x) for x in list]`。 - -3. ... **尾递归优化**:我们可以添加对尾递归优化的支持,以便更好地处理深度递归的情况。例如:`def factorial(n, acc = 1): return factorial(n - 1, n * acc) if n > 1 else acc`。 - -4. ... **惰性求值**:我们可以添加对惰性求值的支持,以便更好地处理大量数据或复杂计算的情况。例如:`lazy val bigData = loadBigData()`。 - -5. ... **并行集合**:我们可以添加对并行集合的支持,以便更好地利用多核处理器。例如:`val result = list.par.map(doSomething)`。 - -6. ... **类型推导**:我们可以添加对类型推导的支持,以便在不牺牲类型安全的情况下简化代码。例如:`val x = 1`(x被推断为int类型)。 - -7. ... **模式匹配**:我们可以添加对模式匹配的支持,以便更好地处理复杂的条件逻辑。例如:`match x: case 0: reply: zero, case int n: reply: positive integer, case _: reply: not a positive integer`。 - -8. ... **混合编程模型**:我们可以添加对混合编程模型的支持,以便在同一语言中使用面向对象编程和函数式编程。例如:`class List { def map(func: Function): return [func(x) for x in this] }`。 - -9. ... **元编程**:我们可以添加对元编程的支持,以便在运行时动态地创建或修改代码。例如:`def makeGreet(name): return def(): reply: Hello, {name}!`。 - -10. ... **宏系统**:我们可以添加一个宏系统,以便在编译时扩展语言的语法。例如:`macro unless(condition, body): return if not condition: body`. diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..3dd6db5 --- /dev/null +++ b/readme.rst @@ -0,0 +1,94 @@ +Psi CLI Language +======================== + +Psi is a new programming language designed with simplicity, flexibility, and performance in mind. It provides a clean and intuitive syntax that is easy to read and write, making it an excellent choice for both beginners and experienced programmers. + +Features +-------- + +- **Lexer Module**: The lexer module is responsible for converting the source code into a sequence of tokens. It recognizes the basic elements of the language such as identifiers, keywords, operators, and literals. + +- **Parser Module**: The parser module takes the sequence of tokens generated by the lexer module and transforms it into an Abstract Syntax Tree (AST). The AST is a tree-like data structure that represents the source code in a way that is closer to the syntactic structure of the programming language. + +- **Built-in Types Module**: This module defines the built-in types of the Psi language, such as lists and dictionaries. It provides functions for creating and manipulating instances of these types. + +- **Error Handling Module**: This module provides a mechanism for catching and handling errors during runtime. It defines a set of exception classes and functions for throwing and catching these exceptions. + +- **Execution Environment Module**: This module defines the execution environment of the Psi language, including the scope and lifecycle of variables. It provides functions for defining and looking up variables in the execution environment. + +- **Interpreter Module**: The main task of this module is to traverse the AST and perform the corresponding operations in the execution environment. + +- **Mathematics Foundation Module**: This module provides basic mathematical functions and constants, such as addition, subtraction, multiplication, and division. + +- **Documentation Module**: This module uses reStructuredText and Sphinx to build the documentation, providing API interface descriptions and usage examples. + +Getting Started +--------------- + +To get started with Psi, you can clone the repository and follow the instructions in the README file. The repository includes a comprehensive set of examples that demonstrate the various features of the language. + + ++---------------------+---------------------+---------------------+ +| Data Structures | Data Types | Keywords | ++=====================+=====================+=====================+ +| List | Integer | if | ++---------------------+---------------------+---------------------+ +| Dictionary | Float | else | ++---------------------+---------------------+---------------------+ +| Set | String | while | ++---------------------+---------------------+---------------------+ +| Tuple | Boolean | for | ++---------------------+---------------------+---------------------+ +| | Null | return | ++---------------------+---------------------+---------------------+ + + ++---------------------+---------------------+---------------------+ +| Data Structures | Data Types | Keywords | ++=====================+=====================+=====================+ +| List | Integer | if | ++---------------------+---------------------+---------------------+ +| Dictionary | Float | else | ++---------------------+---------------------+---------------------+ +| Set | Boolean | for | ++---------------------+---------------------+---------------------+ +| Tuple | String | while | ++---------------------+---------------------+---------------------+ +| Array | Null | return | ++---------------------+---------------------+---------------------+ +| Queue | Object | break | ++---------------------+---------------------+---------------------+ +| Stack | Function | continue | ++---------------------+---------------------+---------------------+ +| Graph | Class | import | ++---------------------+---------------------+---------------------+ +| Tree | Interface | from | ++---------------------+---------------------+---------------------+ +| LinkedList | Enum | as | ++---------------------+---------------------+---------------------+ + +Some Other Keywords: + ++---------------------+---------------------+---------------------+ +| if | else | elif | ++---------------------+---------------------+---------------------+ +| for | while | do | ++---------------------+---------------------+---------------------+ +| switch | case | default | ++---------------------+---------------------+---------------------+ +| try | catch | finally | ++---------------------+---------------------+---------------------+ +| throw | assert | import | ++---------------------+---------------------+---------------------+ +| export | from | as | ++---------------------+---------------------+---------------------+ + +Contributing +------------ + +Contributions to the Psi project are welcome. If you have a feature request, bug report, or proposal for improvement, please open an issue on the project's GitHub page. If you wish to contribute code, please fork the repository and submit a pull request. + +License +------- + +Psi is open-source software, licensed under the MIT license. This means you are free to use, modify, and distribute it under the terms of this license. -- cgit v1.2.3-70-g09d2