To answer you question "where and how did you start?": This is where I started learning about compilers and programming language implementation. This book taught me how to write a compiler and build a programming language of my own. Here's my previous comment somewhere in HN: We can talk further by sending me an email (see my profile). You'll be able to grok compilers after reading and answering the exercises from this book. I think this book suits your situation and I've been into that!Ĭompiler Construction Using Java, JavaCC, and Yacc, IEEE/Wiley, 2012 I recommend an online, free course, like the following from Stanford that is self-paced and results in a compiler that generates assembly level instructions for test running in an emulator. Start by looking into Code Generation, Code Optimizations and Assembly Code. ![]() Again, the specifics are very dependant on the actual language you are dealing with and the target. The specifics are very dependant on the actual language you are dealing with.Ī compiler will be generating code but an interpreter will perform actual execution of the Abstract Syntax Tree operations. ![]() Here you need to learn about Symbol Tables and Type Checking. Just because the input has valid syntax does not mean it makes actual sense. You need to learn about Context Free Grammers, Backus Naur Form and Abstract Syntax Trees. Processing the above tokens and ensuring the input has the valid syntax of a program is your next step. To understand this you should learn about Regular Expressions and Finite State Machines. The first step of your compiler takes in free form text and turns it into a set of tokens that make the rest of the process much easier. You can get started on the compiler/interpreter specific learning as long as you already know a programming language and basic data structures. If you have a bit of spare time i heartily recommend (i) learning to implement a basic compiler, and (ii) building the compiler in or for a language that has a radically different concept to languages you are more familiar with. * "OK, what if i defined a simple language that is much easier to do useful work, but could be readily compiled to brainfuck? i could build a compiler from that new language to brainfuck" can i write a brainfuck compiler in brainfuck?" * "let's implement a compiler for a simple language (brainfuck) to something low level (assembler) in a high-level language i am familiar with (python)" I think my descent into fun with compilers went something like: this was probably one of the most enjoyable periods of programming i can remember. I don't think any of these are a requirement for building a simple compiler.Īfter reading Crenshaw some years ago, i was motivated to just knuckle down and start building a compiler for brainfuck (yes, a toy compiler, entirely pointless). I also heartily recommend Crenshaw's "let's build a compiler" if you want some guidance and motivation to help you just roll up your sleeves and start building a bare-bones but functional compiler. glue everything together into one pipeline generate C code from templated quotations, again using ocaml quotation support, but for C language, not ocaml ocaml program produces single ocaml value that models the input program described by makefile bundle everything into an ocaml program ![]() use ocaml's quotation machinery to define ocaml AST values from standard ocaml syntax, without building AST values by hand map parsed input into AST for Ocaml functions defined earlier define Ocaml types and functions to model things found in input makefile (variable, rules, dependencies). Result: pipeline to compile subset of makefile syntax into native executables, in less than 400 lines of code > goal: translate subset of makefile syntax into native executables Graydon Hoare's "One-Day Compilers" presentation:
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |