Coder Social home page Coder Social logo

mongacomp's Introduction

MongaComp is a compiler for the Monga language, a small C-like programming language designed by Roberto Ierusalimschy at PUC-Rio. More information of its design can be found here.

Requirements

  • C compiler
  • make
  • flex
  • bison
  • bash
  • clang/llc (llvm compiler)

Obs.: rules.lex was developed using flex. It should also work on lex, but it was never tested. Obs.2.: grammar.y was developed using bison. It should also work on yacc, but bison's output should be taken over yacc's, in case they differ.

Getting Started

  • First, use make to compile the project:
make

make will generate a executable file named comp. comp reads from standard input and outputs a file named a.ll and only then calls clang to generate a binary named a.out.

Usage examples

cat test/helloWorld.monga | ./comp
./a.out
cat test/test6.monga | ./comp
./a.out -c 

Usage Description

<string input> | ./comp [options] [clangOptions]
clangOptions

clangOptions will be redirected to clang in compile time as-is.

options
noBin

noBin flag does not emit a binary file a.out.

./comp -noBin 
noTree

noTree flag does not emit the program's AST.

./comp -noTree
noCode

noCode outputs only the program's AST.

./comp -noCode

Tests

To run the tests run:

make test

For binary compilation only, run:

make testbin

The tests aim to check syntax, types and variables. It should output the messages "Syntax OK" and Types OK before printing the AST and compiling your program into the files a.ll and a.out. The file a.out can be executed by running ./a.out.

For checking the file only, run:

make testchecks

For testing only the lexical scope, run:

make testlexical

For testing only the syntactical scope, run:

make testsyntax

Clean binary files

To clean builds, use:

make clean

Folder structure

src/ contains the sources:

  • rules.lex
  • lex.h
  • grammar.y
  • grammar.c
  • grammar.h
  • main.c
  • ...

lex.c is generated by compiling rules.lex with flex. Likewise grammar.c and grammar.h by compiling grammar.y with bison.

test/ contains MongaComp test suites. Each folder is a collection of test cases. Each test has a name and consists of two files: name.monga and name.answer name.monga is the input the compiler receives and name.answer, the expected output. The result and the answer are compared textually. If they are equal, the test is said to be OK. If they are different, a problem is found and the difference is outputted.

Each test suite has its own script.

temp/ is a folder for temporary files during a given compilation.

mongacomp's People

Contributors

lucasmw avatar luizperes avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

luizperes

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.