{"id":27185985,"url":"https://github.com/bdusell/cminor","last_synced_at":"2025-10-08T21:23:08.755Z","repository":{"id":12517214,"uuid":"15187015","full_name":"bdusell/cminor","owner":"bdusell","description":"A compiler for a small C-like language.","archived":false,"fork":false,"pushed_at":"2021-01-12T14:14:07.000Z","size":518,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-08-04T07:40:04.048Z","etag":null,"topics":["compiler","java","javacup","jflex"],"latest_commit_sha":null,"homepage":"","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/bdusell.png","metadata":{"files":{"readme":"README","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":"2013-12-14T14:42:41.000Z","updated_at":"2022-10-24T04:50:59.000Z","dependencies_parsed_at":"2022-09-16T04:10:50.999Z","dependency_job_id":null,"html_url":"https://github.com/bdusell/cminor","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fcminor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fcminor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fcminor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bdusell%2Fcminor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bdusell","download_url":"https://codeload.github.com/bdusell/cminor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248083598,"owners_count":21045122,"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":["compiler","java","javacup","jflex"],"created_at":"2025-04-09T17:55:58.377Z","updated_at":"2025-10-08T21:23:08.642Z","avatar_url":"https://github.com/bdusell.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"==== DESCRIPTION ====\n\nThis is a Java-implemented compiler for a miniature programming language called\n\"C Minor.\" The Makefile generates a Java program which reads C Minor code as\ninput and prints compiled AT\u0026T-syntax x86 assembly code as output, or else\nreports errors on ill-formed input.\n\nThis project was completed on May 10, 2013 for a university compilers course.\nIt is released under an MIT license, except for any library source code covered\nby its own license.\n\n==== DEPENDENCIES ====\n\nThe Java Cup (java_cup/) and JFlex (jflex/) tools are used to generate the\ncompiler's lexer and parser classes and are both included with this project in\nconformance with their respective licenses.\n\nSee:\n\thttp://www2.cs.tum.edu/projects/cup/\n\thttp://jflex.de/\n\nThis project was developed in a Linux environment, and although the source code\nis written in portable Java, the peripheral scripts and Makefile may depend on\ncommands or files not present on every system. These include dot, tempfile,\ngnome-open.\n\nOf course, you must have javac, java, and make installed to compile and execute\nthe program (ant is not used).\n\n==== BUILDING ====\n\nThe Makefile provided contains rules for generating the C minor compiler from\nJFlex, Java Cup, and java source files as well as rules for compiling test\ninputs using the generated compiler. All of the compiler code resides in the\ncminor Java package, and the main class which serves as the C Minor compiler is\ncminor.Compiler.\n\nIn order to build cminor.Compiler from its sources, simply use\n\n\t% make\n\n==== RUNNING ====\n\nOnce the compiler has been built, it is invoked using\n\n\t% java cminor.Compiler [options]\n\nThe C Minor compiler has a number of different options and modes. These options\ncan be used to control whether the compiler reads from stdin or from a file,\nwrites code to stdout or a file, and generates x86 code or dot code for\nvisualizing the abstract syntax tree. Without any arguments the compiler reads\nC Minor from stdin and sends compiled x86 code to stdout if the input is valid.\nIn order to see all of the available options, use\n\n\t% java cminor.Compiler -h\n\n==== TESTING ====\n\nThe project comes with a number of tests which were used to validate the\nbehavior and features of the compiler. These files are all under the test/\ndirectory. The directory test/ast/ contains a set of about 40 tests which\ntest various features of the compiler. For any test file in this directory,\nuse\n\n\t% make test/ast/\u003cfilename\u003e\n\nto attempt to use the C Minor compiler to produce x86 code from the\ncorresponding .cm file, assemble it, and link it into an executable.\n\nThere is another test in the test/ms/ directory which pulls together several\naspects of the project. It is the Fibonacci program provided for the syntax\nanalysis phase of the project. To compile it, use\n\n\t% make test/ms/test\n\nand then use\n\n\t% ./test/ms/test\n\nto verify that it prints out the first 20 or so Fibonacci numbers.\n\nThe scripts/ directory contains a number of scripts which abbreviate certain\nmodes of the C Minor compiler to a single command. For example, the script\nscripts/resolve reads a C Minor file, prints its contents, and uses the C Minor\ncompiler to generate dot code for displaying the abstract syntax tree of the\ninput program including nodes for resolved symbols. It then uses the dot\ncommand to produce an image of the tree and opens it in the user's preferred\napplication.\n\n==== IMPLEMENTATION NOTES ====\n\nThe compiler is written in Java and makes extensive use of the visitor pattern.\nThis design decision is a result of the benefits of having closely-related code\nfor each compiler phase kept in the same class file instead of spread out\naccross several abstract syntax tree node class files.\n\nThe project is separated into the following phases:\n\n\t1. Lexing (sends tokens to the parser using jflex)\n\t2. Parsing (builds an abstract syntax tree using java_cup)\n\t3. Symbol resolution (resolves identifiers and other symbols in the\n\t   AST)\n\t4. Type checking (resolves and validates expression types and performs\n\t   other semantic analyses)\n\t5. Code generation (assuming the AST has been fully validated and\n\t   resolved, proceeds to generate x86 code)\n\nFor the sake of simplicity, the generated code simulates a stack machine. It\nshould be considered pre-optimization assembly code. All return and expression\nvalues are passed through %eax; all function arguments are passed through the\nstack.\n\n==== STATUS ====\n\nAll required functionality currently appears to be working. There is, of\ncourse, no guarantee that the compiler or the programs which it generates will\nnot bug out unexpectedly, but the experience of using them so far suggest that\nthe compiler is generally quite sound. It works on all test programs provided.\n\nThe compiler implements (or at least supposes to implement) the following\nfeatures:\n\n\t- Error checking during the scanning phase\n\t- Error recovery during the parsing phase\n\t- Location information for errors in the input and descriptive error\n\t  messages for semantic errors\n\t- Validation that a main function exists with the correct signature\n\t- Validation that functions with non-void return types return values in\n\t  all branches of execution\n\t- Detection of unreachable statements\n\t- Use of a string table to minimize the number of string literals\n\t  included in the resulting program\n\t- Packing of constant values into the format strings used by the calls\n\t  to printf which underlie print statements\n\t- Ensurance that the literal arguments to print cannot be used to\n\t  insert extra format specifiers that break the underlying printf\n\t  implementation\n\t- Printing of \"true\" and \"false\" for boolean values\n\t- Implementation of lexical scoping rules\n\t- Control flow statements if, else, and while\n\t- Short-circuited logical operators\n\t- Awesomeness\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdusell%2Fcminor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbdusell%2Fcminor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbdusell%2Fcminor/lists"}