{"id":25046166,"url":"https://github.com/herniqeu/fofi","last_synced_at":"2025-10-21T04:30:15.907Z","repository":{"id":274252299,"uuid":"865357034","full_name":"herniqeu/fofi","owner":"herniqeu","description":"functionally-pure compiler for the 𝒇𝒐𝒇𝒊 language, implemented in Haskell :)","archived":false,"fork":false,"pushed_at":"2025-01-26T02:00:12.000Z","size":8,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T02:49:57.924Z","etag":null,"topics":["haskell","javascript","language","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Haskell","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/herniqeu.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}},"created_at":"2024-09-30T11:59:12.000Z","updated_at":"2025-01-26T02:21:15.000Z","dependencies_parsed_at":"2025-01-26T02:50:01.861Z","dependency_job_id":"4e8f2c8c-838b-4026-9224-bcf9ce153065","html_url":"https://github.com/herniqeu/fofi","commit_stats":null,"previous_names":["herniqeu/fofi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herniqeu%2Ffofi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herniqeu%2Ffofi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herniqeu%2Ffofi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herniqeu%2Ffofi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/herniqeu","download_url":"https://codeload.github.com/herniqeu/fofi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237431099,"owners_count":19308947,"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":["haskell","javascript","language","programming-language"],"created_at":"2025-02-06T06:36:04.548Z","updated_at":"2025-10-21T04:30:15.505Z","avatar_url":"https://github.com/herniqeu.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FOFI Compiler\n\nFOFI originated as a university project in Brazil, designed to help occupational therapists create thematic games for children on the autism spectrum. To learn more (in Portuguese), check out the local coverage: \u003ca href=\"https://g1.globo.com/sp/sao-paulo/bom-dia-sp/video/universitarios-criam-tapete-para-criancas-autistas-12778632.ghtml\"\u003ehere\u003c/a\u003e.\n\nA high-performance, functionally-pure compiler for the FOFI language, implemented in Haskell.\nFOFI (Framework Orientado para Facilitação Inclusiva) is a simple, statically-typed programming language inspired by both imperative and functional paradigms. Our compiler is built with modular design techniques, providing a clean architecture for lexical analysis, parsing, semantic analysis, and code generation.\n\n\u003cdiv align=\"center\"\u003e\n  \n[FOFI Docs] | [User Guide] | [Contributing] \n\n\u003c/div\u003e\n\n[FOFI Docs]: ./docs/README.md\n[User Guide]: ./docs/README.md#table-of-contents\n[API Documentation]: ./docs/README.md\n[Contributing]: ./CONTRIBUTING.md\n[Changelog]: ./CHANGELOG.md\n\n---\n\n## Table of Contents\n1. [Introduction](#introduction)  \n2. [Features](#features)  \n3. [Installation](#installation)  \n4. [Using the Compiler](#using-the-compiler)  \n5. [Code Overview](#code-overview)  \n6. [Examples](#examples)  \n7. [Contributing](#contributing)  \n8. [License](#license)\n\n---\n\n## Introduction\n\nFOFI is designed to be easy to learn and powerful enough to demonstrate key concepts of compiler design. It achieves:\n• Functional-purity: Emphasizing immutable data structures and declarative design.  \n• High-level abstractions: Leveraging Haskell's monadic parser combinators and lazy evaluation.  \n• Readable syntax: Drawing ideas from both imperative and functional styles, making it easy to transition from other languages.\n\nSee the [FOFI language documentation](./docs/README.md) for more details about the syntax, data types, control structures, and built-in functions.\n\n---\n\n## Features\n\n• Lexical Analysis using deterministic finite automata (DFA).  \n• Recursive Descent Parsing with monadic combinators.  \n• Polymorphic Type Inference and advanced semantic checks.  \n• Intermediate Representation in continuation-passing style (CPS).  \n• Optimized JavaScript Code Generation.  \n• Cross-platform: The compiler is written in Haskell using GHC, so it runs on most systems.\n\n---\n\n## Installation\n\nTo build and install the compiler, make sure you have GHC (Glasgow Haskell Compiler) and Cabal installed.  \nThen, from the repository root, run:\n\n```bash\ncabal update\ncabal install --only-dependencies\ncabal build\n```\n\nThis will produce the binary (called \"fofi-compiler\" by default) in one of Cabal's build directories.\n\n---\n\n## Using the Compiler\n\nOnce compiled, run:\n\n```bash\n./dist/newstyle/build/.../fofi-compiler \u003cinput-file\u003e\n```\n\nThe compiler will:\n1. Lex and parse the input FOFI file.  \n2. Perform semantic checks (type checking, variable declarations, etc.).  \n3. Generate the corresponding JavaScript code (saving it in \u003cinput-file\u003e.js).\n\nA typical command might look like:\n\n```bash\nfofi-compiler my_program.fofi\n```\n\nIf compilation succeeds, you'll see:\n```\nCompilation successful!\n```\n\nCheck out the newly generated \"my_program.fofi.js\" file in the same directory.\n\n---\n\n## Code Overview\n\nThis repository is organized into key modules, each handling a major phase of compilation. Below are brief overviews of some files and a sample of how they work.\n\n### 1. Main Entry Point\n\nThe compiler's top-level behavior is defined in [src/Main.hs](./src/Main.hs). It reads command-line arguments, calls into the different phases, and writes the final JavaScript output.\n\n```haskell:src/Main.hs\nmodule Main where\n\nimport System.Environment (getArgs)\nimport Lexer (tokenize)\nimport Parser (parse)\nimport SemanticAnalyzer (analyze)\nimport CodeGenerator (generate)\n\nmain :: IO ()\nmain = do\n    args \u003c- getArgs\n    case args of\n        [inputFile] -\u003e do\n            contents \u003c- readFile inputFile\n            let tokens = tokenize contents\n            case parse tokens of\n                Left error -\u003e putStrLn $ \"Parse error: \" ++ error\n                Right ast -\u003e do\n                    case analyze ast of\n                        Left error -\u003e putStrLn $ \"Semantic error: \" ++ error\n                        Right _ -\u003e do\n                            let code = generate ast\n                            writeFile (inputFile ++ \".js\") code\n                            putStrLn \"Compilation successful!\"\n        _ -\u003e putStrLn \"Usage: fofi-compiler \u003cinput-file\u003e\"\n```\n\n### 2. Lexer\n\n[Lexer.hs](./src/Lexer.hs) transforms raw text into tokens (e.g., identifiers, types, operators):\n\n```haskell:src/Lexer.hs\nmodule Lexer where\n\nimport Data.Char (isAlpha, isAlphaNum, isDigit, toLower)\n\ndata Token = Token\n    { tokenType :: String\n    , tokenValue :: String\n    , tokenLine :: Int\n    } deriving (Show, Eq)\n\n-- Core lexer function \ntokenize :: String -\u003e [Token]\ntokenize input = ...\n```\n\n### 3. Parser\n\n[Parser.hs](./src/Parser.hs) converts tokens into an Abstract Syntax Tree (AST). We use a recursive descent approach. Once the AST is built, we can do further checks or transformations:\n\n```haskell:src/Parser.hs\nmodule Parser where\n\nimport Lexer (Token(..))\n\ndata AST = ...\n-- This data type encapsulates the entire structure of the program.\n \nparse :: [Token] -\u003e Either String AST\nparse tokens = ...\n```\n\n### 4. Semantic Analysis\n\n[SemanticAnalyzer.hs](./src/SemanticAnalyzer.hs) checks for type correctness, variable declarations, etc. It uses a symbol table to ensure everything is well-typed:\n\n```haskell:src/SemanticAnalyzer.hs\nmodule SemanticAnalyzer where\n\nimport qualified Data.Map as Map\nimport Parser (AST(..), Expression(..))\n\nanalyze :: AST -\u003e Either String ()\nanalyze (Program _ varDecls stmts) = ...\n```\n\n### 5. Code Generation\n\n[CodeGenerator.hs](./src/CodeGenerator.hs) traverses the validated AST and emits JavaScript code:\n\n```haskell:src/CodeGenerator.hs\nmodule CodeGenerator where\n\nimport Parser (AST(..), Expression(..))\n\ngenerate :: AST -\u003e String\ngenerate (Program desc varDecls stmts) = ...\n```\n\n---\n\n## Examples\n\nBelow is a minimal \"Hello, FOFI!\" example. For a more in-depth guide, see the [FOFI Language Documentation](./docs/README.md).\n\nCreate a file named `hello.fofi`:\n\n```fofi\nprograma\n\"This is a simple FOFI program\"\n\nvar\ntexto message;\n\n{\n    message : \"Hello, FOFI!\";\n    mostrar(message);\n}\n```\n\nCompile it:\n```bash\nfofi-compiler hello.fofi\n```\n\nYou'll get `hello.fofi.js`. Run it with Node.js (or any JavaScript runtime):\n```bash\nnode hello.fofi.js\n```\n\nExpected output:\n```\nHello, FOFI!\n```\n\nFor additional examples, including control structures, function usage, and advanced graphics/animation, check out [docs/README.md](./docs/README.md#examples).\n\n---\n\n## Contributing\n\nWe welcome contributions! If you'd like to propose a feature or fix a bug:\n1. Fork the repository and make your changes in a new branch.  \n2. Create a Pull Request describing your changes.  \n3. Ensure your code passes any relevant tests.  \n\nAlso, please open an issue if you find any bugs or have feature requests. See [CONTRIBUTING.md](./CONTRIBUTING.md) for details.\n\n---","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherniqeu%2Ffofi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fherniqeu%2Ffofi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherniqeu%2Ffofi/lists"}