Giter Site home page Giter Site logo

giuliano-macedo / obc Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 174 KB

Simple version of C Compiler written in python with lark library

License: GNU General Public License v3.0

Python 91.58% Assembly 8.17% Makefile 0.25%
compiler python-3 sintaxis-analyzer semantic-analyzer lexer-analyzer

obc's Introduction

Build Status

OBC - Simple version of C NASM X86 linux Compiler

This project implements a compiler for a simplified version of C with error recovery using python and Lark parsing library

What is the difference between this language and C?

  • only has 2 data types, int and void
  • there is no preprocessor

it does not support the following C features

  • unary operators
  • bitwise operators
  • ternary operators
  • structs
  • pointers

for more information about it's syntax read src/grammar.lark

Builtin functions and variables

This language consists of the following builtin functions

declaration description
void putchar(int c) writes in the stdout the first byte indicated by the variable c.
void putstr(int str[]) writes in the stdout all the first bytes indicated by the variable str, it must be null-ended.
void putint(int n) writes in the stdout an integer n.
int getchar(void) returns single byte read from stdin.
int getint(void) returns integer read from stdin.
int SIZEOFINT represents the size in bytes of int variables (4)

Prerequisites

  • python >= 3.6 (some source files have literal string interpolation)
  • pip
  • nasm

Installing

Install all dependecies described in requirements.txt using pip

pip3 install -r requirements.txt

Usage

cd to the src directory

cd src

and call the compiler on some source file

./obc.py [SOURCE FILE PATH]

by default the following files representing the compiler's IO will be created:

  • tokens.dot,tokens.pdf, representing the lexer output
  • syntax_tree.dot,syntax_tree.pdf, representing the syntax analyzer output
  • symtable.dot,symtable.pdf,semantic_tree.dot,semantic_tree.pdf, representing the semantic analyzer output
  • tac.txt, representing the intermediate code generator output
  • code.asm, representing the code generator output
  • object.o, representing the asembler output (NASM)
  • [program_name], representing the linker output (ld)

for more options use /obc.py --help

obc's People

Contributors

danbailo avatar giuliano-macedo avatar

Stargazers

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