{"id":22036020,"url":"https://github.com/ashokdey/parserts","last_synced_at":"2025-03-23T12:40:55.231Z","repository":{"id":61902680,"uuid":"544002143","full_name":"ashokdey/ParserTS","owner":"ashokdey","description":"A parser implemented in pure typescript without any dependencies.","archived":false,"fork":false,"pushed_at":"2022-10-28T11:51:49.000Z","size":232,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-28T18:49:41.708Z","etag":null,"topics":["abstract-syntax-tree","parser","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/ashokdey.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}},"created_at":"2022-10-01T11:28:57.000Z","updated_at":"2022-10-30T06:28:13.000Z","dependencies_parsed_at":"2023-01-20T19:48:30.912Z","dependency_job_id":null,"html_url":"https://github.com/ashokdey/ParserTS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashokdey%2FParserTS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashokdey%2FParserTS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashokdey%2FParserTS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashokdey%2FParserTS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashokdey","download_url":"https://codeload.github.com/ashokdey/ParserTS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245104462,"owners_count":20561377,"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","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":["abstract-syntax-tree","parser","typescript"],"created_at":"2024-11-30T10:31:49.859Z","updated_at":"2025-03-23T12:40:55.208Z","avatar_url":"https://github.com/ashokdey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ParserTS \n\n### An AST generator implemented in TypeScript\n\n![Parser](.github/parser.png)\n\n### What Does Parser Mean? \u003csup\u003e\u003ca href=\"https://www.techopedia.com/definition/3854/parser\"\u003esource\u003c/a\u003e\u003c/sup\u003e\n\nA parser is a compiler or interpreter component that breaks data into smaller elements for easy translation into another language. A parser takes input in the form of a sequence of tokens, interactive commands, or program instructions and breaks them up into parts that can be used by other components in programming.\n\nA parser usually checks all data provided to ensure it is sufficient to build a data structure in the form of a parse tree or an abstract syntax tree.\n\nIn order for the code written in human-readable form to be understood by a machine, it must be converted into machine language. This task is usually performed by a translator (interpreter or compiler). The parser is commonly used as a component of the translator that organizes linear text in a structure that can be easily manipulated (parse tree). To do so, it follows a set of defined rules called “grammar”.\n\nThe overall process of parsing involves three stages:\n\n### Lexical Analysis\n\nA lexical analyzer is used to produce tokens from a stream of input string characters, which are broken into small components to form meaningful expressions. A token is the smallest unit in a programming language that possesses some meaning (such as +, -, *, “function”, or “new” in JavaScript).\n\n### Syntactic Analysis\n\nChecks whether the generated tokens form a meaningful expression. This makes use of a context-free grammar that defines algorithmic procedures for components. These work to form an expression and define the particular order in which tokens must be placed.\n\nSemantic Parsing: The final parsing stage in which the meaning and implications of the validated expression are determined and necessary actions are taken.\n\nA parser's main purpose is to determine if input data may be derived from the start symbol of the grammar.\n\n## Examples \n\n```javascript\n\nfunc add(a, b) {\n    return a + b;\n}\n\n```\n\nThe above code will be converted into an AST like: \n\n```json\n\n{\n  \"type\": \"Program\",\n  \"body\": [\n    {\n      \"type\": \"FunctionDeclaration\",\n      \"name\": {\n        \"type\": \"IDENTIFIER\",\n        \"name\": \"add\"\n      },\n      \"params\": [\n        {\n          \"type\": \"IDENTIFIER\",\n          \"name\": \"a\"\n        },\n        {\n          \"type\": \"IDENTIFIER\",\n          \"name\": \"b\"\n        }\n      ],\n      \"body\": {\n        \"type\": \"BlockStatement\",\n        \"body\": [\n          {\n            \"type\": \"ReturnStatement\",\n            \"argument\": {\n              \"type\": \"BinaryExpression\",\n              \"operator\": \"+\",\n              \"left\": {\n                \"type\": \"IDENTIFIER\",\n                \"name\": \"a\"\n              },\n              \"right\": {\n                \"type\": \"IDENTIFIER\",\n                \"name\": \"b\"\n              }\n            }\n          },\n          {\n            \"type\": \"EmptyStatement\",\n            \"body\": null\n          }\n        ]\n      }\n    }\n  ]\n}\n\n```\n\n### Upcoming Developments\n\n- Support for function call\n- Support for Classes and Objects\n- CLI tool\n\n\n### Usages\n\n- Type your code in the `src/index.ts`\n- Run command to produce ast `npm run dev \u003e\u003e ast.json`\n\n### Notes\n\nThanks to [Dmitry Soshnikov](http://dmitrysoshnikov.com/) for his course on [Programming Languages](https://www.dmitrysoshnikov.education/p/programming-languages-design-ultimate-bundle-2nd-edition)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashokdey%2Fparserts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashokdey%2Fparserts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashokdey%2Fparserts/lists"}