Giter Site home page Giter Site logo

basemax / mylang Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 1.0 35 KB

A hobby compiler build by nearley. (Thanks from Toby)

License: GNU General Public License v3.0

JavaScript 100.00%
lexer compiler js nodejs nearley nearleyjs nearley-grammar grammar grammar-parser grammar-checker

mylang's Introduction

MyLang

A hobby compiler build by nearley.

Features

  • Lexer
  • Parser
  • AST Tree as JSON format
  • Generate JS as intermediate code

Statements

  • While loop
  • Variable
  • Print
  • Operator + - * / >= <= > < = :=

Using

$ node parser.js examples/hello-world.mylang
$ node examples/hello-world.js

Examples

Print

$ node parser.js examples/hello-world.mylang 
$ node examples/hello-world.js 
print 10

Loop

$ node parser.js examples/loop.mylang
$ node examples/loop.js
n := 1
while n < 10 {
	n := n + 1
	print n
}

Fibonacci

$ node parser.js examples/fib.mylang
$ node examples/fib.js
i := 1
n := 10
fi := 1
fii := 1
while i <= n {
	print fi
	temp := fi + fii
	fi := fii
	fii := temp
	i := i +1
}

TODO

  • For
  • Function
  • Array value
  • String value
  • Boolean value

© Copyright Max Base 2021

Thanks from Toby Ho and Nearley (https://nearley.js.org/)

mylang's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.