#spa #language #grammar #slice #algorithm #generic #running

dyck

A crate for running Dyck and InterDyck algorithms over languages of generic <T> token enum instances or string slice types

1 unstable release

new 0.1.0 Apr 11, 2024

#1150 in Algorithms

Download history 85/week @ 2024-04-06

85 downloads per month

MIT license

9KB
135 lines

A library for running Dyck algorithms over languages of generic string slice types.

This module provides functionalities to create and manipulate languages based on user-defined tokens, allowing for the evaluation and transformation of sequences of tokens (words) according to the rules of Dyck languages.

Usage

Add dyck to your Cargo.toml:

[dependencies]
dyck = "0.1"

Example: Creating a Dyck language and checking if a word is valid.

use dyck::{Language, Word};

// define pairs of tokens for the language
let pairs = vec![("(", ")"), ("[", "]"), ("{", "}")];
let language = Language::new_from_vec(&pairs).expect("Failed to create language");

// define a word to check
let word: Word<&str> = vec!["(", "[", "]", "(", ")", ")"];

// check if the word is a valid Dyck word
if language.is_valid(&word) {
        println!("The word is a valid Dyck word.");
} else {
    println!("The word is not a valid Dyck word.");
}

See /examples in the repository root for more examples.

Dependencies

~115KB