Code Monkey home page Code Monkey logo

toco's Introduction

Toco

Toco is a small toy compiler using Flex (Lexer), Bison (Parser) and LLVM for generating the Assembly

Installation requirements

In order to build Toco you need Flex, Bison, LLVM and a recent C++ compiler. If you're on macOS you may use homebrew for installing all the dependencies:

$ brew install flex bison llvm
$ export PATH="/usr/local/Cellar/flex/2.6.3/bin:$PATH"
$ export PATH="/usr/local/Cellar/bison/3.0.4/bin:$PATH"

Basic compiler toolchain

Following are the different parts of Toco which will parse source code and transform it into a binary

+----------+    +----------+    +----------+
| Lexical  |    | Semantic |    | Assembly |
| Analysis |--->| Parsing  |--->|          |
| (Flex)   |    | (Bison)  |    |  (LLVM)  |
+----------+    +----------+    +----------+

The lexer (compiler frontend) takes some source code (text) as input and generates a sequence of tokens (strings with an assigned and identified meaning, for instance identifiers, keywords, numbers, brackets etc.)

The semanting parsing part takes the sequence of tokens and generates an abstract syntax tree (AST). We will use Bison for this part.

Finally we traverse our previously generated AST and generate byte code / machine readable code for each node using LLVM.

Defining the grammar of Toco

As a first step, we will use the well known C-like syntax for Toco, since this is easy to parse and fairly simple. For instance, the following snippet will be valid code for Toco

int add_two_numbers(int a, int b) {
    int res = a + b;
    return res;
}

toco's People

Contributors

newproggie avatar

Watchers

 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.