{"id":20678541,"url":"https://github.com/codegetters/compiler-example","last_synced_at":"2026-04-17T23:36:44.834Z","repository":{"id":203437487,"uuid":"709337331","full_name":"CodeGetters/compiler-example","owner":"CodeGetters","description":"A basic compiler for learning written in typescript language 一个使用TS编写用于学习的编译器","archived":false,"fork":false,"pushed_at":"2023-11-05T07:58:37.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T19:30:21.246Z","etag":null,"topics":["compiler","node","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeGetters.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-24T14:12:19.000Z","updated_at":"2024-07-21T08:40:09.000Z","dependencies_parsed_at":"2023-10-29T12:28:00.511Z","dependency_job_id":"7ed1d7be-53b9-4eb9-b4de-0558698cf50a","html_url":"https://github.com/CodeGetters/compiler-example","commit_stats":null,"previous_names":["codegetters/compiler-example"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/CodeGetters/compiler-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeGetters%2Fcompiler-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeGetters%2Fcompiler-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeGetters%2Fcompiler-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeGetters%2Fcompiler-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeGetters","download_url":"https://codeload.github.com/CodeGetters/compiler-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeGetters%2Fcompiler-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31950755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T17:29:20.459Z","status":"ssl_error","status_checked_at":"2026-04-17T17:28:47.801Z","response_time":62,"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":["compiler","node","typescript"],"created_at":"2024-11-16T21:20:45.631Z","updated_at":"2026-04-17T23:36:44.816Z","avatar_url":"https://github.com/CodeGetters.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# compiler-example\n\n一个由 TS 搭建的学习版编译器\n\nA basic compiler for learning written in typescript language\n\n```sh\nyarn tsc\n\nyarn check\n\nyarn dev\n```\n\n-   [x] 预处理\n-   [x] 词法分析\n-   [ ] 语法分析\n\nWhat should be before running?\n运行前代码是什么样的？\n\n```js\n// example/sourceRoutine.js\nlet a = 12;\nlet b = 14;\n\nlet c = a + b;\n```\n\nAfter running it will become...\n代码运行后将变成...\n\n```\n// example/output.js\nlet a=12;let b=14;let c=a+b;\n```\n\n```json\n// example/lexicalOutput.json\n{\n    \"tokens\": [\n        {\n            \"type\": \"keyword\",\n            \"val\": \"let\",\n            \"line\": 1\n        }\n    ]\n}\n```\n\nC 语言子集语法 EBNF 描述\n\n```txt\n\u003c语句\u003e   ∷=  \u003c变量\u003e∶=\u003c表达式\u003e            // 变量赋值\n        | if \u003c表达式\u003e \u003c语句\u003e             // 条件语句\n        | if \u003c表达式\u003e \u003c语句\u003e else \u003c语句\u003e  // 条件语句\n\u003c变量\u003e   ∷=  i   | i  '['\u003c表达式\u003e']'    // 对数组或列表的索引\n\u003c表达式\u003e ∷=  \u003c项\u003e | \u003c表达式\u003e + \u003c项\u003e      // 单独的项或表达式 + 项(可以进行加法运算)\n\u003c项\u003e    ∷=  \u003c因子\u003e| \u003c项\u003e*\u003c因子\u003e         // 因子|项和因子(乘法运算)\n\u003c因子\u003e  ∷=  \u003c变量\u003e| '('\u003c表达式\u003e')'      //\n```\n\n这是一个简单的语法规则定义，描述了一个类似于编程语言中的语句、变量和表达式的结构。\n\n-   1. `\u003c语句\u003e ::= \u003c变量\u003e∶=\u003c表达式\u003e`\n       这一行定义了一条语句的结构，它由一个变量和一个表达式组成，用冒号和等号连接。这可以表示给变量赋值的操作。\n-   2. `\u003c语句\u003e ::= if \u003c表达式\u003e \u003c语句\u003e`\n       这一行定义了一个条件语句的结构，以关键字 \"if\" 开始，后面跟着一个表达式和一条语句。如果表达式的结果为真，就执行这条语句。\n-   3. `\u003c语句\u003e ::= if \u003c表达式\u003e \u003c语句\u003e else \u003c语句\u003e`\n       这一行定义了一个条件语句的结构，与上一行类似，但多了一个 \"else\" 关键字和另一条语句。如果表达式的结果为真，执行第一条语句；否则，执行第二条语句。\n-   4. `\u003c变量\u003e ::= i | i '['\u003c表达式\u003e']'`\n       这一行定义了变量的结构。变量可以是一个简单的标识符 \"i\"，也可以是一个带有方括号的表达式，表示对一个数组或列表的索引。\n-   5. `\u003c表达式\u003e ::= \u003c项\u003e | \u003c表达式\u003e + \u003c项\u003e`\n       这一行定义了表达式的结构。一个表达式可以是一个单独的项，或者是由一个表达式和一个加号连接的项。这表示可以进行加法运算。\n-   6. `\u003c项\u003e ::= \u003c因子\u003e | \u003c项\u003e* \u003c因子\u003e`\n       这一行定义了项的结构。一个项可以是一个因子，或者由一个项、一个乘号和一个因子连接而成。这表示可以进行乘法运算。\n-   7. `\u003c因子\u003e ::= \u003c变量\u003e | '(' \u003c表达式\u003e ')'`\n       这一行定义了因子的结构。一个因子可以是一个变量，或者是由一对括号括起来的表达式。这表示可以使用括号改变运算顺序。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodegetters%2Fcompiler-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodegetters%2Fcompiler-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodegetters%2Fcompiler-example/lists"}