{"id":26244511,"url":"https://github.com/realorko/experimentalcompilerinc","last_synced_at":"2025-08-02T05:35:46.171Z","repository":{"id":279869536,"uuid":"937693912","full_name":"RealOrko/ExperimentalCompilerInC","owner":"RealOrko","description":"An experimental compiler in C","archived":false,"fork":false,"pushed_at":"2025-07-31T16:36:11.000Z","size":393,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-31T19:04:25.838Z","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/RealOrko.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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-23T17:22:58.000Z","updated_at":"2025-07-31T16:36:14.000Z","dependencies_parsed_at":"2025-02-28T07:16:30.014Z","dependency_job_id":"52a2e79d-56c3-4ba1-9822-1faa334871b5","html_url":"https://github.com/RealOrko/ExperimentalCompilerInC","commit_stats":null,"previous_names":["realorko/experimentalcompilerinc"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/RealOrko/ExperimentalCompilerInC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrko%2FExperimentalCompilerInC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrko%2FExperimentalCompilerInC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrko%2FExperimentalCompilerInC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrko%2FExperimentalCompilerInC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RealOrko","download_url":"https://codeload.github.com/RealOrko/ExperimentalCompilerInC/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RealOrko%2FExperimentalCompilerInC/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268339409,"owners_count":24234544,"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-02T02:00:12.353Z","response_time":74,"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":"2025-03-13T11:27:51.906Z","updated_at":"2025-08-02T05:35:46.163Z","avatar_url":"https://github.com/RealOrko.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"Language Specification for Custom C Compiler\nThis document outlines the language specification for a custom programming language designed to be compiled by a C-based compiler. The language supports a concise, readable syntax with functional and imperative features. Below is a detailed description of the language's syntax and semantics, based on the provided example code.\n1. General Syntax\n\nIndentation: The language uses indentation (2 spaces) to denote blocks, similar to Python, instead of curly braces.\nArrow Operator (=\u003e): Used to define function bodies, conditionals, loops, and other control structures.\nSemicolons: Statements within the same block do not require semicolons, as line breaks separate statements.\nComments: Not shown in the example, but the language supports single-line comments starting with // and multi-line comments with /* */.\n\n2. Data Types\nThe language supports the following primitive data types:\n\nint: 32-bit signed integer (e.g., 5, -10).\nbool: Boolean values (true, false).\nstr: String type for text data (e.g., \"hello\").\ndouble: 64-bit floating-point number (e.g., 3.14159).\nchar: Single character (e.g., 'A').\n\nVariables are declared using the var keyword, followed by the variable name, a colon, and the type:\nvar num: int = 5\nvar text: str = \"hello\"\n\n3. Functions\nFunctions are defined using the fn keyword, followed by the function name, parameters, return type, and body.\nSyntax\nfn \u003cname\u003e(\u003cparam1\u003e: \u003ctype1\u003e, \u003cparam2\u003e: \u003ctype2\u003e, ...): \u003creturn_type\u003e =\u003e\n  \u003cbody\u003e\n\n\nParameters are specified in parentheses, with each parameter followed by its type.\nThe return type is specified after a colon.\nThe function body is introduced by =\u003e and indented.\nThe return statement is used to return a value.\n\nExample\nfn factorial(n: int): int =\u003e\n  if n \u003c= 1 =\u003e\n    return 1\n  return n * factorial(n - 1)\n\n\nThe factorial function takes an int parameter n and returns an int.\nIt uses recursion to compute the factorial.\n\n4. Control Structures\n4.1 If-Else\nConditional statements use the if keyword, followed by a condition, =\u003e, and an indented block. An optional else clause can follow.\nif \u003ccondition\u003e =\u003e\n  \u003cbody\u003e\nelse =\u003e\n  \u003cbody\u003e\n\n\nConditions are expressions evaluating to a bool.\nExample:if is_prime(7) =\u003e\n  print(\"7 is prime\")\nelse =\u003e\n  print(\"7 is not prime\")\n\n\n\n4.2 While Loop\nThe while loop executes a block while a condition is true.\nwhile \u003ccondition\u003e =\u003e\n  \u003cbody\u003e\n\n\nExample:while i * i \u003c= num =\u003e\n  if num % i == 0 =\u003e\n    return false\n  i = i + 1\n\n\n\n4.3 For Loop\nThe for loop iterates over a range or sequence, with a loop variable declared inline.\nfor var \u003cvar\u003e: \u003ctype\u003e = \u003cstart\u003e; \u003ccondition\u003e; \u003cincrement\u003e =\u003e\n  \u003cbody\u003e\n\n\nExample:for var j: int = 0; j \u003c count; j++ =\u003e\n  result = result + text\n\n\nThe loop variable (j) is declared with var and a type.\nThe j++ syntax increments the variable by 1.\n\n5. String Interpolation\nStrings support interpolation using the $ prefix and {} to embed expressions.\n$\"This is a {variable}\"\n\n\nExample:print($\"Factorial of {num} is {fact}\")\n\n\nThe expression inside {} is evaluated and converted to a string.\nSupported types for interpolation: int, double, char, bool, str.\n\n6. Operators\nThe language supports standard arithmetic, comparison, and logical operators:\n\nArithmetic: +, -, *, /, % (modulus).\nComparison: ==, !=, \u003c, \u003c=, \u003e, \u003e=.\nLogical: Not shown in the example, but assumed to include \u0026\u0026 (and), || (or), ! (not).\nAssignment: = for assignment, +=, -=, etc., are not shown but may be supported.\n\n7. Built-in Functions\nThe language includes a print function for console output.\nprint(\u003cexpression\u003e)\n\n\nThe argument can be a string, interpolated string, or other printable type.\nExample:print(\"7 is prime\")\nprint($\"Pi approx: {pi_approx}\")\n\n\n\n8. Variable Scoping\n\nVariables declared with var are scoped to the block (function, loop, or conditional) in which they are defined.\nExample:var i: int = 2  // Local to the is_prime function\n\n\n\n9. Example Program Analysis\nThe provided main function demonstrates the language's features:\nfn main(): void =\u003e\n  var num: int = 5\n  var fact: int = factorial(num)\n  print($\"Factorial of {num} is {fact}\")\n\n  if is_prime(7) =\u003e\n    print(\"7 is prime\")\n  else =\u003e\n    print(\"7 is not prime\")\n\n  var repeated: str = repeat_string(\"hello \", 3)\n  print(repeated + \"world!\")\n\n  var sum: int = 0\n  for var k: int = 1; k \u003c= 10; k++ =\u003e\n    sum = sum + k\n  print($\"Sum 1 to 10: {sum}\")\n\n  var pi_approx: double = 3.14159\n  print($\"Pi approx: {pi_approx}\")\n\n  var ch: char = 'A'\n  print($\"Char: {ch}\")\n\n  var flag: bool = true\n  print($\"Flag: {flag}\")\n\n  var any: str = $\"This is a thing {num}\"\n  print(any)\n  ...\n\n\nDeclares variables of types int, double, char, bool, and str.\nCalls functions (factorial, is_prime, repeat_string).\nUses string interpolation for output.\nDemonstrates control structures (if, for).\n\n10. Implementation Notes for C Compiler\nTo implement a compiler in C for this language:\n\nLexer/Parser: Use a lexer (e.g., Flex) to tokenize keywords (fn, var, if, etc.), operators, and literals. Use a parser (e.g., Bison) to handle the indentation-based grammar and =\u003e syntax.\nType System: Implement a type checker to enforce type annotations (int, str, etc.) and ensure type safety in operations.\nCode Generation: Generate C or LLVM IR code, mapping language constructs to equivalent C code. For example, the =\u003e blocks can be translated to C's {} blocks.\nRuntime: Provide a runtime library for string interpolation (using a format string approach) and the print function (mapping to printf).\nMemory Management: Strings (str) may require dynamic memory management in C (e.g., using malloc and free).\nError Handling: Ensure the compiler reports meaningful errors for type mismatches, undefined variables, or incorrect indentation.\n\n11. Limitations and Assumptions\n\nThe language does not appear to support arrays, structs, or pointers in the provided example.\nNo explicit support for exception handling or advanced data structures.\nThe string concatenation operator (+) is supported for strings, but its behavior for other types is undefined.\nThe language assumes single-threaded execution, as no concurrency features are shown.\n\n12. Future Extensions\nPotential extensions to the language could include:\n\nSupport for arrays or lists (e.g., var arr: [int]).\nFunction overloading or default parameters.\nModules or imports for code organization.\nAdditional control structures like switch or try-catch.\n\nThis specification provides a foundation for implementing a compiler in C that can process the given language's syntax and semantics. For further details or clarifications, refer to the example code or contact the language designer.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealorko%2Fexperimentalcompilerinc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frealorko%2Fexperimentalcompilerinc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frealorko%2Fexperimentalcompilerinc/lists"}