Browse Source

Add greeter example

github-actions
Garrit Franke 3 years ago
parent
commit
f1ede63d5f
  1. 2
      .gitignore
  2. 7
      examples/greeter.sb
  3. 4
      examples/hello_world.sb
  4. 0
      examples/playground.sb
  5. 7
      examples_out/out.asm
  6. 4
      examples_out/out.js
  7. 10
      src/lexer/mod.rs
  8. 2
      src/main.rs

2
.gitignore vendored

@ -1,3 +1,3 @@
target/ target/
.vscode/ .vscode/
examples_out/ examples_out/

7
examples/greeter.sb

@ -0,0 +1,7 @@
main :: () {
return greet("Garrit");
}
greet :: (name) {
return "Hello " + name;
}

4
examples/hello_world.sb

@ -1,4 +1,4 @@
main :: (n) { main :: () {
return 2 * n; return "Hello World";
} }

0
examples/playground.sb

7
examples_out/out.asm

@ -1,7 +0,0 @@
.globl main
main:
.globl fib
fib:

4
examples_out/out.js

@ -1,4 +0,0 @@
function main(n) {
return 2 * n
}
console.log(main())

10
src/lexer/mod.rs

@ -165,11 +165,17 @@ impl Cursor<'_> {
'-' => Minus, '-' => Minus,
'*' => Star, '*' => Star,
'/' => match self.first() { '/' => match self.first() {
'/' => self.comment(), '/' => {
self.bump();
self.comment()
}
_ => Slash, _ => Slash,
}, },
'=' => match self.first() { '=' => match self.first() {
'=' => Equals, '=' => {
self.bump();
Equals
}
_ => Assign, _ => Assign,
}, },
':' => match self.first() { ':' => match self.first() {

2
src/main.rs

@ -9,7 +9,7 @@ mod parser;
mod util; mod util;
fn main() -> Result<(), String> { fn main() -> Result<(), String> {
let mut file = File::open("examples/hello_world.sb").expect("Could not open file"); let mut file = File::open("examples/playground.sb").expect("Could not open file");
let mut contents = String::new(); let mut contents = String::new();
file.read_to_string(&mut contents) file.read_to_string(&mut contents)
.expect("Could not read file"); .expect("Could not read file");

Loading…
Cancel
Save