@bitloops/bl-transpiler
TypeScript icon, indicating that this package has built-in type declarations

0.7.5 • Public • Published

npm version FOSSA Status

Bitloops Language Transpiler

What is a transpiler?

A transpiler is a type of translator that takes the source code of a program written in a programming language as its input and produces an equivalent source code in the same or a different programming language.

Structure

Transpiler is composed by the following building blocks:

The transpilation follows the flow mentioned below:

Architecture of a transpiler

  1. The code in the original (bitloops) language is parsed by a language parser which is ANTLR in our case, in order to create an AST. Specifically in ANTLR's implementation in order for ANTLR to be able to parse the original language, two files are needed, to specify the language grammar in order for ANTLR to create the AST (we specifically use ANTLR's visitor functionality):

    • The Lexer file (e.g. BitloopsLexer.g4)
    • The Parser file (e.g. BitloopsParser.g4)
  2. After the AST is created there is a step to create an intermediate model. The intermediate model is a data tree structure model which will be used to generate the AST target language tree. In this step validation logic for this tree could be added.

  3. Then the intermediate tree can be used as base to generate the AST target language tree which will have the characteristics needed to create the actual code for the target language. <<This step has not been implemented yet in our case.>>

  4. The final step is to create the actual code in the target language.

Transpiler Folder structure

The transpiler folder structure can be found at transpiler/src. More specifically:

  • Folder transpiler/src/parser contains all the logic concerning the ANTLR parsing from the original bitloops language to AST of original language. Here the ANTLR grammar is defined via the lexer and parser g4 files. Currently we have two different grammars for the setup and for all the other elements which can be found at transpiler/src/parser/setup and transpiler/src/parser/core respectively.

  • Folder transpiler/src/ast contains the implementation for the part AST -> Intermediate Model. The setup functionality may be found at the transpiler/src/ast/setup. All the others elements of the language, which can be found in the transpiler/src/ast/core

  • Folder transpiler/src/target contains the implementation from the intermediate model to the target language. Currently only implementation for typescript as a target language exists.

Package Sidebar

Install

npm i @bitloops/bl-transpiler

Weekly Downloads

1

Version

0.7.5

License

GPL-3.0

Unpacked Size

15.2 MB

Total Files

9609

Last publish

Collaborators

  • varagos
  • giorgosnty
  • elli
  • antonissar
  • danias