Code Monkey home page Code Monkey logo

c--compiler's Introduction

C-- Compiler

What does it do?

It is a compiler for C-- programming language. (You can see C-- Documentation)

In Phase 1, the lexer of C-- is made in Cmm.g4 using Antlr.

In Phase 2, the AST is constructed from lexical analysis and the symbol table is filled. Finally, it shows up semantic errors.

In Phase 3, the remaining errors are shown and type-checking is done.

In Phase 4, Java bytecode of the C-- program will be generated.

Phase 1 (Lexer)

Checking grammar of language.

Phase 2 (Semantics)

Errors

  • Cyclic Dependency
  • Duplicate Function
  • Duplicate Struct
  • Duplicate Variable
  • Function & Struct Name Conflict
  • Variable & Function Name Conflict
  • Variable & Struct Name Conflict

Phase 3 (Type-Checking)

Errors (Main Errors)

  • Reference to an undeclared variable
  • Unsupported usage of operand type
  • Type-checking all conditions and statements
  • Unsupported usage of function calls
  • Not validation of left side of assignment
  • Return type validation
  • and all other compile errors...

Phase 4 (Code Generation)

  • All of the code generation process is handled in this phase.
  • This compiler generates Java bytecode using jasmin assembler.
  • After all, the Smoola program is run on Java Virtual Machine.

How to run?

Step 1:

You should at first generate Cmm.g4 grammer using Antlr. For more info about Antlr visit This Page.

Step 2:

You should run the whole Java project. For running that you can use CmmCompiler.java script. If you run this code, it runs the whole project easily.

Step 3:

After running the Java project, Java bytecode will be generated in the output folder. Then it's time to run the generated code. First go to the output directory in terminal. Then run

java -jar jasmin.jar *.j

and then it will create corresponding Java classes. Then you should run the program through executing your main class:

java <MainClass>

c--compiler's People

Contributors

kalhorghazal avatar

Stargazers

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