{"id":13687337,"url":"https://github.com/dontpanic92/dparse","last_synced_at":"2025-07-31T17:04:22.605Z","repository":{"id":16930380,"uuid":"19692110","full_name":"dontpanic92/dparse","owner":"dontpanic92","description":"dparse is a Dynamic Parser / a Parser Generator.","archived":false,"fork":false,"pushed_at":"2015-11-14T12:46:41.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T07:31:43.835Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","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/dontpanic92.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":"2014-05-12T09:02:03.000Z","updated_at":"2014-10-06T02:33:26.000Z","dependencies_parsed_at":"2022-09-08T03:00:58.279Z","dependency_job_id":null,"html_url":"https://github.com/dontpanic92/dparse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dontpanic92/dparse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dontpanic92%2Fdparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dontpanic92%2Fdparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dontpanic92%2Fdparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dontpanic92%2Fdparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dontpanic92","download_url":"https://codeload.github.com/dontpanic92/dparse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dontpanic92%2Fdparse/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268074198,"owners_count":24191522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-08-02T15:00:52.727Z","updated_at":"2025-07-31T17:04:22.414Z","avatar_url":"https://github.com/dontpanic92.png","language":"C++","funding_links":[],"categories":["Compiler"],"sub_categories":[],"readme":"dparse\n======\n\n哈工大编译原理实验语法分析器，附带一个简易C语言后端。\n\n词法分析器有独立版本，请见https://github.com/dontpanic92/dlex\n\n\ndparse结构\n======\ndparse为LR(1)型语法分析器，采用语法制导定义方式进行代码生成。建立状态转移表的算法描述请参考龙书，代码基本上是完全按照龙书的描述实现的。\n\ndaprse前端语法分析部分由C++编写，三地址码生成及汇编代码生成部分使用lua编写。parser在lua解释环境中注入了两个函数，分别为`parser_getstackcontent`和`parser_getcurrenttokenname`，分别用于获取当前栈空间中的内容以及获取当前token的名字（用于处理identifier）。\n\n\ndparse文件语法\n======\ndparse文件描述了语言的产生式，使用行开头#号作为注释。\n\n文件的开头两行需要指定词法分析文件以及负责代码生成的lua程序，例如\n\n```\n/home/dontpanic/1.dlex\n/home/dontpanic/1.lua\n```\n\n每一条产生式以冒号:开头，后跟产生式左端名称。\n\n新起一行用空格分割产生式的各个部分。可以使用的符号包括产生式左端名称、以及由dlex文件定义的终结符名称。产生式后跟处理这条产生式的lua函数，使用冒号:与产生式隔开。\n\n最后一行使用分号;结束这条产生式的定义。\n\n例如\n\n```\n: valid-parse-structure\n\tdeclaration : process_declaration\n;\n```\n\n上述代码定义了一个产生式`valid-parse-structure -\u003e declaration`，并由`process_declaration`函数进行处理。\n\n当多条产生式具有相同的左端时，它们需要写在一起。例如\n\n```\n: valid-parse-structure\n\tvalid-parse-structure valid-parse-structure : process_valid_parse_structure\n\tdeclaration : process_declaration\n\tstatement : process_statement\n\tfunction-definition : process_helper_directcopy\n;\n```\n定义了4条产生式，分别为\n\n```\nvalid-parse-structure -\u003e valid-parse-structure valid-parse-structure\nvalid-parse-structure -\u003e declaration\nvalid-parse-structure -\u003e statement\nvalid-parse-structure -\u003e function-definition\n```\n\n更详细的例子请参考example/1.dparse。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdontpanic92%2Fdparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdontpanic92%2Fdparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdontpanic92%2Fdparse/lists"}