{"id":21176803,"url":"https://github.com/justanothercoder/compiler","last_synced_at":"2025-09-19T17:25:30.572Z","repository":{"id":15563618,"uuid":"18298874","full_name":"justanothercoder/Compiler","owner":"justanothercoder","description":"Compiler","archived":false,"fork":false,"pushed_at":"2015-03-21T20:26:04.000Z","size":2020,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-14T18:36:27.155Z","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/justanothercoder.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}},"created_at":"2014-03-31T15:54:51.000Z","updated_at":"2020-11-04T16:00:24.000Z","dependencies_parsed_at":"2022-09-24T03:12:52.068Z","dependency_job_id":null,"html_url":"https://github.com/justanothercoder/Compiler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/justanothercoder/Compiler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justanothercoder%2FCompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justanothercoder%2FCompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justanothercoder%2FCompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justanothercoder%2FCompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justanothercoder","download_url":"https://codeload.github.com/justanothercoder/Compiler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justanothercoder%2FCompiler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275974490,"owners_count":25562667,"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","status":"online","status_checked_at":"2025-09-19T02:00:09.700Z","response_time":108,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-20T17:05:27.302Z","updated_at":"2025-09-19T17:25:30.519Z","avatar_url":"https://github.com/justanothercoder.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Rainbow \n========\n\nThe aim of this project is to build a compiler for the Rainbow language and produce correct x86 Linux assembly code for it.\n\n###Algorithms and techological side.\n\nThere are several phases of compilation such as:\n\n1. Lexical analysis.\n2. Syntax analysis and IR generation.\n3. Semantic analysis.\n4. TAC generation. \n5. Optimization.\n6. Assembly generation.\n\nOn the first stage some kind of finite automaton is used. Lexical analysis is needed to divide the text of a program into tokens - minimal units of syntax.\n\nNext stage is parsing. On this stage the backtracking *LL(k)* parser is the main idea.\nIt is used to make sure that program is syntactically correct and transform it to the internal representation.\nThis representation has form of abstract syntax tree (AST). \n\nOn the next stage of compilation semantic analysis is performed. We take the several in-order traversals through the AST to make sure that all needed symbols are defined, all function calls can be performed, and to check the types.\n\nThe next stage is Three-Address Code (TAC) generation which is primarily used to perform optimization. Optimization currently consists of constant propagation and elimination of unused variables and temporaries.\n\nThe last stage is code generation. This is performed by mapping TAC instructions to assembly instructions. The output of this phase is the final assembly code, that can be turned into object code with **_nasm_** and then linked with **_ld_**, for example.\n\n###User guide\n\nAll you need is to compile the source into the executable. For this you need **_make_** and **_clang_** that supports the _C++14_.\n\nThen you need to execute in shell such command as\n```bash\n$ [executable_name] [program_name]\n```\n\nThe language is quite simple, there are several examples.\n\n* Comments\n\n```\n// This is one-line commnet\n\n/*\n  This is multi-line comment\n*/\n```\n\n* Function definition\n\n```\ndef f(int x, int y) : int {\n  //code\n}\n\ntemplate \u003cclass T, class U\u003e\ndef f(U x) : T {\n  //code\n}\n```\n\n* Struct definition\n\n```\nstruct A {\n  //functions and variables and structures\n}\n\ntemplate \u003cclass T, class U\u003e // template metaprogramming like in C++\nstruct B {\n  //functions and variables and structures\n}\n```\n\n* Control structures\n\n```\nif ( cond ) {\n  //code if cond\n}\nelse { //optional\n  //code if not cond\n}\n\nwhile ( cond ) { \n  //code\n}\n\nfor ( init; cond; step ) { //all three are optional, but here semicolons are mandatory\n  //code;\n}\n```\n\n* Import\n\n```\nimport libname\nfrom libname import something\n```\n\n* New\n\n```\n\n//Like in Java and C#\n\nstruct A \n{\n  def A() {\n  \n  }\n}\n\nnew A\nnew A() \n\n```\n\n##Standart Library\n\n1. _ASCII_ strings\n2. Arrays\n3. Heap allocation\n4. Buffered IO\n\nMore containers are in plans.\nAs for language core, this will soon be ready: first-class functions, lambda expressions, improved import system, JIT compilation.\n\n\n###Developer Guide\n  \nThere are several main classes that do most of the work.\n* Lexer (divides input in tokens)\n* Parser (does all the parsing)\n* AST (base class for all AST nodes)\n* ExprNode (base class for all expressions and child of AST)\n* ExpandTemplatesVisitor (expands templates)\n* DefineVisitor (defines symbols)\n* CheckVisitor (perform semantic analysis)\n* GenSSAVisitor (generates TAC)\n* ThreeAddressCode (code)\n* Optimizer (performs optimization)\n\nIf you want to add something new you should change one of this classes and possibly add a new node as a child of AST class.\n\nYou can also expand the standart library of the Rainbow, adding new classes and functions to stdlib/. \nHowever, there can be very platform-specific things, that need to be coded in assembly language. Then you should write it and recompile the library.\n\n\n###References\n\nBooks:\n\n* Language Implementation Patterns, Terence Parr\n* Let's build a compiler, Jack Crensaw\n* Basics of compiler design, Torben Mogensen\n* Compilers: Principles, Techniques, and Tools, Alfred Aho, Jeffrey Ullman \n\nReference:\n\n* http://en.cppreference.com/\n\nInspired by C++, D and Python\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustanothercoder%2Fcompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustanothercoder%2Fcompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustanothercoder%2Fcompiler/lists"}