- 1. Introduction 2m 31s
- 2. Overview Of The Course 8m 44s
Creating a C Compiler From Scratch Video Course!
About this course
Learn to create your very own C compiler from scratch. In this course we develop a compiler that compiles a subset of the C Programming Language. By the time you finish all modules of this course you will be able to compile C programs that use pointers, structures, unions, arrays, functions, for loops, while loops. do while loops, if statements, switches and much more! This course includes all course modules!
Our compiler also has a preprocessor macro system allowing you to include header files and create definitions just like you would in any C file.
Your compiler is advanced enough to use the GCC standard library so we are able to call C functions from our compiler. Your compiler will be able to compile the C programming language.
This course does not rely on any frameworks we do everything from scratch to ensure the best possible learning experience for students
Module 1
In module 1 of this course we load our C source file that we wish to compile, into memory. We create a lexer to preform lexical analysis on the source input which will convert the source code into a bunch of tokens that our compiler can easily understand. We then pass the tokens through a parser to produce an abstract syntax tree. An AST describes the C program in a logical way that makes it easier for our compiler to understand. For example for the expression 50 + 20 you will end up with a root expression node that has a left operand that has a node of value 50 and a right operand that has a node of value 20. Breaking down problems in this way makes it much easier to create compilers.
Module 2 & 3
In module 2 and 3 of this course we create a code generator that produces 32 bit Intel assembly language that can then be passed through an assembler to produce a program binary that we can run. We also in this module create a resolver system which is responsible for taking a complicated expression such as "a->b.c.e[50] = 50" and breaking it down into simple steps and rules that our code generator can then easily follow. This abstraction is essential to ensure that the code generator does not become over complex. With the use of a resolver system we can ensure the code base remains clean.
Module 4
In module 4 of this course we create a preprocessor and macro system. This preprocessor system allows us to include header files in our C programs and also use a variety of macro keywords such as "#define" "#ifdef" , "sizeof" and many more.
Module 5
In module 5 we build a semantic validator which validates our C code. A semantic validator ensures that we are not setting variables that do not exist or accessing structures that arent there.
This is the only video course in the world that shows you how to create a C compiler, come and learn today!
What you'll learn
- Learn to create your very own C compiler from scratch.
- In this course we develop a compiler that compiles a subset of the C Programming Language.
- By the time you finish all modules of this course you will be able to compile C programs that use pointers, structures, unions, arrays, functions, for loops, while loops.
- do while loops, if statements, switches and much more!
Curriculum
249 Lessons • 39H 49M- 1. Installation & Setup 1m 22s
- 2. Preparing our Project 26m 33s
- 1. What is Lexical Analysis 6m 51s
- 2. Creating Our Token Structures 6m 38s
- 3. Preparing Our Lexer 19m 8s
- 4. Creating a number token 27m 24s
- 5. Creating a string token 4m 46s
- 6. Creating a operator token 28m 6s
- 7. Creating a symbol token 4m 45s
- 8. Creating a identifier token 5m 10s
- 9. Creating a keyword token 5m 50s
- 10. Creating a new line token 1m 18s
- 11. Creating a comment token 7m 18s
- 12. Handling quotes in the Lexer 5m 35s
- 13. Implementing Hexadecimal Numbers 8m 50s
- 14. Implementing Binary Numbers 4m 8s
- 15. Dealing with the parentheses buffer 5m 52s
- 16. Creating tokens outside of the input file 5m 41s
- 17. Creating number types 3m 21s
- 18. Finalizing the lexer 51s
- 1. What is parsing 5m 1s
- 2. Creating our parser structures 6m 5s
- 3. Writing our parser template 6m 4s
- 4. Creating our node file 7m 59s
- 5. Creating our first node 14m 19s
- 6. Creating an expression node 22m 2s
- 7. Dealing with precedence in expression - Part 1 12m 27s
- 8. Dealing with precedence in expression - Part 2 21m 19s
- 9. Dealing with precedence in expression - Part 3 2m 42s
- 10. Creating an identifier node 1m 44s
- 11. Implementing datatypes and keywords - Part 1 17m 23s
- 12. Implementing datatypes and keywords - Part 2 17m 59s
- 13. Implementing datatypes and keywords - Part 3 16m 56s
- 14. Implementing datatypes and keywords - Part 4 7m 55s
- 15. Understanding scopes 6m 41s
- 16. Implementing the scopes 21m 21s
- 17. Understanding Symbol Resolution 3m 18s
- 18. Implementing The Symbol Resolver 17m 37s
- 19. Implementing datatypes and keywords - Part 5 4m 43s
- 20. Implementing Variables - Part 1 16m 56s
- 21. Implementing Variables - Part 2 8m 46s
- 22. Implementing Variables - Part 3 21m
- 23. Understanding Array Declarations 3m 51s
- 24. Implementing the calculation of array sizes 5m 26s
- 25. Implementing Structures - Part 1 10m 34s
- 26. Implementing Structures - Part 2 1m 38s
- 27. Implementing Body's - Part 1 19m 28s
- 28. What is padding and alignment 4m 27s
- 29. Implementing datatype size functions 6m 51s
- 30. Implementing variable size functions 5m 16s
- 31. Implementing Alignment and Padding Functions 14m 1s
- 32. Implementing Body's - Part 2 12m 28s
- 33. Implementing Body's - Part 3 8m 25s
- 34. Scope offsets explained 11m 34s
- 35. Implementing parser scope entities and functionalities 4m 16s
- 36. Implementing the variable node scope offset - Part 1 16m 59s
- 37. Implementing the variable node scope offset - Part 2 2m 34s
- 38. Implementing the variable node scope offset - Part 3 7m 7s
- 39. Pushing variables to the scope 1m 35s
- 40. Implementing Body's - Part 4 15m 13s
- 41. Implementing Body's - Part 5 5m 39s
- 42. Implementing Structures - Part 3 17m 46s
- 43. Implementing Structures - Part 4 8m 41s
- 44. Initializing our symbol resolver 1m 25s
- 45. Testing our structure functionality 2m 33s
- 46. Error checking our structures 4m 17s
- 47. Project cleanup 2m 30s
- 48. Understanding Functions 7m 32s
- 49. Implementing The Function Structures 4m 54s
- 50. Parsing functions 22m 59s
- 51. Parsing functions arguments 9m 15s
- 52. Dealing with upward stacks 3m 34s
- 53. Changing the parsing of identifiers 35s
- 54. Res = 0 is missing 1m
- 55. Implementing expression parentheses 14m 30s
- 56. Implementing IF statement 9m 49s
- 57. Implementing Else And Else If 6m 30s
- 58. Fixing some compiler warnings 1m 37s
- 59. Implementing the return statement 4m 17s
- 60. Implementing for loops 11m 1s
- 61. Implementing while loops 4m 9s
- 62. Implementing Do While Loops 3m 26s
- 63. Implementing switch statements 13m 23s
- 64. Implementing continue and break 3m 35s
- 65. Implementing labels 5m 16s
- 66. Implementing goto 3m 43s
- 67. Implementing switch cases 4m 26s
- 68. Implementing tenaries 4m 56s
- 69. Implementing commas 1m 59s
- 70. Implementing array brackets 3m 16s
- 71. Implementing casts 5m 59s
- 72. Case indexes or our register case function 52s
- 73. Understanding Fixups 4m 29s
- 74. Creating our fixup core functionality 14m 8s
- 75. Integrating our fixup functionality into the parser 7m 7s
- 76. Parsing forward declarations 2m 3s
- 77. Parsing unions 8m 23s
- 78. Adjusting the function stack size 59s
- 79. Additional recording for nodes 19m 51s
- 1. Module 1 Summary 1m 59s
- 2. Module 2 Information 22s
- 1. The Code generator 2m 2s
- 2. Building the fundementals 7m 36s
- 3. Beginning the iteration of the AST 11m
- 4. Generating global variables 8m 42s
- 5. Understanding the label systems 9m 34s
- 6. Building the label system 16m 25s
- 7. Dealing with strings in the code generator 2m 45s
- 8. Building our string registration system 14m 30s
- 9. Implementing numerical values for global variables 2m 27s
- 10. Implementing string values for global variables 2m 36s
- 11. Fixing issue parsing strings 1m 27s
- 12. Stackframes 16m 43s
- 13. Building our stack frame functionality 19m 29s
- 14. The resolver explained 13m 49s
- 15. Creating the resolver - Part 1 29m 25s
- 16. Creating the resolver - Part 2 20m 43s
- 17. Creating the resolver - Part 3 11m 30s
- 18. How array offsets are calculated 10m 18s
- 19. Creating the resolver - Part 4 15m 26s
- 20. Creating the resolver - Part 5 9m 25s
- 21. Calculating structure and union offsets 10m 8s
- 22. Implementing the struct_offset function 12m
- 23. Creating the resolver - Part 6 12m 14s
- 24. Creating the resolver - Part 7 15m 31s
- 25. Creating the resolver - Part 8 15m 6s
- 26. Creating the resolver - Part 9 16m 18s
- 27. Creating the resolver - Part 10 15m 12s
- 28. Implementing unaries 18m 25s
- 29. Creating the resolver - Part 11 7m 29s
- 30. Creating the resolver - Part 12 8m 43s
- 31. Creating the resolver - Part 13 6m 58s
- 32. Creating the resolver - Part 14 9m 45s
- 33. Creating the resolver - Part 15 19m 26s
- 34. Creating the resolver default handler 37m 8s
- 35. Starting to implement function code generation 33m 12s
- 36. Implementing the foundation of scope variables 35m
- 37. Fixing the parser_scope_offset_for_stack function 2m 41s
- 38. Assigning Variables 32m 23s
- 39. Code generator response system 6m 3s
- 40. Implementing the code generator response system and expressions 1s
- 41. Running our first program 9m 39s
- 42. Modifying our parser_datatype_init_type_and_size function 1m 36s
- 43. Generating identifier variable access 11m 9s
- 44. Handling pointer values in expressions 7m 5s
- 45. Implementing logical operators 20m 55s
- 46. Implementing function calls 17m 23s
- 47. Generating structures 21m 19s
- 48. Generating structures - Part 2 9m 19s
- 49. Generating the get address operator 5m 11s
- 50. Useful resources 1m 52s
- 51. Finishing the codegen_resolve_node_for_value function 3m 10s
- 52. Finishing unaries 23m 59s
- 53. Generating unsupported entities 3m 36s
- 54. Generating statement return 19m 43s
- 55. Generating if statements 7m 32s
- 56. Generating while loops 4m 57s
- 57. Generating do while loops 3m 11s
- 58. Generating for loops 8m 42s
- 59. Generating break statements 1m 55s
- 60. Generating continue statements 3m 8s
- 61. Fixing bug in for statements 2m 49s
- 62. Creating switch statements 9m 5s
- 63. Creating switch statements Part 2 7m 25s
- 64. Creating switch statements Part 3 6m 24s
- 65. Generating goto statements 1m 55s
- 66. Creating labels 1m 11s
- 67. Creating strings and calling printf 4m 47s
- 68. Generating expression parenthesis 2m 13s
- 69. Creating tenary nodes 5m 36s
- 70. Generating casts 5m 26s
- 71. Generating array access 8m 14s
- 72. Generating array access - Part 2 2m 32s
- 73. Fixing a bug with indirection assignments 3m 48s
- 74. Generating unions 2m 57s
- 75. Generating array variables in the global scope 1m 48s
- 76. Finishing the codegen_generate_global_variable function 32s
- 77. Generating variable lists 3m 40s
- 78. Escaping characters 3m 39s
- 79. Finishing our operators 15m 41s
- 80. Implementing the ++ and -- operators 18m 43s
- 81. Fixing a couple bugs 4m 9s
- 82. Fixing a bug with the switch statements default case 5m 36s
- 83. Fixing a bug with function calls within arguments 10m 27s
- 1. The preprocessor brief introduction 3m 40s
- 2. What is the expressionable system 4m 45s
- 3. Creating our expressionable structures 15m 23s
- 4. Creating our expressionable system - Part 1 16m 21s
- 5. Creating our expressionable system - Part 2 13m 38s
- 6. Creating our expressionable system - Part 3 16m 59s
- 7. Creating our expressionable system - Part 4 12m 26s
- 8. Creating our expressionable system - Part 5 7m 46s
- 9. Creating our expressionable system - Part 6 12m 16s
- 10. The Preprocessor Internal And Mechanics 15m 32s
- 11. Creating the preprocessor structures 7m 52s
- 12. Beginning the preprocessor logic 37m 17s
- 13. Creating the preprocessor expressionable configuration 23m 21s
- 14. Creating the define macro 25m 59s
- 15. Creating macro arguments 11m 29s
- 16. Implementing undef 2m 37s
- 17. Implementing the macro warning 5m 22s
- 18. Implementing the macro error 1m 59s
- 19. Creating the ifdef macro 20m 4s
- 20. Creating the ifndef macro 3m 14s
- 21. Evaluating expressions in the preprocessor - Part 1 7m 16s
- 22. Implementing the if macro 3m 46s
- 23. Evaluating expressions in the preprocessor - Part 2 9s
- 24. Evaluating the expressions in the preprocessor part 3 15m 23s
- 25. Evaluating the expressions in the preprocessor part 4 11m 5s
- 26. Understanding macro functions 8m 7s
- 27. Implementing macro functions - Part 1 37m 30s
- 28. Getting the value of definitions from within source code 9m 3s
- 29. Implementing macro functions part 2 15m 14s
- 30. Implementing macro functions part 3 6m 45s
- 31. Finishing the typedef directive - Part 1 29m 13s
- 32. Finishing the typedef directive - Part 2 17m 31s
- 33. Implementing macro strings - Part 1 7m 24s
- 34. Implementing macro strings - Part 2 8m 10s
- 35. Implementing preprocessor unary not 3m 21s
- 36. Fixing a mistake with logical not in the code generator 3m 17s
- 37. Implementing the parentheses node in the preprocessor 1m 19s
- 38. Implementing joined nodes in the preprocessor 6m 44s
- 39. Evaluating tenaries in the preprocessor 43s
- 40. Processing concat directive in the preprocessor 17m 22s
- 41. Creating native definitions - Part 1 13m 23s
- 42. Creating native definitions - Part 2 3m 55s
- 43. Implementing includes - Part 1 18m 9s
- 44. Implementing includes - Part 2 6m
- 45. Implementing includes - Part 3 17m 10s
- 46. Implementing sizeof 2m 34s
- 47. Fixing some issues with casting pointers 6m 45s
- 48. Implementing offsetof 3m 52s
- 49. Adding our source file as an included file 2m 18s
- 50. Implementing Native Functions - Part 1 21m 4s
- 51. Implementing Native Functions - Part 2 25m 7s
- 52. Implementing VALIST - Part 1 14m 8s
- 53. Implementing VALIST - Part 2 12m 49s
- 54. Finishing some important header files 9m 41s
- 55. Summary Module 4 50s
- 1. What is semantic validation? 6m 15s
- 2. Building the foundations 3m 45s
- 3. Implementing validator scopes 3m 59s
- 4. Implementing validation of functions 10m 26s
- 5. Implementing validation of variables 5m
- 6. Implementing the validation of statements 11m 25s
- 7. Implementing the validation of structures and unions 3m 24s
- 8. Continuing the validator 8m 54s
- 0.00 instructor rating
- 1 courses
- Systems students worldwide
Daniel McCarthy
Learn from DragonZap instructors with practical, build-first lessons focused on systems, low-level programming, compilers, kernels, and real-world engineering fundamentals.
Student reviews
Really enjoyed this course. It was a long one, but good to go from the parser and lexer, all the way through to code generation. Was fascinating to see how it was all broken down and finally all came together.
NA
This course is intense!
Amazing course! Daniel explains everything clearly and in a straightforward manner. Professionally, I prefer more of a top-down approach, but a practical course like this requires more of a bottom-up approach. Daniel bal...
It would be of great value if the course had some theoretical background on compilers.
Excellent course
Very thorough explanation