Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Albab-Hasan/redix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redix

A C compiler written in C.

My goal for this project is to learn how compilers work by building a functional compiler. So far I've implemented a lexer, a parser and code generation. Currently it supports:

  • arithmetic operators: +, -, *, /
  • unary operators: -, ~, !
  • increment/decrement: prefix ++x, --x and postfix x++, x--
  • comparison operators: <, >, <=, >=, ==, !=
  • logical operators: &&, ||
  • ternary conditional: cond ? a : b
  • local and global variable declarations, assignments, and references
  • compound assignment: +=, -=, *=, /=
  • if/else statements
  • while loops
  • for loops
  • break and continue
  • multiple functions with up to 6 parameters and calls
  • void return type and bare return;
  • pointers: int *p, address-of &x, dereference *p, pointer parameters
  • pointer arithmetic: p + n, p - n, p++, p--, pointer difference, and p[i] indexing
  • // line comments and /* */ block comments

Building

make

Usage

./redix input.c
gcc -o out out.s
./out

Tests

make test

Test files live in tests/. Each file has a // expect: N comment on the first line indicating the expected exit code.

License

MIT

About

My attempt at building a C compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors