Code Monkey home page Code Monkey logo

compiler's Introduction

Compiler

Compiler from C-like programming language to LLVM

Language description

PL has static typing with simple datatypes and functions.

Entry point is main function with type int:

int main(){
  return 0;
}

Full grammar for PL is available here

Datatypes

  • int - standard 32-bit integer number
  • bool - boolean with two possible values: true and false
  • string - string value with access to characters by index
  • void - type for function, which returns no value

Operators

There is only a brief overview. Please, see examples for more.

  • while - standard while cycle, which keeps running until condition is true. Supports break and continue operators
  • if/then/else - conditional operator with optional else clause
  • switch - conditional operator for choice based on value equality
  • union - operator for uniting bits for different variables

Built-in functions

Again only a brief everview. Please, see examples for more.

  • read - read values from standard input
  • write - write value to standard output (please, use \0A for new lines)
  • length - returns length of a string
  • ==, !=, &&, || - logic operators
  • +, -, *, /, % - arithmetic operators

Compiler optimizations

Same thing with examples =)

  • forward propagation - invokate function before declaration
  • constant folding - fold simple arithmetic expressions to constant value

Examples

All code examples listed in example_*.txt files for ability to compile and run them.

Compiler usage examples:

java -jar compiler.jar input.txt output.txt

compiler.jar - jar file, which could be built with Maven

input.txt - input code

output.txt - produced LLVM code

Also you can run compiler directly from Java

Please, use lli for running LLVM code.

compiler's People

Contributors

a-vasin avatar rabodaber 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.