GithubHelp home page GithubHelp logo

gmh5225 / csgo-compiler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xinyu-evolutruster/csgo-compiler

0.0 1.0 0.0 2.73 MB

CsGo compiler compiles a self-designed language with features in both C and Golang, using flex, bison and LLVM.

Shell 0.51% C++ 61.98% Makefile 1.41% HTML 2.01% Yacc 23.58% Lex 10.51%

csgo-compiler's Introduction

CsGo

Introduction

The CsGo compiler compiles a self-designed language with features in both C and Golang, using flex, bison and LLVM.

Features

  • C macros (supports variadic macro)
  • function calls (supports recursion)
  • arrays
  • multiple variable assignment
  • AST visualization

Install

  • OS:Ubuntu 20.04
  • Dependencies
    • Flex 2.6.4
    • Bison 3.5.1 (GNU Bison)
    • LLVM 10.0.0

To install, first download the project by

git clone https://github.com/xinyu-evolutruster/CsGo-Compiler.git

Then run

cd ./src

to the main directory. Compile the project by running

make
# the compiler program is named 'mini'

To compile your program, run

./mini {filename}.gc
clang {filename}.o -o filename.out

Grammar Rules

variable declaration:

int num;
int arr[100];

variable assignment:

num = 1;
i, j, k = 1, 2, 3;
i, j, k = begin, end, arr[begin];

function declaration:

// func {func_name}({var_name}{var_type}, ...)(ret {var_type})

func main(void)(ret int);
func qsort(arr[] int, begin int, end int)(void);

I/O operations:

scanf("%d", len);
printf("%d\n", arr[i]);

conditional statements:

if(i<j){
  arr[i]=arr[j];
}

loop statements:

while(i<j){
  arr[i]=key;
  i=i+1;
}

macros:

#define ZERO 0
#define index(i,j,N) (i*N+j)

To learn more about the CsGo language, check ebnf.md to see all definitions.

File Description

  • src:where the source code is stored

    • mini.l: written in Flex, performs lexical analysis and generates all the tokens

    • mini.y: written in Bison, performs syntactic analysis and generates the AST (Abstract Syntax Tree)

    • ast.h: defines all the nodes in the AST

    • ast.cpp: implements the AST

    • CodeGenerator.cpp: generates the intermediate representation

    • ObjGenerator.h: header file for object code generation

    • ppMacro.h: header file for macro definition

    • ppMacro.cpp: the implementation of macros

    • gentest.sh: script file used to generate object code and perform all tests

    • tree.json: JSON file generated from the AST structure

    • tree.html:visualization of the AST

  • test: stores the test cases

    • qsort

      • qsort.gc:implements quick sort
      • linux-amd64:the test file
    • matrix

      • matrix.gc:implements matrix multiplication
      • linux-amd64:the test file
    • course_assist

      • c_assist.gc:implements a program to assist in online course selection
      • linux-amd64:the test file

csgo-compiler's People

Contributors

xinyu-evolutruster 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.