Skip to content
Write a simple interpreter of C. Inspired by c4 and largely based on it.
Branch: master
Clone or download
lotabout Merge pull request #24 from krupan/grammar-fixes
some lesson 7 grammar fixes
Latest commit d1e64bb Apr 24, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
tutorial/en some lesson 7 grammar fixes Apr 24, 2019
.gitignore Initial commit Dec 23, 2015
LICENSE change LICENSE to GPL2 Dec 26, 2015 support 64bit target Apr 3, 2019
hello.c [ex] add example C file Dec 26, 2015
xc-tutor.c fix #21 typo of expression_type Apr 6, 2019
xc.c fix #21 typo of expression_type Apr 6, 2019

C interpreter that interprets itself.

How to Run the Code

File xc.c is the original one and xc-tutor.c is the one that I make for the tutorial step by step.

gcc -o xc xc.c
./xc hello.c
./xc -s hello.c

./xc xc.c hello.c
./xc xc.c xc.c hello.c


This project is inspired by c4 and is largely based on it.

However, I rewrote them all to make it more understandable and help myself to understand it.

Despite the complexity we saw in books about compiler design, writing one is not that hard. You don't need that much theory though they will help for better understanding the logic behind the code.

Also I write a series of article about how this compiler is built under directory tutorial/en.

There is also a chinese version in my blog.

  1. 手把手教你构建 C 语言编译器(0)——前言
  2. 手把手教你构建 C 语言编译器(1)——设计
  3. 手把手教你构建 C 语言编译器(2)——虚拟机
  4. 手把手教你构建 C 语言编译器(3)——词法分析器
  5. 手把手教你构建 C 语言编译器(4)——递归下降
  6. 手把手教你构建 C 语言编译器(5)——变量定义
  7. 手把手教你构建 C 语言编译器(6)——函数定义
  8. 手把手教你构建 C 语言编译器(7)——语句
  9. 手把手教你构建 C 语言编译器(8)——表达式
  10. 手把手教你构建 C 语言编译器(9)——总结


Further Reading:



The original code is licenced with GPL2, so this code will use the same licence.

You can’t perform that action at this time.