Skip to content

igor-240340/CompilerC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler C

The very basic C compiler for fun and education written in C++. It's just a starting point.

It's mostly based on Nora Sandler's "Writing a C Compiler" and Robert Nystrom's "Crafting Interpreters".

How it works

For now can compile just a simple main function with return statement.

  1. Tokenizes source code with regexps.
  2. Recursive descent parser builds an AST for C.
  3. Then we build an AST for Assembly representation.
  4. Finally we walk through Assembly AST and generate Assembly instructions compatible with MASM.

To build exe from output assembly file run masm_build.bat.

Note

You have to have Visual Studio installed so x64 Native Tools Command Prompt is available.
You can either to run x64 Native Tools Command Prompt and then locate and run masm_build.bat
or you can just locate ml64.exe and add it's directory to Path so you can run masm_build.bat from anywhere.

About

Educational C compiler

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published