Code Monkey home page Code Monkey logo

mangacc's Introduction

MangaCC

GUI

Language Descriptions

Tokens

1- Variable and constant Declaration

int x;
int x = 5;
const int x = 5;
string x = "Hello";
string x = "c";
  • Available types
    • int
    • float
    • string
    • bool

2- Mathematical and Logical expressions

  • Mathematical operator
    • +, -, *, /, %,
  • Logical operator
    • ==, !=, >, <, >=, <=
    • and , or , not , xor

3 - Assignment statement

x = 5;
x = "Hello";
x = 5.5;
x = true;

4 - If else statement

if (x == 5 and y == 10) {
  x = 10;
} endif
if (x >= 5 or y <= 10) {
  x = x +1 ;
} else {
  x = x - 1;
}
if (x < 5 and y > 10) {
  x = x + 1;
} else if (x > 5) {
  x = x - 1;
} else {
  x = 0;
} 

5 - While loop

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

6 - Repeat until

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

7 - For loop

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

8 - Switch case

switch (x) {
  case 1:
    x = 1;
    break;
  case 2:
    x = 2;
    break;
  default:
    x = 0;
}

9 - Function declaration

int func1(int x, int y) {
  return x + y;
}
void func2(int x) {
  x = x + 1;
}
int func3() {
  return 5;
}

10 - Function call

int x = func1(5, 10);
func2(5);
int y = func3();

11 - Block structure

{
  int x = 5;
  {
    x = x + 1;
  }
}

12- Comments

// This is a comment

13- Print

print("Hello World");
print(x);
print(5);
print(5+6);

14- Enum

enum Color {
  RED,
  GREEN,
  BLUE
}
enum Color c = RED;

How to run

  • There is a script named build.sh that generates the parser and lexer and takes test file from you as input argurmnt.

  • You can run the script by typing the following command in the terminal:

    ./build.sh if_test.c
    
  • Note: the test file should be in the test_cases folder.

  • It will print the tokens with its line number.

Quadraples Description

Quadraple Description
PUSH (value) Pushing (value) to stack
POP (ID) Pop value from stack to the (ID)
NOT (value) Getting complement of (value)
ADD (arg1) (arg2) (result) Adding (arg1) (arg2) and save value to (result)
SUB (arg1) (arg2) (result) Substracting (arg1) (arg2) and save value to (result)
MUL Multiply (arg1) (arg2) and save value to (result)
DIV Divide (arg1) (arg2) and save value to (result)
MOD Calculate the modules of (arg1) (arg2) and save value to (result)
AND Perform logical and between (arg1) (arg2) and save value to (result)
OR Perform logical or between (arg1) (arg2) and save value to (result)
XOR Perform logical xor between (arg1) (arg2) and save value to (result)
EQ Check the equality of the two operands and store the comparsion result in temp reg
NE Check the inequality of the two operands and store the comparsion result in temp reg
LT Check if the first operand is less than the second and store the comparison result in temp reg
GT Check if the first operand is greater than the second and store the comparison result in temp reg
LE Check if the first operand is less than or equal the second and store the comparison result in temp reg
GE Check if the first operand is greater than or equal the second and store the comparison result in temp reg
JMP L(): Unconditional Jump to label
JUMPZERO L(): Jump if the zero flag from previous command is zero
JMPNONZERO L(): Jump if the zero flag from previous command is non-zero
Convi (var/value) Convert float to integer
Convf (var/value) Convert integer to float

Contributors

mangacc's People

Contributors

ahmedihabb2 avatar github-actions[bot] avatar we2am-bassem avatar yahia3200 avatar yousif-ahmed avatar

Stargazers

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

Watchers

 avatar

Forkers

yousif-ahmed

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.