A minimalistic interpreter for a simple smart contract written in Solidity. Solidity language documentation here
- 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
).
- 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); }
cargo build
cargo run
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);
}