Risc-V Compiler
- 3 Devlogs
- 9 Total hours
A Risc-V compiler written in C for the pico 2 W.
A Risc-V compiler written in C for the pico 2 W.
I received my two Pico 2s today. I spent some time trying out examples and modifying them, and I managed to get the LED to blink, which was surprisingly difficult to find examples for because I needed it in Risc-V assembly. Then I worked on generating a tree from the parser I made in the last devblog. It seems to work well, but it is kind of hard to tell. Next I think I’ll either do semantic error checking, or skip right to the assembly generation and worry about the semantics later :)
I worked on creating the Syntax analyzer for my Risc-V compiler. This stage checks the structure of the program and any grammatical errors. I had to do a lot of research on CFGs (Context free grammars). They define the rules for the language. Below is a spreadsheet of the CFG. I will improve it in the future to add more functions. I implemented an LL(1) parser. I was successfully able to check the grammar of a simple program. I still need to make the parser construct an abstract syntax tree. I realized that it is quite difficult to find pictures to post because it mostly happens in the console, but trust me, interesting things are happening!
I have just started working on my first compiler. I have coded a couple of interpreters before, but this is my first time creating a compiler. I am designing it for the Pico 2 W and will be translating a modified C into Risc-V assembly. So far I have created the lexer which separates the source code into tokens. I have also set up a nice starting infrastructure including some error tracing. Below is the output of a test source code tokenized. Funnily enough, I’m running this compiler on a Pico as well. In the future, I hope to incorporate this compiler into a Pico based OS.