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
node cc.js <source file>
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
The lexer is implemented in clex.js
. It uses simple regex matching to tokenize the source file
The parser is implemented in cpars.js
. It uses recursive descent for everything.
The code generator is implemented in cgen.js
. It takes is the AST generated by the parser, traverses and generates assembly code.