falila / smart-contract-interpreter

Simple Solidity Smart Contract interpreter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Smart Contract Interpreter

A minimalistic interpreter for a simple smart contract written in Solidity. Solidity language documentation here

Features

  • Variable Declaration: Declare and initialize variables.
  • Arithmetic Operations: Support for basic arithmetic operations.
  • Conditional Statements: Basic if-else conditions.
  • While Loops: Looping with while conditions.
  • Function Calls: Calling predefined functions (e.g., print).

Language Syntax

  • Variable Declaration: let <var> = <value>;
  • Arithmetic Operation: <var> = <var> + <value>;
  • Conditional Statement:
    if <var> == <value> {
        // statements
    } else {
        // statements
    }
    
    let x = 0;
    while x < 5 {
        x = x + 1;
        print(x);
    }
    
    

Build the project:

cargo build

Run the project:

cargo run

Usage

To modify the contract, edit the code variable in the main function in src/main.rs:

fn main() {
    let mut interpreter = Interpreter::new();

    let code = r#"
        let x = 0;
        while x < 5 {
            x = x + 1;
            print(x);
        }
    "#;

    let statements = interpreter.parse(code);
    interpreter.evaluate(statements);
}

About

Simple Solidity Smart Contract interpreter


Languages

Language:Rust 100.0%