Step 1: Create an AST

This step consists of creating the AST to represent the input
expression, the only evaluation done for now is the recognition of three
MalTypes for the nodes of the AST:
- Symbols: atomic isolated groups of characters
- Integers: Symbols that can be parsed as number and are treated as so
- Lists: recognizable by the presence of parentheses (only "()" for now,
  "[]" and "{}" later), these can contain any number of MalTypes

The second half of this step (much easier) is to reconstruct the
original syntax (with clean whitespaces) to check the correctness of the
process

Signed-off-by: teo3300 <matteo.rogora@live.it>
This commit is contained in:
teo3300
2023-06-05 23:04:51 +02:00
parent 9144fc04bc
commit 13790d0864
5 changed files with 194 additions and 3 deletions

33
src/step1_read_print.rs Normal file
View File

@ -0,0 +1,33 @@
// Structure the main functions of the interpreter
//
// For now just act as an echo, note that each function should not modify the
// input, thus this can be referenced by the previous step without the need
// to allocate more memory
use crate::printer::pr_str;
use crate::reader::read_str;
use crate::types::MalType;
#[allow(non_snake_case)]
/// Read input and generate an ast
fn READ(input: &str) -> MalType {
read_str(input)
}
#[allow(non_snake_case)]
/// Evaluate the generated ast
fn EVAL(ast: MalType) -> MalType {
ast
}
#[allow(non_snake_case)]
/// Print out the result of the evaluation
fn PRINT(input: MalType) -> String {
pr_str(&input)
}
pub fn rep(input: &str) -> String {
let ast = READ(input);
let out = EVAL(ast);
PRINT(out /*&result*/)
}