{"id":15101421,"url":"https://github.com/e3m3/calcc-rust","last_synced_at":"2026-02-16T17:35:33.939Z","repository":{"id":235996806,"uuid":"781052540","full_name":"e3m3/calcc-rust","owner":"e3m3","description":"Learning rust by implementing the calc langauge using the llvm-sys crate","archived":false,"fork":false,"pushed_at":"2024-11-05T01:27:25.000Z","size":123,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-31T13:37:45.549Z","etag":null,"topics":["calc","calculator-application","llvm","llvm-ir","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/e3m3.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,"zenodo":null}},"created_at":"2024-04-02T16:56:26.000Z","updated_at":"2024-11-05T02:55:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"e924a006-5815-4a45-ab82-4687ab221d1b","html_url":"https://github.com/e3m3/calcc-rust","commit_stats":{"total_commits":52,"total_committers":1,"mean_commits":52.0,"dds":0.0,"last_synced_commit":"7a0ee2ec31bb04c833051b60bb30ead4d6e6dc0c"},"previous_names":["e3m3/calcc-rust"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/e3m3/calcc-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e3m3%2Fcalcc-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e3m3%2Fcalcc-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e3m3%2Fcalcc-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e3m3%2Fcalcc-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e3m3","download_url":"https://codeload.github.com/e3m3/calcc-rust/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e3m3%2Fcalcc-rust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322170,"owners_count":25967877,"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-10-04T02:00:05.491Z","response_time":63,"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":["calc","calculator-application","llvm","llvm-ir","rust-lang"],"created_at":"2024-09-25T18:22:25.361Z","updated_at":"2025-10-04T14:16:01.789Z","avatar_url":"https://github.com/e3m3.png","language":"Rust","readme":"#   Copyright\n\nCopyright 2024, Giordano Salvador\nSPDX-License-Identifier: BSD-3-Clause\n\nAuthor/Maintainer:  Giordano Salvador \u003c73959795+e3m3@users.noreply.github.com\u003e\n\n\n#   Description (calcc language)\n\n[![Ubuntu 22.04](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2204.yaml)\n[![Ubuntu 24.04](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2404.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/ubuntu-2404.yaml)\n[![Fedora 40](https://github.com/e3m3/calcc-rust/actions/workflows/fedora-40.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/fedora-40.yaml)\n\n[![MacOS 13](https://github.com/e3m3/calcc-rust/actions/workflows/macos-13.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/macos-13.yaml)\n[![MacOS 14](https://github.com/e3m3/calcc-rust/actions/workflows/macos-14.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/macos-14.yaml)\n\n[![Windows 2022](https://github.com/e3m3/calcc-rust/actions/workflows/windows-2022.yaml/badge.svg?event=workflow_dispatch)](https://github.com/e3m3/calcc-rust/actions/workflows/windows-2022.yaml)\n\nLearning [Rust][1] [[1]] by implementing the calc langauge using the [llvm-sys][2] [[2]] crate.\nImplements the calc language, inspired by the [C++][3] [[3]] implementation presented by\n    Nacke and Kwan in [[4]] and [[5]].\n\nAccepted factors in the grammar have been extended for convenience (see `src/{lex,parse}.rs`\n    and `tests/lit-tests/`).\nThe output of the compiler is LLVM IR, LLVM bitcode, an object file, or executable file [[6]].\n\n\n##  Language\n\nThe original license for the calc source can be found here [[7]].\n\n### Lexer\n\n```text\nident           ::= letter+ (letter | digit)*\nnumber          ::= digit+ | (`0x` hex_digit+)\ndigit           ::= [0-9]\nhex_digit       ::= [a-fA-F0-9]\nletter          ::= letter_lower | letter_upper | `_`\nletter_lower    ::= [a-z]\nletter_upper    ::= [A-Z]\nwhitespace      ::= ` ` | `\\r` | `\\n` | `\\t`\n\nany             ::= _\ntoken           ::= { tokenkind, text }\ntokenkind       ::=\n    | Unknown\n    | Comma\n    | Comment\n    | Colon\n    | Eoi\n    | Eol\n    | Ident\n    | Minus\n    | Number\n    | ParenL\n    | ParenR\n    | Plus\n    | Slash\n    | Star\n    | With\ntext            ::=\n    | ``\n    | `,`\n    | `/``/` any*\n    | `:`\n    | ident\n    | `-`\n    | number\n    | `(`\n    | `)`\n    | `+`\n    | `/`\n    | `*`\n    | `with`\n```\n\n### Grammar\n\n```text\ncalc    ::= ( With Colon Ident (Comma Ident)* Colon )? expr\nexpr    ::= term ( Plus | Minus ) term\nfactor  ::= Minus? ( Number | Ident | ParenL expr ParenR )\nterm    ::= factor ( Slash | Star ) factor\n```\n\nNotes:\n\n*   The grammar rules above use the `tokenkind` as a shorthand for a `token` object as described\n    by the lexer rules.\n\n*   In the AST, a factor with a leading `Minus` token is represented as a subtraction expression\n    where the left term is `Number` with the constant value `0`.\n\n\n##  Prerequisites\n\n*   libstdc++\n\n*   rust-2021\n\n*   llvm-18 and llvm-sys (or llvm version matching llvm-sys)\n\n*   clang-18 (for executables and `-C|--c-main` flags)\n\n*   python3-lit, FileCheck (for testing)\n\n    *   By default, `tests/lit-tests.rs` will search for the lit executable in\n        `$PYTHON_VENV_PATH/bin` (if it exists) or the system's `/usr/bin`.\n\n*   [docker|podman] (for testing/containerization)\n\n    *   A [Fedora][8] [[8]] image can be built using `containers/Containerfile.fedora*`.\n\n    *   An [Ubuntu][9] [[9]] image can be built using `containers/Containerfile.ubuntu*`.\n\n    *   A [Windows][10] [[10]] image can be built using `containers/Dockerfile.windows*`.\n\n\n##  Setup\n\n*   Native build and test:\n    \n    ```shell\n    cargo build\n    cargo test -- --nocapture\n    ```\n\n*   Container build and test [podman][11] [[11]]:\n\n    ```shell\n    podman build -t calcc -f container/Containerfile .\n    ```\n\n*   Container build and test [docker][12] [[12]]:\n\n    ```shell\n    docker build -t calcc -f container/Dockerfile .\n    ```\n\n*   Container build and test [docker-buildx][12] [[12]] for [Windows][10] [[10]]:\n\n    ```shell\n    docker buildx build -t calcc -f container/Dockerfile.windows2022 --platform linux/amd64 --load .\n    ```\n\n*   If `make` is installed, you can build the image by running:\n\n    ```shell\n    make\n    ```\n\n##   Usage\n\nFrom the help message (`calcc --help`):\n\n```\nusage: calcc [OPTIONS] \u003cINPUT\u003e\nINPUT              '-' (i.e., Stdin) or a file path\nOPTIONS:\n--ast              Print the AST after parsing\n-b|--bitcode       Output LLVM bitcode (post-optimization) (.bc if used with -o)\n-c                 Output an object file (post-optimization) (.o if used with -o)\n--drop             Drop unknown tokens instead of failing\n-e|--expr[=]\u003cE\u003e    Process expression E instead of INPUT file\n-h|--help          Print this list of command line options\n--lex              Exit after running the lexer\n--ir               Exit after printing IR (pre-optimization)\n-S|--llvmir        Output LLVM IR (post-optimization) (.ll if used with -o)\n-k|--no-main       Omit linking with main module (i.e., output kernel only)\n                   When this option is selected, an executable cannot be generated\n--notarget         Omit target specific configuration in LLVM IR/bitcode\n-o[=]\u003cF\u003e           Output to file F instead of Stdout ('-' for Stdout)\n                   If no known extension is used (.bc|.exe|.ll|.o) an executable is assumed\n                   An executable requires llc and clang to be installed\n-O\u003c0|1|2|3\u003e        Set the optimization level (default: O2)\n--parse            Exit after running the parser\n--sem              Exit after running the semantics check\n-C|--c-main        Link with a C-derived main module (src/main.c.template)\n                   This option is required for generating object files and executables on MacOS\n                   and requires clang to be installed\n-v|--verbose       Enable verbose output\n--version          Display the package version and license information\n```\n\n\n#   References\n\n[1]:    https://www.rust-lang.org/\n[2]:    https://crates.io/crates/llvm-sys\n[3]:    https://isocpp.org/\n[4]:    https://www.packtpub.com/product/learn-llvm-17-second-edition/9781837631346\n[5]:    https://github.com/PacktPublishing/Learn-LLVM-17\n[6]:    https://llvm.org/\n[7]:    https://github.com/PacktPublishing/Learn-LLVM-17/blob/main/LICENSE\n[8]:    https://fedoraproject.org/\n[9]:    https://ubuntu.com/\n[10]:   https://www.microsoft.com/en-us/windows\n[11]:   https://podman.io/\n[12]:   https://www.docker.com/\n\n1.  `https://www.rust-lang.org/`\n\n1.  `https://crates.io/crates/llvm-sys`\n\n1.  `https://isocpp.org/`\n\n1.  `https://www.packtpub.com/product/learn-llvm-17-second-edition/9781837631346`\n\n1.  `https://github.com/PacktPublishing/Learn-LLVM-17`\n\n1.  `https://llvm.org/`\n\n1.  `https://github.com/PacktPublishing/Learn-LLVM-17/blob/main/LICENSE`\n\n1.  `https://fedoraproject.org/`\n\n1.  `https://ubuntu.com/`\n\n1.  `https://www.microsoft.com/en-us/windows`\n\n1.  `https://podman.io/`\n\n1.  `https://www.docker.com/`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe3m3%2Fcalcc-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fe3m3%2Fcalcc-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fe3m3%2Fcalcc-rust/lists"}