{"id":36835732,"url":"https://github.com/pywee/lit","last_synced_at":"2026-01-12T14:22:33.962Z","repository":{"id":61596910,"uuid":"543486464","full_name":"pywee/lit","owner":"pywee","description":"go Lit 是一个基于 Golang 开发的解释型编程语言，现已支持变量、函数、算术表达式、流程控制等特性，目前仍在持续开发中。This is an interpreter which created by Golang. You can also see it as a novel computer language, but i'm now still working on it to produce a bit more features","archived":false,"fork":false,"pushed_at":"2023-01-08T16:08:28.000Z","size":240,"stargazers_count":13,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-19T19:48:00.655Z","etag":null,"topics":["go","golang","web"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pywee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-30T07:45:30.000Z","updated_at":"2024-06-19T19:48:00.656Z","dependencies_parsed_at":"2023-02-08T06:31:43.553Z","dependency_job_id":null,"html_url":"https://github.com/pywee/lit","commit_stats":null,"previous_names":["pywee/goexpr"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pywee/lit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywee%2Flit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywee%2Flit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywee%2Flit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywee%2Flit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pywee","download_url":"https://codeload.github.com/pywee/lit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pywee%2Flit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28340393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","web"],"created_at":"2026-01-12T14:22:32.073Z","updated_at":"2026-01-12T14:22:33.888Z","avatar_url":"https://github.com/pywee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 基于 Golang 编写的解释型语言 (迭代中)\n\nThis is an interpreter which created by Golang. You can also see it as a novel computer language, but i'm now still working on it to produce a bit more features ...\n\nLit 是一个基于纯 Golang 开发的解释型编程语言，目前仍在持续开发中。\n\n最终我想把它实现为一个解释型的弱类型编程语言，用于日常的 Web 开发。\n\n关于目前已实现的特性，请看如下文档示例，我将会定期更新。\n\n当前文档更新日期是: 2022.12.08\n\n---\n\n### 已支持的特性\n\n**一、变量**\n\n**二、数组**\n\n**三、算术表达式**\n\n**四、弱类型**\n\n**五、关系运算**\n\n**六、逻辑运算**\n\n**七、内置函数**\n\n**八、自定义函数**\n\n**九、流程控制 if**\n\n**十、流程控制 for (实验阶段)**\n\n---\n\n\n\n### 使用方法 非常简单\n\n##### 第一步：下载 lit 项目包\n\n```\ngo get github.com/pywee/lit\n```\n---\n\n##### 第二步：在当前目录新建 main.go 文件，内容如下\n\n```golang\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"github.com/pywee/lit\"\n)\n\nfunc main() {\n\texprs, err := os.ReadFile(\"./src.lit\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tif _, err = goExpr.NewExpr(exprs); err != nil {\n\t\tfmt.Println(err)\n\t\treturn\n\t}\n}\n\n```\n\n---\n\n##### 第三步：在当前目录新建 src.lit 文件\n\n```go\n\n// src.lit 文件内容\n\n// 例1\n// 变量声明、进行算术运算、执行内置函数\na = 5\nb = a + 6\nc = a + b * (1 + 2 * (3 + 4) - 5 / b)\nprintln(a + b + c) // 输出 186\n\n// 浮点型处理\na = 11\na /= 2\nfunc demo(arg) {\n    return arg+1\n}\nprintln(demo(a+1)) // 输出 7.5\n\n\n// 例2\n// 较为复杂的算术运算，优先级的处理逻辑与 golang 保持一致\n// * 以下代码如果是在 PHP 中执行会输出 -24，两种语言针对优先级的处理略微不一样，其他语言也是如此\na = (2 + 100 ^ 2 - (10*1.1 - 22 + (22 | 11))) / 10 * 2\nb = 12 / 333 + 31 + (5 / 10) - 6 | 100\nprintln(a) // 输出 16\nprintln(b) // 输出 125\n\n\n// 例3\n// 自定义函数以及弱类型处理\nfunc demo(arg) {\n    arg++\n    return arg-false*3/10+(20-1)\n}\nprintln(demo(10)+70) // 100\n\n\n// 例4\n// 下面的句子调用了两个函数 \n// isInt(arg) 用来检查 arg 是否为整型 \n// replace(arg1, arg2, arg3, arg4) 用来做字符串替换\na = replace(\"Hello Word111!\", \"1\", \"\", 2-isInt((1+(1 + isInt(123+(1+2)))-1)+2)-2)\nprintln(a) // 输出 Hello word!\n\n\n// 例5\n// 更多关于弱类型的处理，基本上参考了 PHP\na = true - 1\nb = isInt(1)\nc = isFloat(1.0)\nd = false == 0.0\ne = \"false\" == 0.0\nprintln(a) // 0\nprintln(b) // true\nprintln(c) // true\nprintln(d) // true\nprintln(e) // true\n\na = false\nb = true\nc = \"123\"\nd = 456\nprintln(a + b) // 1\nprintln(a \u003e= b) // false\nprintln(a + b + c + d) // 580\n\n\n// 例6\n// 流程控制语句 if 多if嵌套示例\na = 100;\nfunc functionDemo() {\n    return 1;\n}\nif a == 101 - functionDemo() {\n    if 1+1 == 2 \u0026\u0026 3-1 == 20 {\n        println(\"yes\")\n    } else {\n        if 1+a == 102{\n            println(\"no\")\n        } else {\n            if false {\n                println(0)\n            } else {\n                println(\"Hello world!\")\n            }\n        }\n    }\n}\n\n\n// 例7\n// 流程控制语句 for\na = 5;\nif a == 6-demo() {\n    for i = 0; i \u003c demo()+a; i ++ {\n        println(a+i); // 输出 5 6 7 8 9 10\n    }\n}\nfunc demo() {\n    return 1;\n}\n\n\n// 例8-01\n// 声明数组 a\n// 直接通过 println 输出 a 及其下标 a[0]\na = [1]\nprintln(a, a[0]) // 输出 Array 1\n\n\n// 例8-02\n// 声明并访问多维数组\narr = [[[123]]]\nprintln(arr[0][0][0]) // 输出 123\n\n\n// 例8-03\n// 多维数组的声明及参与运算的效果\nb = [9, [123]]\nb[1][0] = 1\nfunc demo(arr) {\n    return arr[1]\n}\nprintln(demo(b)[0]+1) // 输出 2\n\n\n// 例8-04\na = [1, 2, 3]\nfunc demo(arg) {\n    for i = 0; i \u003c 3; i ++ {\n        if arg[i] \u003e 1 {\n            break\n        }\n        println(arg[i])\n    }\n}\ndemo(a) // 输出 1\n\n```\n\n```golang\n// 最后即可在当前目录执行 go run . 输出结果\n// go run .\n\n// * for 功能仍在迭代中，仅实现了一种 针对 (i = 0; i \u003c n; i++)\n// * 我在完成对数组的支持后会继续迭代 for 功能，实现 range 操作\n```\n\n---\n**请注意，Lit 的算术符号优先级向 Golang 看齐。每个语言对算术符号的优先级处理都有一定区别，如，针对以下表达式进行计算时：**\n\n``` golang\n// 2 + 100 ^ 2 - (10*1.1 - 22 + (22 | 11)) / 10 * 2\n// PHP 输出 -104\n// Node.js 输出 -104\n// Golang 输出 96\n// Lit 输出 96\n```\n\n---\n\n**Lit 算术符号优先级**\n\n第一级  ``` () \u0026\u0026 || ```\n\n第二级  ``` \u003e \u003c \u003e= \u003c= == != ===```\n\n第三级  ``` * / % ```\n\n第四级 ```| \u0026``` \n\n第五级  ``` + - ^ ```\n\n---\n\n**当前支持的内置函数有如下，更多函数将会在逐步补充 (当前仍然存在bug）**\n通用处理函数\n```golang\nprint\nvarDump\n```\n---\n字符串处理函数\n函数的命名基本参考了 Go 语言\n除了个别函数有差别，如 \nutf8Len 用于检测字符串字数的函数\nisNumeric 用于判断当前输入是否为数字\n\n```\ntrim\ntrimLeft\ntrimRight\ntrimSpace\nlen\nutf8Len\nmd5\nreplace\ncontains\nindex\nlastIndex\ntoLower\ntoUpper\ntoTitle\nrepeat\n```\n---\n其他函数\n```\nisNumeric\nisBool\nisInt\nisFloat\n```\n\n---\n\n\n#### 计划后期支持的特性\n\n##### 数组、对象或结构体 (从中选择其一实现)、递归、基础的动态库 (如 tcp/http/mysql等)、异常处理\n\n由于它将是一个解释型语言，出于效率考虑，我不会让它支持任何的语法糖，不支持多余的、锦上添花的特性，避免在运行时过多影响效率。\n\n得益于 Golang 原生支持的一些高级特性，例如 管道、协程 这些可轻松实现异步操作，Lit 会有更多扩展空间，它会比 php 更灵活、更小巧。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpywee%2Flit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpywee%2Flit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpywee%2Flit/lists"}