Giter VIP home page Giter VIP logo

ybor's Introduction

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.

ybor's People

Contributors

roby2014 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.