diff --git a/TODO b/TODO index 9b9d119..4d28a40 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,7 @@ # Bugs - +- Uninitialized variables don't compile # Features -- Array access syntax - For loop - Type system - Nested expressions like (1 + (2 * 2)) diff --git a/examples/bubblesort.sb b/examples/bubblesort.sb new file mode 100644 index 0000000..698f96a --- /dev/null +++ b/examples/bubblesort.sb @@ -0,0 +1,25 @@ +// Doesn't compile yet + +fn main() { + let arr = [2, 5, 3, 1, 4] + let n = len(arr) + + let c = 0 + while c < n { + let d = 0 + while d < n - c - 1 { + let current = arr[d] + let next = arr[d+1] + if current > next { + let swap = arr[d] + arr[d] = arr[d+1] + arr[d+1] = swap + } + + d = d + 1 + } + + c = c + 1 + } + +} \ No newline at end of file diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 30e032e..1a95b62 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -484,3 +484,49 @@ fn test_array_access_standalone() { let tree = parse(tokens, Some(raw.to_string())); assert!(tree.is_ok()) } + +#[test] +fn test_array_access_assignment() { + let raw = " + fn main() { + let arr = [1, 2, 3] + let x = arr[0] + + return x + } + "; + let tokens = tokenize(raw); + let tree = parse(tokens, Some(raw.to_string())); + assert!(tree.is_ok()) +} + +#[test] +#[ignore] +fn test_array_access_in_if() { + let raw = " + fn main() { + if arr[d] > arr[d+1] { + let swap = arr[d] + arr[d] = arr[d+1] + arr[d+1] = swap + } + } + "; + let tokens = tokenize(raw); + let tree = parse(tokens, Some(raw.to_string())); + assert!(tree.is_ok()) +} + +#[test] +#[ignore] +fn test_uninitialized_variables() { + let raw = " + fn main() { + let x + let y + } + "; + let tokens = tokenize(raw); + let tree = parse(tokens, Some(raw.to_string())); + assert!(tree.is_ok()) +}