Giter Club home page Giter Club logo

c--compiler's Introduction

C-- Compiler

C-- Compiler is a compiler for a subset of C language implemented by C++. It includes 4 components:

  • Lexical Analyzer
  • Parser
  • Semantic Analysis
  • Code Generation

Each component is able to be compiled and ran independently. Each of them contains code in previous compiler construction phases.

make lexicalAnalyzer
make parser
make semanticAnalyzer
make codeGeneration

Lexical Analyzer

Lexical Analyzer can recognize tokens in defined language and ignore white spaces and comments(enclosed inside /*...*/). The principle function is getToken() that returns the next token. The main function contains a loop that calls getToken(). This program will print out token class returned and the string value.

TODO: attach DFA graph

Parser

Built followed by revised LL(1) grammar(LL(1) grammar file is under Parser folder). Given an input, Parser either reports an appropriate error message if it finds a syntax issue , or constructs an abstract syntax tree and prints it out in preorder.

Semantic Analysis

Semantic Analysis can detect following semantic error:

  1. undeclared variables and functions
  2. multiple occurrences of the same variable or function name in the same scope
  3. parameters error: wrong number or wrong type
  4. break statements must occur in a loop

For each error, it will print an appropriate message and exit. If the program has no semantic issue, it will print out necessary information contained in the symbol table for each scope including the names and their associated semantic information.

Code Generation

Code Generation produce instructions following IBM rules. You can run and test your output instructions in modified "Tiny Machine" from Kenneth C. Louden(ibm.c). Some future work can be done, like tail recursion optimization.

c--compiler's People

Contributors

codecodecodesde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

c--compiler's Issues

Getting no output.

Hi ,
I tried running your code , but I am unable to get any output at all. Any suggestions?

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.