{"id":26046843,"url":"https://github.com/sigilbyte/functional-programming-language-fun","last_synced_at":"2025-03-07T21:48:54.816Z","repository":{"id":63368660,"uuid":"518938304","full_name":"sigilbyte/Functional-Programming-Language-Fun","owner":"sigilbyte","description":"About Fun is a playful implementation of the basic functional programming language F. This was a group project by CS students @ LMU Munich.","archived":false,"fork":false,"pushed_at":"2022-11-17T16:43:04.000Z","size":133,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T15:48:55.696Z","etag":null,"topics":["compiler","functional-programming","haskell","parser","tokenizer"],"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/sigilbyte.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":"2022-07-28T17:32:35.000Z","updated_at":"2023-03-24T05:40:58.000Z","dependencies_parsed_at":"2022-11-17T18:31:40.672Z","dependency_job_id":null,"html_url":"https://github.com/sigilbyte/Functional-Programming-Language-Fun","commit_stats":null,"previous_names":["sigilbyte/functional-programming-language-fun"],"tags_count":null,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigilbyte%2FFunctional-Programming-Language-Fun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigilbyte%2FFunctional-Programming-Language-Fun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigilbyte%2FFunctional-Programming-Language-Fun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigilbyte%2FFunctional-Programming-Language-Fun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigilbyte","download_url":"https://codeload.github.com/sigilbyte/Functional-Programming-Language-Fun/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242467569,"owners_count":20133114,"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":["compiler","functional-programming","haskell","parser","tokenizer"],"created_at":"2025-03-07T21:48:54.417Z","updated_at":"2025-03-07T21:48:54.810Z","avatar_url":"https://github.com/sigilbyte.png","language":"Haskell","readme":"\n# FUN - a functional programming language in Haskell \n### An implementation of the functional programming language F in Haskell\n\u003cbr/\u003e\n\n## How to get started\n1. The fun way\n   ```Shell\n   ghci Main.hs\n   letsGo\n   ```\n2. The other way\n   ```Shell\n   ghci Main.hs\n   emulate \"your Fun code\"\n   ```\n3. The hard way (*see at the bottom of the ReadMe)\n   \n\u003cbr/\u003e\n\n## Syntax changes\nWe made four adjustments to the F syntax:\n1. We decided to interchange the semicolons between multiple `Local Definitions` with commas because we wanted semicolons to be used exclusively between multiple `Definitions` (for better readability).\n\n2. According to the script the precedence of the negation should be lower than the precedence of an addition. This would lead to `-5 + 2` being evaluated as `-7`. We wanted our syntax to be more intuitive so we changed the precedences to let `-5 + 2` be evaluated as `-3`.\n   \n3. As opposed to the script we allow inputs of the form `A-B-C` and `A/B/C` by implementing a left associativity for `-` and `/`.\n   \n4.  We also implemented exponential expressions. Only integers are allowed as exponents.\n\u003cbr/\u003e\n\n## Modules\n### Main\nThe Main module is the interface for our entire implementation. It imports all of the modules below. You can either call the modules' functions directly or call **`letsGo`** for a fun and interactive experience of Fun!\n\nEach module provides a `function` and a `showFunction`. When other modules want to continue processing the result of a different module they always call `function`, never `showFunction`. The only purpose of `showFunction` is to create a nice, more comprehensive output of an intermediate result.\n\n### Tokenizer\n\n- ### `tokenize`\n    takes a `String` (your Fun program) as input, splits it up into `Tokens` and returns them in a list.\n    \n- ### `showTokenize`\n    \n\n### Parser\n- ### `parse`\n    takes a `String` (your Fun program) as input, calls `tokenize` on it and converts the list of `Tokens` into an AST (abstract syntax tree) with `Expressions` as nodes and leaves.\n\n- ### `showParse`\n    creates an output that is easier to comprehend than the output of `parse`. It lists all `Definitions` with their arguments and represents the AST structure of the function body with parentheses.\n    \n    For example `showParse \"main = cool 1; cool x = 10*x;\"`\n    creates the following output:\n    ```Haskell\n    Definition main      []        (Function (Variable \"cool\") (Val 1))\n    Definition cool      [\"x\"]     (Mult (Val 10) (Variable \"x\"))\n    ```\n### Compiler\n- ### `compile`\n    takes a `String` (your Fun program) as input, calls `parse` on it and converts the AST into a list of `Instructions`. This list is appended to `initCode` which contains the `Instructions` that call the `main` function, ensure the termination of the code and enable the emulation of unary, binary and if `Expressions`. `compile` also initializes `Heap`, `Global`, `PC` and `Stack`:\n    ```Haskell\n    pc     = 0\n    code   = initCode ++ [Instruction]\n    stack  = []\n    heap   = [DEF name arity codeAddress]\n    global = [(name, heapAddress)]\n    ```\n    `Heap` is initialized with `DEF` cells which consist of the name, arity and code address of each function. The `Global` environment contains the function names and corresponding `Heap` addresses of those `DEF` cells.\n    \n    These five sets of data are returned as a `State`:\n    ``` Haskell\n    State pc code stack heap global\n    ```\n\n- ### `showCompile`\n    provides a better visualization of the initial `State`. It only shows `Instructions`, `Heap` and `Global`.\n\n### Emulator\n- ### `emulate`\n    takes a `String` (your Fun program) as input, calls `compile` on it and uses the `State` as input for `run` which emulates the `Instructions` step by step and changes `PC`, `Stack` and `Heap` accordingly. It is a recursive function which overwrites the old `State` after each `Instruction` is processed. The final `State` contains the result of the emulation and is returned to `emulate` which unpacks the result and returns it.\n\n- ### `showEmulate`\n    visualizes `emulate` by showing each state of the emulation process. In order to do that, it needs to know how the `State` looked after each `Instruction` but run doesn't provide this information. So it calls `showRun` which doesn't overwrite the old `State`, but rather appends each new `State` to a list in a recursive manner.\n   \n\u003cbr/\u003e\n\n## Highlights\n- letsGo function\n- monadic error handling\n- console output of `showFunctions`\n- associativity of `-` and `/`\n- exponential functions\n- it works\n- it's Fun!\n  \n\u003cbr/\u003e\n\n---\n\n*3.   The hard way\n   ```Haskell\n   -- myProgram.hs\n   import Tokenizer\n   import Parser\n   import Compiler\n   import Emulator\n   import Datatypes\n   example = showTokenize \"your Fun code\"\n   ```\n   ```Shell\n   ghci myProgram.hs\n   example\n   ```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigilbyte%2Ffunctional-programming-language-fun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigilbyte%2Ffunctional-programming-language-fun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigilbyte%2Ffunctional-programming-language-fun/lists"}