λ-calculus parser made by rust

Overview

Lambda Calculus Parser

This is a parser for λ-calculus expressions. It takes a λ-terms as input, parses it and returns a JSON representation of the term. The parser currently supports λ-abstractions, variables and function applications. It uses a recursive descent parsing technique.

Features

  • Parses λ-abstractions, variables and function applications
  • Returns a JSON representation of the parsed λ-term
  • Includes a REPL for interactive parsing

Usage

The parser is implemented as a Parser struct with several methods. It uses a Peekable<Chars> iterator to read the input string single characters at a time. The main parsing function, parse_term, loop over the input string and determine the appropriate parsing function to call based on the current character.

The parsing functions are:

  • parse_lambda : Parsed a λ-abstraction(e.g., λx.x)
  • parse_application : Parses a function application (e.g., (f x))
  • parse_variable : Parses a variable (e.g., x)

The parser returns an enum Term, which can be one of the following:

  • Lambda: Represents a λ-abstraction with a binding variable and a body
  • Application: Represents a function application with a function and an argument
  • Variable: Represents a variable with a name
  • Null: Represents an empty term or failed parsing

The parsed Term is then converted to a JSON format using the term_to_json function. which converts the Term to a serde_json::Value object.

Example

Here's an example of how to parse a λ-term using the parser:

fn main() {
    let input = "λf. λx. (f x)";
    let term = parse(input);
    let json = term_to_json(&term);
    println!("{}", serde_json::to_string_pretty(&json).unwrap());
}

This will output:

{
  "bind": "f",
  "body": {
    "bind": "x",
    "body": {
      "arg": {
        "name": "x",
        "tag": "var"
      },
      "func": {
        "name": "f",
        "tag": "var"
      },
      "tag": "application"
    },
    "tag": "lambda"
  },
  "tag": "lambda"
}

Note: There is a problem that the position of the tag goes down when print the current JSON. This will be fixed in the future.

To use the REPL, run the following command:

cargo run

After that, you can enter a λ-term and press enter to parse it. The REPL will print the parsed JSON representation of the term.

Comments
  • Rearrange JSON tags

    Rearrange JSON tags

    Describe

    JSON output must be formatted by this order: "tag", "bind", and "body".

    How to solve this?

    Via implementing custom Display trait for Term enum.

    enhancement 
    opened by notJoon 0
  • When outputting JSON,

    When outputting JSON, "tag" must go to the top.

    Currently, there is a problem that "tag" goes down when outputting JSON from REPL. It doesn't really matter, but I think need to move it up for better readability.

    opened by notJoon 0
  • need to print better error messages

    need to print better error messages

    If the current parsing fails, it will return 'Null', but I think this will need to print more detailed error messages.

    For example, if implement the 'ParseError' type and the parsing of each Lambda, Application, Variable fails, parser must throw each error message.

    opened by notJoon 0
  • Add more informative error cases

    Add more informative error cases

    Description

    Extended the error message before, but there are still some ambiguities.

    Therefore, I think we need to add the error type and the corresponding message to deal with more detailed errors.

    Example

    #[derive(Debug)]
    pub enum ParseError {
        UnexpectedCharacter(char),
        UnexpectedEndOfFile,
        UnmatchedParenthesis,
        // ...
    }
    

    By using these specific error types, REPL can provide better error messages to users and make it easier for them to understand and fix issues with their input.

    enhancement 
    opened by notJoon 0
  • Parser doesn't handle applications with single term inside parentheses

    Parser doesn't handle applications with single term inside parentheses

    Description

    The current implementation of the lambda calculus parser fails to correctly parse applications that have a single term inside parentheses, such as the following example:

    λf.(λx.f(x x))(λx.f(x x))
    

    This issue is caused by the assumption that applications must have at least two terms.

    Expected Behavior

    The parser should correctly parse applications with a single term inside parentheses, as well as those with multiple terms.

    opened by notJoon 0
Owner
Lee ByeongJun
Uncertified Quasi-polyglot pseudo dev
Lee ByeongJun
Untyped Concatenative Calculus

Untyped Concatenative Calculus The untyped concatenative calculus, implemented in Rust. A toy programming language and prototype for Dawn. Native REPL

The Dawn Programming Language 16 Aug 23, 2022
A Bancho implementation made in Rust for the *cursed* stack.

cu.rs A Bancho implementation made in Rust for the cursed stack. THIS PROJECT IS REALLY UNFINISHED AND IN ITS EARLY STAGES A drag and drop replacement

RealistikOsu! 5 Feb 1, 2022
An annotated string type in Rust, made up of string slices

A string type made up of multiple annotated string slices.

Togglebit 3 Dec 29, 2022
A bundler (mainly for TypeScript projects) made in Rust

TSAR A bundler (mainly for TypeScript projects) made in Rust. Also my first Rust Project! What does TSAR stand for Like phar (PHP Archive) or JAR (Jav

null 2 Mar 19, 2022
Easily customizable command runner made with Rust 🦀

Easily customizable command runner made with Rust ?? ?? Usage Install by the following command: cargo install rxe Or build from the source. git clone

Flisan 4 May 25, 2022
A replit.com scraper, designed to grab discord tokens. Made in Rust.

Scraper A discord token scraper, designed to scrape forks from replit.com. This script uses the Graphql api on replit to essentially pull forks. Setup

Shell 18 Jan 2, 2023
Analog subtractive synth (VST Plugin) made with Rust

Synja Analog subtractive synth (VST3 Plugin) made with Rust. More an experiment in making a VST and learning Rust than a production quality Synth, but

Anders Forsgren 7 Jan 18, 2023
Rustymind is a driver and parser for NeuroSky MindWave EEG headset written in pure Rust.

Rustymind is a driver and parser for NeuroSky MindWave EEG headset written in pure Rust. You can use it to connect, interact, and plot real time data from the headset.

Junjun Dong 34 Sep 13, 2022
Motoko concrete syntax parser in Rust.

motoko.rs Motoko concrete syntax parser and dynamic evaluator (VM) in Rust. Motoko VM The Motoko VM explores a more dynamic way for Motoko to execute.

DFINITY 8 Dec 15, 2022
The axiom profiler for exploring and visualizing SMT solver quantifier instantiations (made via E-matching).

Axiom Profiler A tool for visualising, analysing and understanding quantifier instantiations made via E-matching in a run of an SMT solver (at present

Viper Project 18 Oct 18, 2022
Lightweight compile-time UUID parser.

compiled-uuid Anywhere you're building Uuids from a string literal, you should use uuid. Motivation If you want to use a fixed Uuid throughout your pr

Quinn 10 Dec 8, 2022
Parser for UltraStar Deluxe song files

This is a rust parser for USDX song files. Files are written as a plaintext files that contain data about the song and notes/lyrics.

null 1 Apr 3, 2022
k-mer counter in Rust using the rust-bio and rayon crates

krust is a k-mer counter written in Rust and run from the command line that will output canonical k-mers and their frequency across the records in a f

null 14 Jan 7, 2023
Experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code

Diplomat is an experimental Rust tool for generating FFI definitions allowing many other languages to call Rust code. With Diplomat, you can simply define Rust APIs to be exposed over FFI and get high-level C, C++, and JavaScript bindings automatically!

null 255 Dec 30, 2022
Aws-sdk-rust - AWS SDK for the Rust Programming Language

The AWS SDK for Rust This repo contains the new AWS SDK for Rust (the SDK) and its public roadmap. Please Note: The SDK is currently released as a dev

Amazon Web Services - Labs 2k Jan 3, 2023
Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps.

rust-yew-axum-tauri-desktop template Rust + Yew + Axum + Tauri, full-stack Rust development for Desktop apps. Crates frontend: Yew frontend app for de

Jet Li 54 Dec 23, 2022
A lightning fast version of tmux-fingers written in Rust, copy/pasting tmux like vimium/vimperator

tmux-thumbs A lightning fast version of tmux-fingers written in Rust for copy pasting with vimium/vimperator like hints. Usage Press ( prefix + Space

Ferran Basora 598 Jan 2, 2023
A command-line tool collection to assist development written in RUST

dtool dtool is a command-line tool collection to assist development Table of Contents Description Usage Tips Installation Description Now dtool suppor

GB 314 Dec 18, 2022
Rust mid-level IR Abstract Interpreter

MIRAI MIRAI is an abstract interpreter for the Rust compiler's mid-level intermediate representation (MIR). It is intended to become a widely used sta

Facebook Experimental 793 Jan 2, 2023