Giter Club home page Giter Club logo

c-mage's Introduction

Colon

A simple programming language compiler similar to c.

Tools used

Flex and Bison

Tokens

%token<STRING> IDENTIFIER STRING_DECLARATION ENUM_DECLARATION CONST_DECLARATION BOOL_DECLARATION CHAR_DECLARATION FLOAT_DECLARATION INT_DECLARATION PRINT
%token<INTEGER> INTEGER_CONSTANT
%token<FLOAT> FLOAT_CONSTANT
%token<CHAR>  CHAR_CONSTANT
%token<BOOL> TRUE_KEYWORD FALSE_KEYWORD
%token<STRING> STRING_CONSTANT

%token AND OR NOT EQ NE LT GT LE GE
%token IF ELSE WHILE FOR DO SWITCH CASE DEFAULT BREAK CONTINUE
%token RETURN VOID 
%token SINGLE_LINE_COMMENT 
%nonassoc IFX
%nonassoc ELSE
%nonassoc UMINUS

%type <STRING> enum_list
%type <STRING> enum_state
%type <STRING> enum_definition
%type <STRING> variable_type
%type <STRING> function_call
%type <node_type> expression
%type <node_type> const_expression
/* %type <STRING> expression_error */

%right '='
%left  OR
%left  AND
%left  EQ NE
%left  LT GT LE GE
%left  '+' '-'
%left  '*' '/' '%'
%right NOT

Allowed rules

  • Variable declaration
  • Const declaration
  • Enum declaration
  • Braced Statement
  • Statements
  • Control Statements ( If, while, do while, for )
  • Return, Break, Continue
  • Function delcaration ( with default values )

Symbol Table

sym_table

Intermediate Code Syntax

Test op evaluates jump conditions based on operand op, ex: Test x ; JZ L1 ;
L: Label with number =
JZ L Jmp if equal zero to Label
JNZ L Jmp if not equal zero to Label
JMP L Unconditional Jump to label
STO src, dest Store ‘src’ to ‘dest’
ADD s1, s2, r r = s1 + s2
MUL s1, s2, r r = s1 * s2
DIV s1, s2, r r = s1 / s2
SUB s1, s2, r r = s1 - s2
MOD s1, s2, r r = s1 % s2
LT s1, s2, r r = s1 < s2
GT s1, s2, r r = s1 > s2
LE s1, s2, r r = s1 ≤ s2
GE s1, s2, r r = s1 ≥ s2
EQ s1, s2, r r = s1 == s2
NE s1, s2, r r = s1 ≠ s2
AND s1, s2, r r = s1 && s2
OR s1, s2, r r = s1
INC s, r r = s +1
DEC s, r r = s - 1
NOT s, r r = ! s
NEG s, r r = - s

Code Playground

image

c-mage's People

Contributors

ahmadjamal01 avatar hoskillua avatar passant-abdelgalil avatar ghiathajam avatar

Stargazers

 avatar Donia Esawi avatar Mohamed Khaled avatar Mostafa Wael avatar Ahmed Ihab 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.