Understanding and Writing Compilers http://www.cs.mdx.ac.uk/staffpages/r_bornat/books/compiling.pdf When I was a student, you would read the Dragon book to...
Hello, I'd like to build a simple compiler. To summarize it, these are the requirements. I'll be adjusting the requirements list as I actually start...
... I was thinking more like: read the code --> parse it --> make intermediate code --> run it Your approach should improve performance though. I guess we can...
Just to update the current status. What I've done is a lexical analysis. What is next step that I should do? Is it the syntax analysis? For the following...
I'd say the first thing is to describe your language with a grammar such as BNF. Then decide what kind of parser you want (and whether you're going to write...
... I want to write it from scratch. And as for the grammar, lets define it this way: there are no functions, there is only int, variables, +, -, *, /, postfix...
... OK, I rearanged my source code to recognize the following: whitespaces (which are ignored in the further processing routines), names (only ASCII letters),...
Just to update, I've implemented the grammar rules, and my not-yet-a-compiler now parses strings like: int a int a, b int a, b = 2 int a, b = a int a, b = 2, c...
... That sounds about right. For the 'special signs', with this simple grammar, the only work your lexer has to do is distinguish '++' from '+'. What sort of...
... Next step is 'show us your code' :-) Do you parse expressions already? Or just declarations? Once expressions are looking good, yes, probably building the...
... For this first round, I'm doing it unoptimized way, just to get the hang of it. For ++ I'm returning string "++" and string "special". Once I complete this...
... The code has over 200 lines, many of which are simple copied and adjusted. Here is the example: int var(struct token_t *token, int i, int n) { int a, b; ...
... Let's do the easy one first (coding it in the grammar) and come back to this later. ... Oh yes, that'll work too :-) ... That's to be expected in a...
... art ... I'll try to do it here. If the browser breaks it all up, I'll create and upload an image. Here is what I'd do for the expression: int a, b = 2, c =...
... Not a problem. actually the declaration tree is a little trickier than the expression tree, because it allows for a list. Let me take a quick side-track...
... If by "3rd variable declared" you're referencing to the "variables table" then I know exactly what you're talking about. Aren't the variable type and name...
... yes, you can throw away the name when you use a variable, though it's useful to keep a pointer to it so you can print it in your debugging info. ... Sure,...
... actually there's a design decision needs to be made here, the choice is that in some compilers it is easier to handle declarations as soon as you see them,...
... Well, just knowing <VAR, 3> would be enough because if I wanted to know a name (or a type for instance), I'd go and lookup variables table and find all the...
... One other problem popped my mind. Look at this code as an example (my first compiler will be simple, but I'd like to make my second compiler "more usable")...
... they ... In my compiler, I forced all variables to be defined before they could be used to simplify my language. Therefore, each declaration of a variable...
CRANFORD, CHRIS
Chris.Cranford@...
Feb 17, 2009 2:39 pm
1183
... This is an area you'll eventually have to look at and you might as well tackle it now. The usual approach is to push the most recent declaration of a...
... This compiler I'm currently building is likely to adhere to the same idea. But that would not work in the following scenario, would it? int a() { int x =...
... Would introducing the column scope help? So when saying "x" I'd be actually referencing something like main::x? This first compiler would contain only...
My whole program broke down after modifying functions so they build the tree. I think it would be the best if I'd rewrite the whole thing again. Is there...
I'll summarize all of my concerns that I can think of now. How exactly to deal with a+++b? (that should be interpreted as a + ++b) When do I implement the...
... There are many ways to handle your Symbol Table. I decided to implement mine in a tree structure. I've seen others use other fancy lists, stacks, etc....