{"id":22458868,"url":"https://github.com/s1998/compiler","last_synced_at":"2025-03-27T14:17:07.601Z","repository":{"id":67610878,"uuid":"120351109","full_name":"s1998/compiler","owner":"s1998","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-21T05:38:34.000Z","size":1292,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-01T18:27:25.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/s1998.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-05T19:27:26.000Z","updated_at":"2018-09-30T17:01:58.000Z","dependencies_parsed_at":"2023-02-20T19:46:19.534Z","dependency_job_id":null,"html_url":"https://github.com/s1998/compiler","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/s1998%2Fcompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1998%2Fcompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1998%2Fcompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s1998%2Fcompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s1998","download_url":"https://codeload.github.com/s1998/compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858881,"owners_count":20684062,"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":[],"created_at":"2024-12-06T08:42:03.384Z","updated_at":"2025-03-27T14:17:07.581Z","avatar_url":"https://github.com/s1998.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# COMPILER\n\nCompiler for a small-C like language.\n\n## Getting Started\n\nCompiler for a small-C like language, will generate intermediate and assembly code (8085). Supports following grammar : \n\n```\nstmts -\u003e stmt stmts | epsilon\nstmt  -\u003e id := expr | if expr then stmt | while expr do stmt | begin stmts end\nexpression -\u003e term_prime relop expression | term_prime\nterm_prime -\u003e term + term_prime | term - term_prime | term\nterm -\u003e factor * term | factor / term | factor\nfactor -\u003e num | id | ( expression )\n```\n\n\n## Running the sample code\n\nTo run code, write in samplecode file and execute code_gen_advamced.\nThe generated intermediate code is saved in intermediate_code.\nSample test cases are present in sample_test. \nCode :\n```\nz := a + b * (c + d);\n```\n\nSample of parse tree generated is :\n\n```\nstatements\n    statement\n        ID := \n            expression\n                term_prime\n                    term\n                        factor\n                            Num or ID \n                    arithmetic_op +\n                    term\n                        factor\n                            Num or ID \n                        arithmetic_op *\n                        factor\n                            (\n                                expression\n                                    term_prime\n                                        term\n                                            factor\n                                                Num or ID \n                                        arithmetic_op +\n                                        term\n                                            factor\n                                                Num or ID \n                            )\n```\n\n### Output printed\n\nOutput printed contains symbol table, parse tree and assembly code.\n\nSample code used is :\n```\na := 1;\n``` \n\nOutput is :\n```\nstatements\n    statement\n        ID := \n            expression\n                term_prime\n                    term\n                        factor\n                            Num or ID \nparse tree ends\n\n\n\n\nSymbol table : \n_1 15 \n_a 14 \n\n\n\n\n\nLDA _a\nMOV B A\nMOV C _1\nMOV B C\nMOV A B \nSDA _a\n```\n\n## Implementation details \n\nSymbol table is stored using linked list.\n\nHashmap is used to store the ending pairs of if-fi, while-do-done and begin-end. \n\nFiles :\nlex.h and lex.c : Used for lexical analysis.\ncode_gen_advanced.c : Used to generate the assembly code.\nhashmap.c and list.c : Used for hashmap and list implementation.\n\n## References\nFor hashmap, source : http://www.kaushikbaruah.com/posts/data-structure-in-c-hashmap/\nInitial (basic) source code was given as part of assignment of cs347.\n\n## Contributors\nAnkit Kumar Singh, Shubhanshu Verma, Sudhanshu Ranjan.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1998%2Fcompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs1998%2Fcompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1998%2Fcompiler/lists"}