{"id":23714178,"url":"https://github.com/aftermath22/oxygen_a-compiled-mini-language","last_synced_at":"2025-08-22T06:44:59.515Z","repository":{"id":270258540,"uuid":"907766306","full_name":"aftermath22/Oxygen_A-Compiled-Mini-Language","owner":"aftermath22","description":"A custom mini language with its own custom compiler built from scratch in modern C++20.","archived":false,"fork":false,"pushed_at":"2024-12-30T08:16:37.000Z","size":1355,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-30T08:48:56.918Z","etag":null,"topics":["arena-allocator","ast","cmake","cpp20","custom-language","error-handling","generation","mini-compiler","nasm","nasm-assembly","oops-in-cpp","parse-tree","parsing","tokenization","wsl"],"latest_commit_sha":null,"homepage":"","language":"C++","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/aftermath22.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":"2024-12-24T10:36:44.000Z","updated_at":"2024-12-30T08:16:40.000Z","dependencies_parsed_at":"2024-12-30T09:31:13.939Z","dependency_job_id":"acf4520b-bbe0-438f-98b7-2f04fcfe4721","html_url":"https://github.com/aftermath22/Oxygen_A-Compiled-Mini-Language","commit_stats":null,"previous_names":["aftermath22/oxygen","aftermath22/oxygen_a-compiled-mini-language"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aftermath22/Oxygen_A-Compiled-Mini-Language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOxygen_A-Compiled-Mini-Language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOxygen_A-Compiled-Mini-Language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOxygen_A-Compiled-Mini-Language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOxygen_A-Compiled-Mini-Language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aftermath22","download_url":"https://codeload.github.com/aftermath22/Oxygen_A-Compiled-Mini-Language/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOxygen_A-Compiled-Mini-Language/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271599871,"owners_count":24787802,"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-08-22T02:00:08.480Z","response_time":65,"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":["arena-allocator","ast","cmake","cpp20","custom-language","error-handling","generation","mini-compiler","nasm","nasm-assembly","oops-in-cpp","parse-tree","parsing","tokenization","wsl"],"created_at":"2024-12-30T20:17:04.868Z","updated_at":"2025-08-22T06:44:59.467Z","avatar_url":"https://github.com/aftermath22.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Oxygen Programming Language\n\nOxygen is a small, compiled programming language that targets x86_64 assembly. It features basic arithmetic operations, variables, control flow, and scoping rules. \\\nI have learned most of the things from a youtube tutorial by 'Pixeled' and this is the [link](https://www.youtube.com/watch?v=vcSijrRsrY0\u0026list=PLUDlas_Zy_qC7c5tCgTMYq2idyyT241qs) to his playlist.\n\n## Table of Contents\n- [Overview](#overview)\n- [Features](#features)\n- [Project Structure](#project-structure)\n- [Building](#building)\n- [Language Syntax](#language-syntax)\n- [Implementation Details](#implementation-details)\n- [Examples](#examples)\n\n## Overview\n\nOXY is implemented in C++ and follows a traditional compiler pipeline:\n1. Lexical Analysis (Tokenization)\n2. Parsing\n3. Code Generation (to x86_64 assembly)\n\nThe compiler outputs assembly code which is then assembled and linked using NASM and LD respectively.\n\n## Features\n\n- Integer arithmetic (addition, subtraction, multiplication, division)\n- Variable declarations and assignments\n- Scoping rules with block-level scope\n- Control flow statements (if, elif, else)\n- Comments (both single-line and multi-line)\n- Exit statements\n\n## Project Structure\n\nThe project consists of several key components:\n\n- `main.cpp`: Entry point that orchestrates the compilation process\n- `tokenization.hpp`: Handles lexical analysis\n- `parser.hpp`: Implements recursive descent parsing\n- `generation.hpp`: Generates x86_64 assembly code\n- `arena.hpp`: Implements a simple memory arena for AST node allocation\n\n### Component Details\n\n#### Arena Allocator\n- Custom memory management system\n- Provides efficient allocation for AST nodes\n- Uses a simple bump allocator approach\n- Supports move semantics but not copying\n\n#### Tokenizer\n- Breaks source code into tokens\n- Handles keywords, identifiers, numbers, and operators\n- Supports both single-line (`//`) and multi-line (`/* */`) comments\n- Tracks line numbers for error reporting\n\n#### Parser\n- Implements recursive descent parsing\n- Builds an Abstract Syntax Tree (AST)\n- Handles operator precedence\n- Provides detailed error messages\n- Uses the arena allocator for memory management\n\n#### Code Generator\n- Generates x86_64 assembly code\n- Implements stack-based variable storage\n- Handles proper scope management\n- Generates efficient arithmetic operations\n- Supports control flow structures\n\n## Building\n\nPrerequisites:\n- C++ compiler with C++20 support\n- NASM assembler\n- LD linker\n\nTo build a program:\n```bash\n# Compile the program\n$ ./oxy input.oxy\n\n# This generates:\n# 1. out.asm (assembly output)\n# 2. out.o (object file)\n# 3. out (executable)\n```\n\n## Language Syntax\n\n### Variables\n```\nlet x = 42;\nx = x + 1;\n```\n\n### Control Flow\n```\nif (condition) {\n    // code\n} elif (other_condition) {\n    // code\n} else {\n    // code\n}\n```\n\n### Arithmetic\n```\nlet result = (5 + 3) * 2;\nlet quotient = 10 / 2;\n```\n\n### Scoping\n```\n{\n    let x = 1;\n    {\n        let y = 2;\n        // x and y visible here\n    }\n    // only x visible here\n}\n```\n\n### Comments\n```\n// Single line comment\n\n/* Multi-line\n   comment */\n```\n\n### Exit Statement\n```\nexit(code);  // Exits with specified code\n```\n\n## Implementation Details\n\n### Memory Management\nThe project uses a custom arena allocator for efficient AST node allocation. The arena allocator:\n- Pre-allocates a large block of memory (4MB by default)\n- Provides fast allocation with minimal overhead\n- Does not support individual deallocation\n- Frees all memory at once when destroyed\n\n### AST Structure\nThe AST is built using variant types for nodes, allowing for:\n- Type-safe node representation\n- Easy visitor pattern implementation\n- Efficient memory layout\n\n### Code Generation\nAssembly generation follows these principles:\n- Stack-based variable storage\n- Proper alignment handling\n- Efficient register usage\n- Direct syscall usage for exit operations\n\n### Error Handling\nThe compiler provides:\n- Line number information in error messages\n- Specific error messages for missing tokens\n- Clear identification of undefined variables\n- Validation of redeclaration attempts\n\n## Examples\n\nBasic arithmetic:\n```\nlet x = 5;\nlet y = 10;\nlet z = x + y * 2;\nexit(z);\n```\n\nControl flow:\n```\nlet x = 5;\nif (x \u003e 3) {\n    exit(1);\n} elif (x \u003c 0) {\n    exit(2);\n} else {\n    exit(3);\n}\n```\n\nNested scopes:\n```\nlet x = 1;\n{\n    let y = x + 1;\n    {\n        let z = y + 1;\n        exit(z);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftermath22%2Foxygen_a-compiled-mini-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faftermath22%2Foxygen_a-compiled-mini-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftermath22%2Foxygen_a-compiled-mini-language/lists"}