{"id":19733756,"url":"https://github.com/h2337/cparse","last_synced_at":"2025-08-13T06:41:45.111Z","repository":{"id":63178543,"uuid":"564014607","full_name":"h2337/cparse","owner":"h2337","description":"cparse is an LR(1) and LALR(1) parser generator","archived":false,"fork":false,"pushed_at":"2025-07-19T17:03:32.000Z","size":55,"stargazers_count":51,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-04T08:58:44.127Z","etag":null,"topics":["c","compiler","compiler-construction","compiler-frontend","compilers","lalr","lalr-parser","lalr-parser-generator","lalr1","lr1","lr1-parser","parser","parser-combinator","parser-combinators","parser-framework","parser-generator","parser-library","parsing"],"latest_commit_sha":null,"homepage":"","language":"C","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/h2337.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":"2022-11-09T20:10:43.000Z","updated_at":"2025-07-19T17:03:39.000Z","dependencies_parsed_at":"2024-12-18T20:43:21.076Z","dependency_job_id":null,"html_url":"https://github.com/h2337/cparse","commit_stats":null,"previous_names":["h2337/cparse","hikmat2337/cparse","jafarlihi/cparse"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/h2337/cparse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2337%2Fcparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2337%2Fcparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2337%2Fcparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2337%2Fcparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/h2337","download_url":"https://codeload.github.com/h2337/cparse/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/h2337%2Fcparse/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270197932,"owners_count":24543466,"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-08-13T02:00:09.904Z","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":["c","compiler","compiler-construction","compiler-frontend","compilers","lalr","lalr-parser","lalr-parser-generator","lalr1","lr1","lr1-parser","parser","parser-combinator","parser-combinators","parser-framework","parser-generator","parser-library","parsing"],"created_at":"2024-11-12T00:33:29.386Z","updated_at":"2025-08-13T06:41:45.088Z","avatar_url":"https://github.com/h2337.png","language":"C","readme":"\u003cimg align=\"right\" src=\"https://github.com/h2337/file-hosting/blob/b51468695319c3768e08ea2f11fcda6bca61551d/cparse2.png?raw=true\"\u003e\n\n## TOC\n\n* [Overview](#overview)\n* [Example](#example)\n\n## Overview\n\n\u003e :warning: cparse is still under development and code is unpolished.\n\ncparse is an LR(1) and LALR(1) parser generator for C.\n\ncparse uses [`clex`](https://github.com/h2337/clex) lexer generator for lexical analysis purposes.\n\nNote that LR(1) parsers are memory-intensive (and there are memory leaks...), so something like full C grammar can require up to 4GBs of free RAM. If you don't have RAM to spare then use the LALR(1) parser, which also happens to get constructed faster but might not support some of the grammars that LR(1) does (though in practice most programming language grammars are LALR(1)-compatible).\n\n## Example\n\n```c\n#include \"cparse.h\"\n#include \"clex/clex.h\"\n#include \u003cstdio.h\u003e\n#include \u003cassert.h\u003e\n#include \u003cstring.h\u003e\n\n// Create an enum for token types\ntypedef enum TokenKind {\n  RETURN,\n  SEMICOL,\n  IDENTIFIER,\n} TokenKind;\n\n// Provide a string representation for each token type to be used in the grammar\nconst char * const tokenKindStr[] = {\n  [RETURN] = \"RETURN\",\n  [SEMICOL] = \"SEMICOL\",\n  [IDENTIFIER] = \"IDENTIFIER\",\n};\n\nint main(int argc, char *argv[]) {\n  // Register your token types with `clex`\n  clexRegisterKind(\"return\", RETURN);\n  clexRegisterKind(\";\", SEMICOL);\n  clexRegisterKind(\"[a-zA-Z_]([a-zA-Z_]|[0-9])*\", IDENTIFIER);\n\n  // Write your grammar\n  char grammarString[] =\n    \"S -\u003e A IDENTIFIER SEMICOL\\n\"\n    \"A -\u003e RETURN\";\n\n  // Parse your grammar\n  Grammar *grammar = cparseGrammar(grammarString);\n  // Construct an LALR(1) parser\n  LALR1Parser *parser = cparseCreateLALR1Parser(grammar, tokenKindStr);\n\n  // Or construct an LR(1) parser\n  //LR1Parser *parser = cparseCreateLR1Parser(grammar, tokenKindStr);\n\n  // Test if given input is valid within the grammar\n  assert(cparseAccept(parser, \"return id1;\") == true);\n\n  // Parse a given input and get a parse tree\n  ParseTreeNode *node = cparse(parser, \"return id1;\");\n\n  // Use your parse tree\n  assert(strcmp(node-\u003evalue, \"S\") == 0);\n  assert(strcmp(node-\u003echildren[0]-\u003evalue, \"SEMICOL\") == 0);\n  assert(node-\u003echildren[0]-\u003etoken.kind == SEMICOL);\n  assert(strcmp(node-\u003echildren[0]-\u003etoken.lexeme, \";\") == 0);\n  assert(strcmp(node-\u003echildren[1]-\u003evalue, \"IDENTIFIER\") == 0);\n  assert(node-\u003echildren[1]-\u003etoken.kind == IDENTIFIER);\n  assert(strcmp(node-\u003echildren[1]-\u003etoken.lexeme, \"id1\") == 0);\n  assert(strcmp(node-\u003echildren[2]-\u003evalue, \"A\") == 0);\n  assert(strcmp(node-\u003echildren[2]-\u003echildren[0]-\u003evalue, \"RETURN\") == 0);\n  assert(node-\u003echildren[2]-\u003echildren[0]-\u003etoken.kind == RETURN);\n  assert(strcmp(node-\u003echildren[2]-\u003echildren[0]-\u003etoken.lexeme, \"return\") == 0);\n}\n```\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2337%2Fcparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fh2337%2Fcparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fh2337%2Fcparse/lists"}