Browse Source

Add greeter example

github-actions
Garrit Franke 2 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/
.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) {
return 2 * n;
main :: () {
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,
'*' => Star,
'/' => match self.first() {
'/' => self.comment(),
'/' => {
self.bump();
self.comment()
}
_ => Slash,
},
'=' => match self.first() {
'=' => Equals,
'=' => {
self.bump();
Equals
}
_ => Assign,
},
':' => match self.first() {

2
src/main.rs

@ -9,7 +9,7 @@ mod parser;
mod util;
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();
file.read_to_string(&mut contents)
.expect("Could not read file");

Loading…
Cancel
Save