Welcome to the first note on my Janky Lexer project diary. If you're wondering why it's called "janky," well, that's because I have no clue what I'm doing. I'm just a guy who decided to dive headfirst into the world of lexers, compilers, and all that jazz without any prior experience. So this is going to be a bumpy ride filled with confusion, Google searches, and probably a lot of facepalms.
Oh boy, where do I even start? So, I decided to embark on this crazy journey of building a compiler. Why? Because apparently, I thought it would be a great idea to torture myself with something I have absolutely no clue about. But hey, that's what learning is all about, right? Right?!
First off, let me just say that I am not a genius. I'm just a dude with a computer, a lot of free time, and an unhealthy obsession with YouTube tutorials and Stack Overflow. I've spent countless hours googling things like "what is a lexer?" and "how to read a file in C?". Yes, I'm that clueless.
So, I started with the lexer. What's a lexer, you ask? Well, it's basically a thing that reads your code and breaks it down into smaller pieces called tokens. Sounds simple enough, right? Wrong.
I began by defining some enums and structs to represent different types of tokens. Easy peasy. But then came the hard part - actually reading the file and generating these tokens. I swear, I've never used fseek
and ftell
so much in my life. And don't even get me started on pointers and memory allocation. I'm pretty sure I've created more memory leaks than a sieve.
- Patience: Coding is hard. Like, really hard. But with enough patience and perseverance, you can eventually figure things out.
- Google is Your Friend: Seriously, I don't know what I would do without Google. It's like my own personal coding guru.
- Memory Management is a Bitch: Pointers, malloc, free - it's all a giant pain in the ass. But it's a necessary evil, so I'm learning to deal with it.
Next up, I'll be working on the parser. (But actually I have to improve on this lexer first though) Because apparently, breaking down code into tokens isn't enough. Now I have to actually make sense of those tokens. Wish me luck!
You can check out the code for this step here.
So there you have it. The first step of my janky lexer journey. It's not much, but it's a start. And who knows? Maybe one day, I'll look back on this and laugh. Or cry. Probably cry.
Happy coding, fellow strugglers! 🚀💻😵💫