This is a boilerplate for creating your own languages for various use cases. You can even create your own programming language from scratch!

Overview

Node.js E2E Testing

Bootstrap compiler

This is a bootstrap compiler that can be used to compile to compiler written in the target language. You can write a compiler in the target language and compile it with this compiler, and create a brand new language

How to use

  1. Write a compiler in the target language
  2. Compile it with this compiler
  3. Run the compiled compiler

You can learn more about this chicken-egg problem in Wikipedia.

To learn more about how to run this code, check this section.

What this compiler can do

The compiler is pretty basic, yet it is capable to do a lot of the hardwork. It can:

  • Add & subtract numbers
  • Parse params and arguments of function calls
  • Parse nested block statements and outputs the result in a tree structure, called Abstract Syntax Tree.
  • Parse import and import from statements

You can learn more about abstract syntax trees here

How to extend this compiler

There are some steps to extend this compiler if you want to create your language.

  1. In tokenizer (tokenize function, also called the lexer), you need to add the tokens that you want to use in your language. For example, if you want to use namespace as a keyword, you need to add it to the tokens array.
  2. In parser (parse function), you need to add the rules for your language. Take the namespace example for instance, you can use the switch case statement at parser.ts:181 to add your own rules, keyword etc.
  3. Next up, you need edit the transform function (transform function) to transform the base syntax tree to an abstract syntax tree that your code generator will be able to understand.
  4. Finally, you need to edit the code generator (generate function) to output the code to your source language, that the computers will be able to parse.

How to work with this compiler

  1. Clone the repo, I recommend using Github Desktop, it has awesome features.
  2. Install the dependencies:
yarn install
  1. Run the compiler. You can ts-node for this, or you can just use the build output.

On Darwin-like systems:

yarn compile:darwin && node src/parser

On Windows:

yarn compile:win && node src/parser

Further work on this repo

I will be working on this repo to make it more powerful and more understandable. This code really does need a refactoring, but I won't be adding any new features, nor accepting extensions via pull requests.

How to contribute

If you want to contribute, you can fork the repo and make a pull request. I will review it and merge it.

See the CONTRIBUTING.md file for more information.

License

This project is licensed under the Apache License - see the LICENSE file for details

You might also like...

Collection of benchmarks of functional programming languages and proof assistants.

Collection of benchmarks of functional programming languages and proof assistants.

Functional Benchmarks This repository contains a collection of benchmarks of functional programming languages and proof assistants. It is split in two

Dec 12, 2022

This project is about building a web application to translate languages using language translator API.

This project is about building a web application to translate languages using language translator API.

Language Translator App A web application to translate multiple languages Want to see live preview » ✧ View Demo ✧ Report Bug ✧ Getting Started ✧ Inst

Dec 19, 2022

This React-Based WebPage allows the client/user system to create their own blog, where users can publish their own opinions.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Jul 28, 2022

A web app which help you to save you a list of your favorite books, they will be saved on your local storage to never loose them even if you close the page. Built wiht JavaScript

Awesome Books In this project I build a page to save a list of your favorites books, you can add new books, delete it and they will be saved in the lo

Dec 17, 2022

Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

May 18, 2022

Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

May 3, 2022

Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

Jan 3, 2023

An even simpler wrapper around native Fetch to strip boilerplate from your fetching code!

An even simpler wrapper around native Fetch to strip boilerplate from your fetching code!

Super lightweight (~450 bytes) wrapper to simplify native fetch calls using any HTTP method (existing or imagined). Features Fully typed/TypeScript su

Dec 28, 2022

Template to showcase different use-cases about Ionic, Firebase, Capacitor

Ionic, Angular, Capacitor, and Firebase Template This is a starter templates for projects using Ionic, Angular, Capacitor, and Firebase. It covers the

Oct 6, 2022
Comments
  • Update LICENSE

    Update LICENSE

    Description

    How has this been tested?

    Types of changes

    • [ ] This change is either a code refactoring or a bug fix (non-breaking change which fixes an issue)
    • [ ] This change requires a documentation update

    Checklist:

    • [x] I have read the CONTRIBUTING document.
    • [x] I have updated/added README.md file.
    • [x] I have added tests to cover my changes.
    opened by kuzeeeyk 0
Owner
Kaan
Backend engineer, mainly experienced in Javascript. Nuxt.js enthusiast ✨ Discord ━ kaan.#1337
Kaan
When a person that doesn't know how to create a programming language tries to create a programming language

Kochanowski Online Spróbuj Kochanowskiego bez konfiguracji projektu! https://mmusielik.xyz/projects/kochanowski Instalacja Stwórz nowy projekt przez n

Maciej Musielik 18 Dec 4, 2022
A mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases.

This is a mobile web application to check the data on the total covid19 confirmed cases and deaths, check data for all countries with recorded cases. It also has a details page to check for the statistics for each region/state if available.

Solomon Hagan 7 Jul 30, 2022
JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

JIT Compiler is a open source online code compiler. You can run more than 40+ most popular programming languages in your browser just-in-time using jitcompiler.

Rajkumar Dusad 36 Jan 5, 2023
Write "hello world" in your native language, code "hello world" in your favorite programming language!

Hello World, All languages! ?? ?? Write "hello world" in your native language, code "hello world" in your favorite language! #hacktoberfest2022 How to

Carolina Calixto 6 Dec 13, 2022
microregex is an open source and highly curated catalog of regular expression patterns. It offers programmers RegEx snippets that can be quickly exported into a variety of programming languages and distributed around teams.

microregex - A catalog of RegEx patterns View Demo · Report Bug · Request Feature Loved the tool? Please consider contributing ✍️ to help it improve!

Sunit Shirke 4 Oct 25, 2022
Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

CookBook - Hacktoberfest Find the book you want to read next! PRESENTED BY What is CookBook? A cookbook in the programming context is collection of ti

GDSC-NITH 16 Nov 17, 2022
A web component that allows you to run high level programming languages on your websites (static websites included!)

Code-Runner-Web-Component A web component that allows you to run high level programming languages on your website via the public Piston API Show your

Marketing Pipeline 28 Dec 16, 2022
Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this workshop, we'll look at some more advanced use cases when building Remix applications.

?? Advanced Remix Workshop Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this

Frontend Masters 167 Dec 9, 2022
This will create a REST API using Express JS and MongoDB removing the hassle of creating everything from scratch.

rest-api-init Fastest way to create REST API with Node.js, Express.js & MongoDB. Prerequisites Node.js needs to be installed. MongoDB Compass needs to

Souvik Das 7 Dec 3, 2022