Skip to content

zawan-ila/tiny-c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiny-c

A C compiler in javascript

tiny-c is a hobby compiler for a small subset of C 😊 This implementation of 8 queens is an example of what tiny-c can handle today. For more examples and features, check out the Tests directory

Usage

node cc.js <source file>

Features

Generates x86-32 assembly in GAS syntax, which is then assembled and linked by GCC.

Has support for:

  • Integers and Integer Arrays only
  • ~, -, !
  • +, -, *, /, &&, ||, <, >, >=, <=, ==, !=
  • All ops have precedence as defined by the C standard
  • Local and Global variables
  • For loops
  • If Else conditionals and the ?: operator
  • C scoping
  • Functions

Implementation

Lexer

The lexer is implemented in clex.js. It uses simple regex matching to tokenize the source file

Parser

The parser is implemented in cpars.js. It uses recursive descent for everything.

ASM Generator

The code generator is implemented in cgen.js. It takes is the AST generated by the parser, traverses and generates assembly code.

About

C compiler created in Javascript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published