Giter VIP home page Giter VIP logo

compilerproject's Introduction

CompilerProject Structure

Overall input & output : see here

Header

  • Using import,
  • Ex:
    import stdio;
    import math;
    

Comment

  • Single line comment

    • Using //,
    • Ex:
      int a = 25;
      // this is single line comment
      
      int b = 123; // also valid here
      
  • Multi-line comment

    • Using /* */,
    • Support nested also,
    • Ex:
          int y = x sub 999; 
          /*multi line comment
              possible to have
              /* nested also */
          */
      
          discard c,d,e, /* valid comment */ f;
      

Prototype declaration

  • Format:
    FUNC_TYPE FUNC_NAME (DATA_TYPE1, DATA_TYPE_2...);
    
  • Example:
    int add(int,int, float);
    int scan();
    void add(int, float, double);
    

Starting point of execution

  • Defined as:
  • Ex:
    static void entryPoint(){
        // starts from here
    }
    

Variable

  • Supporeted Data type

    • int, float, double
  • Declaration:

    • Using:
      DATA_TYPE VAR1, VAR2;
      
    • Ex:
      int a;
      int b;
      
      int c,d,e;
      
  • Initialization

    • Using:
      DATA_TYPE VAR1 = const_value, VAR2 = calc_value, VAR3 = func_call;
      
    • Ex:
      int m = 102, n = m add 10;
      // m = 102, n = 112
      
      double e = @max(2,3),f;
      // e = 3, f = 0
      
  • Assignment

    • Using
      VAR = const_value or calc_value or func_call;
      
    • Ex:
          int z;
          z = 100; // constant
          z = 10 add 20; // calculated value
          b = @max(a,101); // function call
      
  • discard variable

    • Using
      discard VAR,VAR...VAR;
      
    • Ex:
      int a = 10;
      discard a;
      // can't access `a` anymore
      
  • Extra:

    • Initialized to 0 by default,
    • Error if duplicate variable is declared,
    • Error if assign value to undeclared variable,
    • All variables are become global once declared,
    • Variable remains gloabl until discarded explicitly,
  • Arithmatic operators

    • Addition(<add>),
    • Subtraction (<sub>),
    • Multiplication (<mul>),
    • Division (<div>),
    • Difference (<dif>),
    • Remainder (<rem>)
    • Ex:
      int a = 10, b = 5;
      int c = a <add> b, d = 10 <sub> a;
      // c = 15, d = 0
      
  • Conditional operators

    • less than (<lt>),
    • greater than (<gt>),
    • equal (<eq>),
    • not equals (<neq>)
    • less equal (<le>),
    • greater equal (<ge>)
  • justInCase - otherwise structure:

    • Equivalent to if - else,
    • Structure:
      justInCase(VAR_CON @ VAR_CON){
          // body
      }
      
    • Ex:
      a = 10; int c = 15;
      justInCase(5 <lt> 10 and a <lt> b and 10 <gt> 10 ){
          println("Condition is false");
      }
      otherwise{
          println("Executed else block");
      }
      
    • Output:
      Executed else block < - - - - - - - - - -
      
  • Loop

    • Using
      till( VAR_CON <COND_OP> VAR_CON ){
          VAR_CON = VAR_CON <ARITH_OP> VAR_CON;
      }
      
    • Example:
      int j = 55;
      till(j <gt> 0){
          j = j <sub> 15;
      }
      
    • Output:
      Iterating - 0, value: 55
      Iterating - 1, value: 40
      Iterating - 2, value: 25
      Iterating - 3, value: 10
      
  • Output to console

    • Using println(),
    • Structure:
      println(VAR_CON, VAR_CON, ... VAR_CON);
      
    • Comma(,) and space(' ') both are valid as separator,
    • Ex:
      float f1 = 243, f2=11;
      
      println(f1,f2);
      
      double height = 25;
      println("My height is: ",height "km");
      
    • Output is like
      243.000 11.000  < - - - - - - - - - -
      
      My height is: 25.000 km < - - - - - - - - - -
      

Run using

bison -d final.y
flex final.l
gcc final.tab.c prototype_list.c  lex.yy.c constant.c var_list.c -o app
app

compilerproject's People

Contributors

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