Giter VIP home page Giter VIP logo

compilers's Introduction

Compilers Study

This project aims to study compilers, how they work and how to build them. To achieve this, I'm building it's parts separately so that I can bring them together sometime.

The first part is the scanner.

Scanner

I implemented two scanners, one for JSON files and other for Java files. The first one aims to separate structuring from data tokens. That said, it identifies curly braces, colons and strings.

The java one identifies keywords, operators, identifiers and other java structure stuff, although there are some things that are missing (for example float literals, string literals, addresses, hexadecimal, etc).

Testing the project

You can test both scanners out. Let's start with the JSON one. First clone the repo using git clone https://github.com/Lorenzobattistela/compilers.git Then: cd compilers/scanner/json

If you're going to change one of the following files: main.c scanner.flex, make sure you have dependencies installed, because you need to recompile. You need gcc and flex:

To install flex: sudo apt install flex For windows, follow this.

If you did not change anything, simply make sure you have a file named somefile.json at compilers/scanner/java and then run the executable with:

./scanner.exe

You'll see the following output (using the same json i did):

output

If you changed anything, before running the executable, compile it with: flex -o flex.c scanner.flex gcc -o scanner.exe main.c flex.c

Now let's go to the Java project:

cd compilers/scanner/java

Make sure you have a file named test.java in the same directory. If you changed anything, before running the executable, compile it with: flex -o flex.c scanner.flex gcc -o scanner.exe main.c flex.c token.c

And run the executable with:

./scanner.exe

You'll se an output like:

java output

Feel free to contribute and report any errors!

Parser

To run the parser, make sure you have bison and flex installed. Then, run the following commands: make This will result in a calc.exe file, and you can simply run it with: ./calc

compilers's People

Contributors

lorenzobattistela 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.