Giter Club home page Giter Club logo

upa-compiler's Introduction

UPA Compiler

A compiler for a custom programming language, named UPA, created to learn basic concepts regarding the compiler theory, parsers and lexical analysers. Essentially, this language is a formal translation of the C language to Brazilian Portuguese.

Operations that are implemented are:

  • Variables and function declaration;
  • Assign operation;
  • Printing function;
  • Basic math operations;

For a full documentation on the language, please, refer to the documentation under /docs folder.

Creating the Compiler

To get this compiler to work, we first have to (from the src directory):

  1. Generate headers and the syntactic analyser:
$ bison -d upa.y
  1. Then, we must generate the lexical analyser:
$ flex upa
  1. Finally, we are able to generate the compiler itself:
  • For Linux environment:
$ gcc -g -o upa upa.tab.c lex.yy.c upa.c -lm
  • For Windows:
$ gcc -g -o upa upa.tab.c lex.yy.c upa.c -lfl
  • For MacOS:
$ cc -g -o upa upa.tab.c lex.yy.c upa.c -ll

Running Examples

Under /src/examples you will find some examples for better understanding of language syntax. Just like a normal compiler, the code can be compiled and executed as it follows (from the src directory):

$ upa ./examples/ex1.upa
$ upa ./examples/ex2.upa
$ upa ./examples/test.upa

References

This work was vastly based on flex & bison: Text Processing Tools, by John Levine, published by O'Reilly Media, Inc and its GitHub repo.

upa-compiler's People

Contributors

domminiks avatar

Watchers

 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.