Skip to content

falila/smart-contract-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages