commit 80f4556786da166cc233bb8f4fdb497e54d75b3c
parent 237a1fae31acf577ef8625c3eabfe4bd96e81a9f
Author: ~karx <karx@tilde.team>
Date: Sun, 7 Feb 2021 18:16:02 +0000
Add support for commenting out lines
Diffstat:
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
@@ -24,6 +24,7 @@ The currently available opcodes are as follows:
- `p` - print out the arguments: `pHello World!` prints "Hello World!"
- `a`, `s`, `m`, `d` - add, subtract, multiply, and divide, respectively: `a2-2` adds 2 + 2.
- `l` - declare a variable: `lv9` declares variable `v` with value `9`; doing `p$v` prints out 9.
+- `#` - comment: the interpreter will skip this line.
Here's an example "Hello world" program:
@@ -58,7 +59,7 @@ Read [this guide](https://git-send-email.io) for more information.
- [x] Better documentation
- [ ] Ability to explicitly print math output and assign math output to variables
-- [ ] Add support for comments (should be pretty easy)
+- [x] Add support for comments (should be pretty easy)
- [ ] Unit testing and CI/CD
## License
diff --git a/src/main.rs b/src/main.rs
@@ -88,6 +88,7 @@ impl Program {
'm' => println!("{}", eval::do_math(self.args_or_vars(arguments), '*')),
'd' => println!("{}", eval::do_math(self.args_or_vars(arguments), '/')),
'l' => self.add_var(arguments),
+ '#' => {}, // Do nothing for comments
_ => panic!("SyntaxError: No such opcode: {}", self.pc)
}
}