{"id":20892734,"url":"https://github.com/chichunchen/cal-transpiler","last_synced_at":"2025-03-12T19:13:04.164Z","repository":{"id":83883780,"uuid":"104538231","full_name":"chichunchen/cal-transpiler","owner":"chichunchen","description":"Syntax error recovery for an extended version of the calculator language. For more details, check README.pdf.","archived":false,"fork":false,"pushed_at":"2017-10-11T23:33:45.000Z","size":222,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-19T11:43:31.335Z","etag":null,"topics":["parsers","programming-language","semantic-checks","syntax-tree","translator"],"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/chichunchen.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":"2017-09-23T03:23:34.000Z","updated_at":"2020-04-21T08:52:56.000Z","dependencies_parsed_at":"2023-03-13T20:04:59.246Z","dependency_job_id":null,"html_url":"https://github.com/chichunchen/cal-transpiler","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/chichunchen%2Fcal-transpiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chichunchen%2Fcal-transpiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chichunchen%2Fcal-transpiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chichunchen%2Fcal-transpiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chichunchen","download_url":"https://codeload.github.com/chichunchen/cal-transpiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243277501,"owners_count":20265352,"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":["parsers","programming-language","semantic-checks","syntax-tree","translator"],"created_at":"2024-11-18T10:13:48.663Z","updated_at":"2025-03-12T19:13:04.143Z","avatar_url":"https://github.com/chichunchen.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# calculator language transpiler\n\n### Feature\n\n- Parse extended caculator with top-down descent approach\n- Syntax Error Detection/Recovery\n    - Exception based\n    - Context specific look ahead for immediate error detection\n- Construct AST\n- Static semantic check for do/check\n    - Every check statement appears inside a do statement\n    - Every do statement has at least one check statement that is inside it and not inside any nested do. \n- Translate to C\n\n### Extended Grammar\n\n- Here the new nonterminal R is meant to suggest a “relation.”\nAs in C, a value of 0 is taken to be false; anything else is true.\n- The relational operators (==, \u003c\u003e [not equal], \u003c, \u003e, \u003c=, and \u003e=) produce either 0 or 1 when evaluated.\n- A do loop is intended to iterate until some check-ed relation inside it evaluates to false— “check R” is analogous to “if (!R) break” in C.\n\n```\nP   →   SL $$\nSL  →   S SL  |  ε\nS   →   id := R  |  read id  |  write R  |  if R SL fi  |  do SL od  |  check R\nR   →   E ET\nE   →   T TT\nT   →   F FT\nF   →   ( R )  |  id  |  lit\nET  →   ro E  |  ε\nTT  →   ao T TT  |  ε\nFT  →   mo F FT  |  ε\nro  →   ==  |  \u003c\u003e  |  \u003c  |  \u003e  |  \u003c=  |  \u003e=\nao  →   +  |  -\nmo  →   *  |  /\n```\n\n### Sample Input\n```\nread n\ncp := 2\ndo check n \u003e 0\n   found := 0\n   cf1 := 2\n   cf1s := cf1 * cf1\n   do check cf1s \u003c= cp\n       cf2 := 2\n       pr := cf1 * cf2\n       do check pr \u003c= cp\n           if pr == cp\n               found := 1\n           fi\n           cf2 := cf2 + 1\n           pr := cf1 * cf2\n       od\n       cf1 := cf1 + 1\n       cf1s := cf1 * cf1\n   od\n   if found == 0\n       write cp\n       n := n - 1\n   fi\n   cp := cp + 1\nod\n$$  \u003c--- do not need to write in the file I guess\n```\n\n### AST Output\n```\n(program\n  [ (read \"n\")\n    (:= \"cp\" (num \"2\"))\n    (do\n      [ (check \u003e (id \"n\") (num \"0\"))\n        (:= \"found\" (num \"0\"))\n        (:= \"cf1\" (num \"2\"))\n        (:= \"cf1s\" (* (id \"cf1\") (id \"cf1\")))\n        (do\n          [ (check \u003c= (id \"cf1s\") (id \"cp\"))\n            (:= \"cf2\" (num \"2\"))\n            (:= \"pr\" (* (id \"cf1\") (id \"cf2\")))\n            (do\n              [ (check \u003c= (id \"pr\") (id \"cp\"))\n                (if\n                  (== (id \"pr\") (id \"cp\"))\n                  [ (:= \"found\" (num \"1\"))\n                  ]\n                )\n                (:= \"cf2\" (+ (id \"cf2\") (num \"1\")))\n                (:= \"pr\" (* (id \"cf1\") (id \"cf2\")))\n              ]\n            )\n            (:= \"cf1\" (+ (id \"cf1\") (num \"1\")))\n            (:= \"cf1s\" (* (id \"cf1\") (id \"cf1\")))\n          ]\n        )\n        (if\n          (== (id \"found\") (num \"0\"))\n          [ (write (id \"cp\"))\n            (:= \"n\" (- (id \"n\") (num \"1\")))\n          ]\n        )\n        (:= \"cp\" (+ (id \"cp\") (num \"1\")))\n      ]\n    )\n  ]\n)\n```\n\n\n### Tests\nMakefile test the output of ast and static semantic check.\n```\n./parse \u003c test01.txt \u003e output01.txt               \ndiff --ignore-all-space correct01.txt output01.txt\n./parse \u003c test02.txt \u003e output02.txt               \ndiff --ignore-all-space correct02.txt output02.txt\n./parse \u003c test03.txt \u003e output03.txt               \ndiff --ignore-all-space correct03.txt output03.txt\n./parse \u003c test04.txt \u003e output04.txt               \ndiff --ignore-all-space correct04.txt output04.txt\n```\n\n### Error Detector\n- test from Michael's mail\n```\nsum := ( x x \u003c yy )\n(program\n[ (:= \"sum\"Expression Exception: error in line number: 1\nfollow:  in lineno: 1, token: lt\nExpression Exception: error in line number: 2\ndeleting token: eof, error in lineno: 2\n\nmatch error in line: 2 , get eof, insert: rparen\n  (\u003c (id \"x\") (id \"yy\")))\n]\n)\n```\n- test06\n```\nread a read b read c write ( a * ( b + c\n(program\n[ (read \"a\")\n(read \"b\")\n(read \"c\")\n(writeExpression Exception: error in line number: 1\ndiscard token: eof, error in lineno: 1\nExpression Exception: error in line number: 1\ndiscard token: eof, error in lineno: 1\n  (* (id \"a\")  (+ (id \"b\") (id \"c\"))))\n]\n)\n```\n- test07\n```\nY := (A * X write A * B\n(*  (* (id \"A\") (id \"X\")) (id \"B\")))\n```\n- test08\n```\n(program\n[ (read \"a\")\n(read \"b\")\n(:= \"Y\"Relation Exception , line number: 1\nfirst: in lineno: 1, token: a\n (* (id \"a\") (id \"b\")))\n]\n)\n```\n- test09\n```\n(program                                                                                 \n[ (read \"a\")                                                                             \n(write  (add (id \"a\")  (mul (num \"4\") (num \"5\"))))                                      \n(write (num \"3\"))                                                                     \n]                                                                   \n)\n```\n### For More Details such as context specific error detction\nplease see README.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchichunchen%2Fcal-transpiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchichunchen%2Fcal-transpiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchichunchen%2Fcal-transpiler/lists"}