Giter Club home page Giter Club logo

simple-compiler's Introduction

Simple Compiler

Table of contents

Description

A simple C-like compiler built using Flex and Bison.

(return to top)

Requirements

  • Linux (Ubuntu, ...etc)
  • GCC
  • Flex
  • Bison

(return to top)

How to run

  • Install gcc
  • Install Flex using sudo apt-get install flex
  • Install Bison using sudo apt-get install bison
  • Run make all in the project folder
  • Type the code in a text file (input.txt) then run ./run.out < input.txt

(return to top)

Capabilities

datatypes

int integer_number = 5;
float float_number = 10.0;
char character = 'c';
string str = "hello world";
bool istrue = true;

(return to top)

enum types

  • Must be defined in the global scope
  • Defined values must start with $
enum enum_type = {$hello, $goodbye};
enum enum_type x = $hello;

(return to top)

constant declaration

const int integer_number = 5;
const float float_number = 10.0;
char character = 'c';
const string str = "hello world";
const bool istrue = true;

(return to top)

if-else statement

int x = 0;
int y;
if (x >= 0 && x < 5)
{
    y = 1;
} else if (x >= 5 && x < 10)
{
    y = 2;
}
else
{
    y = 3;
}

(return to top)

switch statement

  • Works with all datatypes
int x = 5;
switch(x)
{
    case 1:
    break;
    default:
    break;
}

(return to top)

loops

for loop

for (int i = 0; i < 5; i = i + 1)
{
}

(return to top)

while loop

int x = 5;
while (x <= 10)
{
    i = i + 1;
}

(return to top)

repeat-until loop

int x = 5;
repeat {
 x = x + 1;
} until(x <= 10);

(return to top)

functions

  • Must be defined in the global scope
  • Must start with keyword func
  • Can be of type int, float, char, string, bool, and void
  • All non-void functions must have a return value
func int sum (int x, int y)
{
    int result = x + y;
    return result;
}

(return to top)

simple-compiler's People

Contributors

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