0.2.4 • Published 12 months ago

pseudo-int-lib v0.2.4

Weekly downloads
-
License
MIT OR Apache-2.0
Repository
github
Last release
12 months ago

A Pseudocode interpreter library to be used in web apps. Written in Rust and exported to npm registrywasm-pack.

Built with 🦀🕸 by The Rust and WebAssembly Working Group

Pseudo Interpreter

License

A pseudocode interpreter library written in rust and exported to npm registry.

Implemented Features

  • print function
  • input function
  • variable assignment
  • expressions
  • if statements
  • multi conditional statements
  • arrays
  • for loops
  • while loops
  • functions

Usage

export async function interpret(input: string): Promise<string> {
    let output = await import("pseudo-int-lib").then((module) => {
        try {
            return module.interpret(input);
        } catch (error) {
            throw error
        }
    });

    return output;
}
  • Create a export a function that will load the wasm module and call its execute function. This is the function you will call in your frontend.

  • the function can be used like this

  • the module.interprete function returns a string when no error occurs or throws a string error when Error occurs.
const [input, setInput] = useState("");
const [output, setOutput] = useState("");
const [error, setError] = useState("");

const handleExecute = async () => {
  if (input.length < 1) {
    setError("No inputs");
    return;
  }
  try {
    const result = await interpret(input);
    console.info(result);
    setOutput(result);
    setError("");
  } catch (error) {
    console.error(error);
    setError(`${error}`);
  }
};

Contact

🔋 Batteries Included

  • wasm-bindgen for communicating between WebAssembly and JavaScript.
  • console_error_panic_hook for logging panic messages to the developer console.
  • LICENSE-APACHE and LICENSE-MIT: most Rust projects are licensed this way, so these are included for you

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

0.2.4

12 months ago

0.2.3

12 months ago

0.2.2

12 months ago

0.2.1

12 months ago

0.2.0

12 months ago

0.1.0

12 months ago