Skip to content
/ ybor Public

Simple interpreter for my *future* custom programming language

Notifications You must be signed in to change notification settings

roby2014/ybor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5fdb2f0 · Sep 29, 2022

History

24 Commits
Sep 19, 2022
Sep 29, 2022
Sep 19, 2022
Sep 28, 2022
Sep 29, 2022
Sep 19, 2022
Sep 19, 2022
Sep 19, 2022
Sep 29, 2022
Sep 19, 2022
Sep 29, 2022

Repository files navigation

ybor

Simple interpreter for my future custom programming language (ybor)

Info

Contains:

  • Lexer/Tokenizer // Transforms source input into list of tokens
  • Parser // Parses list of tokens into an AST (Abstract Syntax Tree)
  • Interpreter // Evaluates the expressions

Some examples of what it can do at the moment:

> 1+2 ;
3.0

> print 1+2 ;
3.0

> print 1+2*3 ;
7.0

> print (1+2)*3 ;
9.0

> 1+a
[line 1] ERROR at 'a': Expected valid expression

> print (1*2 ;
[line 1] ERROR at 'EOF': Expected ')'

> "hello" + "world" ;
AST: (+ hello world)
Result: helloworld

> "cool interpreter" - "cool " ;
AST: (- cool interpreter cool)
Result: interpreter

> -5 ;
AST: (- 5.0)
Result: -5.0

> -"invalid_unary" ;
AST: (- invalid_unary)
[line 1] ERROR at '-': Operand must be a number
Result: null

> 2 > 2 ;
AST: (> 2.0 2.0)
Result: false

> 2 >= 2 ;
AST: (>= 2.0 2.0)
Result: true

> 2 == 2 ;
AST: (== 2.0 2.0)
Result: true

> "abc" == "abc" ;
AST: (== abc abc)
Result: true

> "abc" != "cba" ;
AST: (!= abc cba)
Result: true

> var a = 3;
> print a;
3.0

> var b;
> b = 5;
5.0

> a == b;
false

> a = b;
5.0

> a == b;
true

why?

Lately I've been reading about Compilers / Interpreters, so this repository contains a basic project which I've been developing while reading Crafting Interpreters by Robert Nystrom. The code structure does not follow 100% the book's one. Use this as educational purposes if you can.

In case of any suggestion/error, create a issue/pull request.

About

Simple interpreter for my *future* custom programming language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages