{"id":16469780,"url":"https://github.com/vinitkumar/mini-c-compiler","last_synced_at":"2026-03-14T20:47:39.963Z","repository":{"id":25696908,"uuid":"29133209","full_name":"vinitkumar/mini-c-compiler","owner":"vinitkumar","description":"C compiler written by Mr. Atul Varma","archived":false,"fork":false,"pushed_at":"2023-08-16T16:30:34.000Z","size":280,"stargazers_count":18,"open_issues_count":2,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T19:55:10.703Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/toolness","language":"Python","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/vinitkumar.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}},"created_at":"2015-01-12T11:52:11.000Z","updated_at":"2024-07-06T07:27:08.000Z","dependencies_parsed_at":"2024-02-03T21:46:59.172Z","dependency_job_id":null,"html_url":"https://github.com/vinitkumar/mini-c-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/vinitkumar%2Fmini-c-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitkumar%2Fmini-c-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitkumar%2Fmini-c-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinitkumar%2Fmini-c-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinitkumar","download_url":"https://codeload.github.com/vinitkumar/mini-c-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"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-11T12:08:52.070Z","updated_at":"2026-03-14T20:47:34.919Z","avatar_url":"https://github.com/vinitkumar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[Atul](https://github.com/toolness)'s Mini-C Compiler\r\nJune 2, 2004\r\n\r\nThis is a compiler for a subset of the C programming language. It was\r\nwritten in Python during the spring of 2004.\r\n\r\nThe lexer and parser were constructed using Dave Beazley's PLY (Python\r\nLex-Yacc), an open-source Python implementation of GNU\r\nlex/yacc. Stages of compilation (symbol tree generation, type\r\nchecking, flow control checking, etc) are performed using an\r\nobject-oriented design pattern called a visitor (GoF 1995). The output\r\nis annotated Intel 80x86 assembly, suitable for translation to machine\r\nlanguage using the GNU Assembler (GAS).\r\n\r\n---------------------------------------------------------------\r\nLANGUAGE FEATURES\r\n---------------------------------------------------------------\r\n\r\nThe subset of the C language implemented here includes:\r\n\r\n    * Functions, variables (local and global), and character and\r\n      string literals.\r\n\r\n    * Assignments (=, +=, etc), standard arithmetic binary and unary\r\n      operators (+,-,*, etc), logical binary and unary operators (!,\r\n      ==, \u003c, etc).\r\n\r\n    * Support for the C datatypes char and int, as well as implicit\r\n      type conversion between the two (warnings are raised in\r\n      situations of potential data loss). int variables are assumed to\r\n      be signed, and char variables are assumed to be unsigned (this\r\n      is not a violation of the ANSI C standard).\r\n\r\n    * Control flow elements including while and for loops,\r\n      if/then/else conditionals, and recursion.\r\n\r\n    * Support for the C keywords extern for functions and variables,\r\n      and static for functions.\r\n\r\n    * Pointers, including pointer dereferencing (the * operator),\r\n      multiple levels of indirection (double pointers, triple\r\n      pointers, etc), array indexing notation, and the address-of (\u0026)\r\n      operator.\r\n\r\n---------------------------------------------------------------\r\nFILES AND DIRECTORIES\r\n---------------------------------------------------------------\r\n\r\n    lex.py       - Python Lex (this is part of PLY).\r\n    yacc.py      - Python Yacc (this is part of PLY).\r\n    clex.py      - Mini-C lexer.\r\n    cparse.py    - Mini-C parser.  Contains yacc rules for Mini-C and\r\n                   defines the classes that make up the AST.\r\n    cvisitors.py - Mini-C visitors.  Defines the base visitor class,\r\n                   and concrete visitor classes for printing the AST,\r\n                   doing symbol table generation, type checking, and\r\n                   flow control.\r\n    cx86.py      - Intel 80x86 assembly code generator.  Defines a\r\n                   virtual stack machine class and the code generator\r\n                   visitor.\r\n    c.py         - Front-end to the compiler.  This takes in command-\r\n                   line options and runs the compiler on the filenames\r\n                   you give it.\r\n    samples/     - This directory contains foo.c and foo_lib.c, two\r\n                   C files that can be compiled by the mini-c\r\n                   compiler.  foo_lib.c is intended to be used as\r\n                   a library that foo.c accesses, to show\r\n                   that mini-c generates assembly that can be linked\r\n                   with gcc.\r\n\r\n---------------------------------------------------------------\r\nUSING THE COMPILER\r\n---------------------------------------------------------------\r\n\r\nThe syntax for using the mini-c compiler is as follows:\r\n\r\n    c.py \u003csource-file-1\u003e [[source-file-2] ...] [-ast] [-annotate]\r\n\r\nSource files are the C files you want to compile into assembly (.s\r\nfiles).\r\n\r\nThe '-ast' option generates a file with extension .ast that is a\r\nprintout of the abstract syntax tree for the source file, after\r\nall stages of compilation occur.\r\n\r\nThe '-annotate' option generates annotated assembly.  That is,\r\nassembly is generated with comments describing what each instruction\r\ndoes, its relevance to the original C source code, and so forth.\r\nAdditional comments are inserted to delimit functions, control\r\nstructures, and so forth.\r\n\r\n---------------------------------------------------------------\r\nTHE MAKEFILE\r\n---------------------------------------------------------------\r\n\r\nThe makefile just compiles the two files in the samples/ directory and\r\noutputs an executable called 'foo' into this directory (all other\r\noutput files are also placed here).\r\n\r\nNote that while compiling this, you may receive a bunch of warnings\r\nmentioning something about an \"Illegal character: ''\".  This is just\r\nan artifact of newline translation differences between platforms and\r\nshould be ignored.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinitkumar%2Fmini-c-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinitkumar%2Fmini-c-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinitkumar%2Fmini-c-compiler/lists"}