https://github.com/4ster-light/f-logic
Implementation of a logic formula parser and truth table generator in F#
https://github.com/4ster-light/f-logic
fsharp interpreter lexer parser
Last synced: 9 months ago
JSON representation
Implementation of a logic formula parser and truth table generator in F#
- Host: GitHub
- URL: https://github.com/4ster-light/f-logic
- Owner: 4ster-light
- License: mit
- Created: 2025-08-05T15:20:55.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-09-25T07:40:51.000Z (9 months ago)
- Last Synced: 2025-09-25T09:25:48.982Z (9 months ago)
- Topics: fsharp, interpreter, lexer, parser
- Language: F#
- Homepage: https://aster.deno.dev/posts/introduction-to-interpreters-part-2
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# 🧑💻 f-logic
Implementation of a logic formula parser and truth table generator in Python.
## 📚 Table of Contents
- [📜 Overview](#-overview)
- [🛠 Usage](#-usage)
- [📋 Requirements](#-requirements)
- [📄 License](#-license)
- [💝 Sponsor](#-sponsor)
## 📜 Overview
This project is meant as educational material in order to learn about basic
interpreters and the process of lexing and parsing a language as well as the
concept of AST (Abstract Syntax Tree), therefore why it supports only basic
logic symbols.
The choice of interpreting logic formulas was made due to its relative
simplicity and the fact that it is related to computer science.
This second tutorial is
written in F# in order to learn about the language and showcase why functional
programming is a good choice for this kind of project, due to its strong
algebraic data types and common patterns like recursion and pattern matching.
You can find the Python version (easier and more readable for beginners) of this
project [here](https://github.com/4ster-light/py-logic) with the corresponding
tutorial
[here](https://aster.deno.dev/posts/introduction-to-interpreters/).
## 🛠 Usage
- Run `dotnet run` to generate a truth table for the given formula:
```bash
$ dotnet run
Enter a logical formula (e.g., P & Q -> R, !A | B):
P & Q -> R
P | Q | R | P & Q -> R
----------+-----------
T | T | T | T
T | T | F | F
T | F | T | T
T | F | F | T
F | T | T | T
F | T | F | T
F | F | T | T
F | F | F | T
```
- Run `dotnet run -- --debug` to see the tokens and AST generated by the parser:
```bash
$ dotnet run -- --debug
Enter a logical formula (e.g., P & Q -> R, !A | B):
P & Q -> R
- Formula:
- P & Q -> R
- Tokens:
- Variable "P"
- AndOp
- Variable "Q"
- ImpliesOp
- Variable "R"
- Eof
- Expression:
- Implies (And (Var "P", Var "Q"), Var "R")
```
## 📋 Requirements
Only .NET 9.0 is required.
## 📄 License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
for details.
## 💝 Sponsor
If you like this project, consider supporting me by buying me a coffee.
[](https://ko-fi.com/B0B41HVJUR)