{"id":16615549,"url":"https://github.com/domiii/sdt-for-javac","last_synced_at":"2025-06-29T13:04:27.546Z","repository":{"id":137713282,"uuid":"170007138","full_name":"Domiii/sdt-for-javac","owner":"Domiii","description":"Syntax-Directed Translation for Javac: Modified Javac to compile a new language (C-Minus-Minus) [from 2011]","archived":false,"fork":false,"pushed_at":"2019-02-11T11:44:35.000Z","size":1912,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T01:52:52.067Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/Domiii.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":"2019-02-10T17:48:23.000Z","updated_at":"2024-05-28T19:07:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"27a36e8b-2013-4adf-b7c7-4281a0926711","html_url":"https://github.com/Domiii/sdt-for-javac","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Domiii/sdt-for-javac","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Domiii%2Fsdt-for-javac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Domiii%2Fsdt-for-javac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Domiii%2Fsdt-for-javac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Domiii%2Fsdt-for-javac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Domiii","download_url":"https://codeload.github.com/Domiii/sdt-for-javac/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Domiii%2Fsdt-for-javac/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262598167,"owners_count":23334669,"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-10-12T02:09:46.436Z","updated_at":"2025-06-29T13:04:27.516Z","avatar_url":"https://github.com/Domiii.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sdt-for-javac [from 2011]\nSyntax-Directed Translation for Javac: Modified Javac to compile a new language (C-Minus-Minus).\n\n## Main Points\n* In this project I modified Javac (`openjdk-6-src-b22-28_feb_2011`) for building a compiler-compiler using [Syntax-Directed Translation (SDT)](https://www.google.com/search?safe=off\u0026rlz=\u0026q=syntax+directed+translation).\n* I added a new construct to the Javac parser called `grammar`, representing a full-fledged Syntax-Directed Definition which maps a [CFG](https://en.wikipedia.org/wiki/Context-free_grammar) to its production rules\n  * You can find the new `grammar` construct [here in the javac source code](https://github.com/Domiii/sdt-for-javac/tree/master/javac/com/sun/tools/javac/parser/grammar)\n* I then used that `grammar` to build a compiler for a simple language called C-Minus-Minus (short: CMM) [[CMM specs pdf](https://github.com/Domiii/sdt-for-javac/blob/master/cmm_def.pdf)] [[CMM samples](https://github.com/Domiii/sdt-for-javac/tree/master/cmm_samples)] [[my CMM compiler source code](https://github.com/Domiii/sdt-for-javac/tree/master/compiler/src/edu/ntu/compilers/lab4)] and convert it to a proprietary assembly language called `BASS` ([BASS documentation + examples](https://github.com/Domiii/sdt-for-javac/tree/master/bass)).\n* I even [patched a bug](https://github.com/Domiii/sdt-for-javac/blob/master/project/bugfix/bugfix.txt) in Javac (enum parsing was broken) that was in that build (`openjdk-6-src-b22-28_feb_2011`) [[official download link](http://download.java.net/openjdk/jdk6/promoted/b22/openjdk-6-src-b22-28_feb_2011.tar.gz)]\n* Within my CMM compiler, the language is defined in [the CMMGrammar](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/cmmgrammar/CMMGrammar.java).\n    * NOTE: You see this right - This `.java` file does not contain a `class`, `interface` etc... but instead it defines a `public grammar CMMGrammar` - That is why I had to make modifications to Javac! 😊\n\n\n## Compiler Steps\nThe [CMMCompiler](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/cmmcompiler/CMMCompiler.java) uses the [CMMGrammar](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/cmmgrammar/CMMGrammar.java) to compile everything in a few simple steps.\n1. The [CMMParser](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/parser/CMMParser.java#L103) builds the AST, based on the Grammar rules\n    * The parser internally calls the [Scanner](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/scanner/Scanner.java) which generates a token stream\n1. When the AST is ready, we start running through it and execute the grammar-defined rules.\n    * The `grammar` can define an arbitrary amount of `grammarpasses`, and [the CMMGrammar](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/cmmgrammar/CMMGrammar.java) defines two, each with their own production rules (code to be executed when matching the lefthand-side patterns in the AST): `prep0` to prepare everything and `gen` to generate code (using [the Gen class](https://github.com/Domiii/sdt-for-javac/blob/master/compiler/src/edu/ntu/compilers/lab4/cmmcompiler/Gen.java))\n1. The CMMGrammar is only 724 lines long (including comments!). Our modification to the Javac parser then takes that and converts it into a regular Java class before letting the Javac code generator worry about the rest.\n    * NOTE: You find that [the equivalent `CMMGrammar` class](https://github.com/Domiii/sdt-for-javac/blob/master/project/cmmsrc/edu/ntu/compilers/lab4/cmmgrammar/CMMGrammar.java) emitted by our modified Javac has over 5000 lines, that's almost 7 times as many lines, and does contain any comments!\n1. I then used this compiler to successfully compile [these 7 sample CMM programs](https://github.com/Domiii/sdt-for-javac/tree/master/cmm_samples) to [BASS assembly code](https://github.com/Domiii/sdt-for-javac/tree/master/bass)\n\nYou can find the initial proposal and 2011 [final report](https://github.com/Domiii/sdt-for-javac/blob/master/project/report.pdf) [in this folder](https://github.com/Domiii/sdt-for-javac/tree/master/project).\nNOTE: The report was not very well written (I loved coding those thousands of lines, but report writing I did not enjoy back then...)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdomiii%2Fsdt-for-javac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdomiii%2Fsdt-for-javac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdomiii%2Fsdt-for-javac/lists"}