From c984c588095b8f73264e297090ef642183df6510 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 6 Oct 2019 21:42:52 +0200 Subject: Add a few comments --- src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 66319b1..d147a40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,6 +72,7 @@ impl Program { } } +/// read the program from the specified file into a string fn read_program(filename: &str) -> Result { let file = File::open(filename)?; let mut content = String::new(); @@ -80,6 +81,7 @@ fn read_program(filename: &str) -> Result { Ok(content) } +/// update loop tokens and look for the matching opposing parts fn find_loops(commands: &mut Vec) -> Result<(), String> { let mut loop_starts = Vec::new(); for i in 0 .. commands.len() { @@ -151,11 +153,13 @@ fn optimize(program: &mut Vec) { optimize_sequences(program); } +/// filter out all non-syntax characters from the input fn preprocess(program: &str) -> String { let allowed_chars = ['>', '<', '+', '-', '.', ',', '[', ']']; program.chars().filter(|c| allowed_chars.contains(c)).collect() } +/// convert input string into syntax tokens fn tokenize(input: &str) -> Vec { input.chars().map(|token| match token { -- cgit v1.2.3