You are browsing as a guest. Sign up (or log in) to start making projects!

tux

@tux

Joined June 16th, 2026

  • 4Devlogs
  • 4Projects
  • 0Ships
  • 0Votes
A proud American.
Open comments for this post

10h 10m 6s logged

So, my last C compiler I forgot to install Wakatime 😅, so this is a revamp of the last C compiler, but I’m applying some knowledge to this one.

Now I kicked the whole thing off with a few different C# projects and scaffolded. The libraries I chose for this project are Pidgin, System.CommandLine, and Serilog.

For my first commit I already had some work done, but it was 3.6k LOC across 64 files and it had a working lexer with keyword/punctuator recognition and trivia handling. It had a recursive-descent parser with expression parsing, statement parsing, and declaration parsing. I had AST node types as C# records for expressions, operators, and statements with x86 MASM code generation with expression and statement lowering and a symbol table. I had a CLI with a few different flags and what not. And quite a few unit tests (generated by my pookie Claude) and yeah.

Now a little later(yesterday) I added if/else control flow with a IfStatement AST node with all sorts of things and else keyword and all sorts of things. Added a semantic analyzer to validate if-statement conditions and Boolean compat. Now last night I did have Claude go through and add some unit tests and cleanup the codebase, so removing unused using statements and cleanup the parser and remove warnings. Also orchestrated it to refactor a bit of the parser into a few different files instead of one big file and had it fix an issue with a diagnostic code being reused that was–well–wrong.

Now I will say the biggest pain in my butt has been naming conflicts with Pidgin, but that’s not too bad.

2
0
41
Open comments for this post

12h 16m 48s logged

So I reused a lot of the previous work done for my C++ compiler in C#, but instead of targeting IL it’s targeting straight ASM, soooo yeah. Anyhow lemme get into it:

The preprocessor system is fully implemented so you have #define, #undef, #ifdef, #ifndef, #if, etc.

The compiler supports C89 fully minus the STD, but I have char, short, int, long etc. all the floating point types const, typedef, volatile, etc.

Now for declarations you can have K&R functions, extern declarations, static locals, static arrays, multiple declarators, etc.

All arithmetic, bitwise, comparisons, logical, ternary, pre/post, casts, and assignments as expression operators are supported.

if/else, while, do/while, for, switch/case/default, break, continue, return, goto, labels, and compound statements are all supported.

Now the biggest part Code-gen it targets x86-64 Windows with full Microsoft ABI supported, variadic functions, struct return, 64-bit arithmetic, widening , string pool dedupplicatoin, floating point support, and a few more things.

Now Standard Library-wise stdio.h, stdlib, string.h, assert.h, cytpe.h, and time.h are the only supported ones as of right now while I continue to implement them.

1
0
38

Followers

Loading…