Browse Source

Add greeter example

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

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