Skip to content

Commit 3f78aee

Browse files
committed
Added command
1 parent d862cd5 commit 3f78aee

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

LANGUAGE_DOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- `LOC [x]` - Set the line the command to the execution point number `x`. DO NOT use this is combination with other commands, it should be standalone. **WARNING: You can only have 1,000 execution points in one program (but you can change where**
77
- Move commands: `LEFT` and `PREV` go backwards, while `RIGHT` and `PREV` go forwards (to be added)
88
- `WRITE [x] (y)` - Writes `x` to the current position. If `y` is specified, it will use `y` rather than the current position.
9-
- `SWITCH [x] (y)` - Similar to `WRITE` but switches the value from it's current position. **(Use `NOT` and `WBOOL` instead)**
9+
- `SWITCH [x]` - Similar to `WRITE` but switches the value from it's current position.
1010
- `END` - Place at end of file, will end your program the moment it is seen
1111

1212
### Logic

src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,20 @@ fn main() {
3737
// Print regexes
3838
let basic_print_regex = Regex::new(r"(?<=PRINT )\d*").unwrap();
3939
let second_print_param = Regex::new(r"(?<=PRINT (0|1) ).*").unwrap();
40+
41+
// Generic
42+
let generic_int_param_regex = Regex::new(r"\d+").unwrap();
43+
4044
// To resize the vector see: https://stackoverflow.com/a/54887778
4145
let mut jump_list = vec![0; 1000];
4246
let mut memory_line = vec![false; 8];
4347

4448
let mut current_location: usize = 0;
4549
let mut current_line: usize = 0;
4650

51+
// Uncomment for debugging
52+
// println!("{}", line);
53+
4754
// Itterate over lines
4855
for current_line in 0..lines.len() {
4956
let line = lines[current_line].clone();
@@ -223,6 +230,15 @@ fn main() {
223230
memory_value
224231
);
225232
}
233+
} else if line.contains(&"SWITCH") {
234+
let location_string = generic_int_param_regex
235+
.find(&line)
236+
.unwrap()
237+
.unwrap()
238+
.as_str();
239+
let location = location_string.parse::<usize>().unwrap();
240+
let value = memory_line[location];
241+
memory_line[location] = !value;
226242
}
227243

228244
// Uncomment for debugging

src/test/switch.trng

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INIT 1
2+
WRITE 1 0
3+
SWITCH 0
4+
BIT PRINT 0
5+
END
6+
// Expected output: `1`

0 commit comments

Comments
 (0)