Hey! Nice to see from you again! :D
First of all, I'm a Computer Science Student studying for my first Bachelor's degree at the moment, meaning that the knowledge that I have is mostly around topics that we learn during that four years in my University. But, we tend to have lots of Hardware courses that got very in-depth into lots of things. Ase these courses are mandatory and not from a list of choices, many Students struggle with them. Either way, I'm currently entering the fourth and final year of my study. The Compiler Design class was in the first semester of the 3rd year.
I told you some things about my study so that you know how much validity you can expect from my information.
I would like to start by mentioning the following things:
- Bison is an updated version of yacc (yet another compiler compiler)
- Flex is an updated version of lex
- Yacc and lex, and therefore Bison and Flex are build to function together
- Lex is combining the input stream/characters into lexical units that we also call tokens or lexemes
- Bison is combining the tokens that it gets from Flex to form a Syntax Tree
- The action code in the lexer of Flex and parser of Bison can be anything we wish. We just have to make sure that Flex returns the Token-ID to Bison using "return Token_ID;" so that Bison knows which exact token is currently in the input.
After that answering your questions is now much easier I think. So, let's go:
- I think that I understand what you mean by that. As we are not limited by what our Action Code in the grammar rules can do, what we want to do first is convert the grammar into a "better" form known as Intermediate Code, which can be generated very easily inside of the aciton code of the grammar. The Intermediate Code that I will cover soon enough will be in the form of an Abstract Syntax Tree (AST). Having the information stored in an abstract way that "leaves" the strictly-defined grammar of the source language you can then easily turn this language into anything. Using the right Code you could generate the same Code for a new Language, which in my series will be Assembly. This "output" language might easily be an FFI in your case. Also, remember that you can store lots of information in the Symbol Table, that afterwards together with the Intermediate Code (AST) gives us a much better overview of the given grammar of a programm.
- Flex and Bison are C-like in Syntax, but I don't had any luck in finding an IDE or IDE package that fully supports them. What I do at the moment is write in Notepad++ by enabling C syntax so that C keywords get colored. But, I don't just copy-paste the Code from Notepad++ whitespaces even occur at the beginning, pushing the Code to the right. I think the problem comes from the Tab's, which in Steemit become more then just 4-6 Spaces.
- Yes, all of the predefined variables and functions of flex and bison start with a "yy". I think it comes from the previous name of Bison which was yacc, but I'm not exactly sure 'Y' there are two of them (see what I did there? :P)
I don't found time to play the Game in the Summer, as I tried to relax a little bit of University stuff by being full-time vacation ;) I know, I know I was still writing articles for Steemit, but these where about Physics that I enjoy a lot and also don't took so much time as this article for example. Now that you mention it again, I will try to play it in the following months to make a full review for it. I will inform you about my progress :P
Hmmm...generating MIPS assembly, I'm also not exactly sure how exactly I am supposed to do it right. :D I will just explain how exactly I did it and how it works for me, so that you can optimize it for any other language or better said AST on your own. I will give you an overall Idea of how we should do it and then give you Code for my specific Case :)