So I've finally started working on my compiler again. Well actually I started from scratch since I wasn't happy with the old codebase - it was far too complex...
Hi again guys, Just wanted to update on the progress of my parser since I'm really (read: overly ; ) pleased with myself now lol. I can parse a real program...
... Good to see you back in the game :-) Can you see if you can work out a way to return a const expression from the normal expression parser, without...
The way I was considering doing it was to have an optional argument to the expressions function which was passed down to the level of the terminals and if it's...
Actually you know, I've changed my mind, I'm not gonna do it the way I was going to because then I would have to do all the reference checking and type ...
... Yep, you got it. The result of calling the expression parser should be an AST object composed of operator nodes and terminals. If the operators of a node...
Cool, I've already figured out how I'm going to do expression folding and the object based AST should make it super easy. I've now just realised that I...
Ok so I've come up with an idea, if an operator node is on the top of the stack when i go to pop off the number on both sides of an operator, then the operator...
... I see, so you're building the ENTIRE tree as one large parse tree and THEN emitting code. You can do that sort of fixup when you do that - I couldn't. You...
... That's a really good idea, Tim. I wound up having an "EvalConst()" procedure and an "ExprEmit()" procedure, both of which pretty much do the same thing,...
... It depends upon what your right side operators do. Normally things like post increment/decrement: a = variable++; Is really just shorthand for: a =...
... The most generic way I can think of is to handle these in the grammar rather than the lexer, ie anywhere you currently have <term>, replace it with...
It actually just occurred to me that there are really only two practical post fix operators anyway, and they are increment and decrement, which don't have a...
... Unless you've been extremely foresightful in your language design, it is almost certain you'll need some lookahead - or more likely backtracking - in your...
Turns out the solution was a lot easier than I though and it doesn't require lookahead or backtracking in the parser. As you suggested, the parser does ...
... In that case you _were_ extremely foresightful in your language design! (Or lucky :-) ) I have a deadline at work in a few weeks time and probably won't...
I thought I'd share a profound moment I just had - I'm coding my parser with all the features of the language I want regardless of whether I know how to...
... Isn't it always so much more satisfying when you discover something like this for yourself :-) We actually discussed this type of parser some time ago -...
PS This statement needs to be re-examined. You need to handle whitespace some way or other, and it's not that difficult. ... I think the problem you may be...
Yup I remember talking about and coding a precedence parser for expressions, but I don't remember taking it further than that - I'll have to go have a look at...
I do handle it, I just don't parse it; it's fully removed by the lexer. What I really wanted in my language was to have no braces and have whitespace determine...
Oh something else I meant to ask- Should the parser just turn everything into a syntax tree regardless of whether it's semantically correct or not? The problem...
... Sometimes it is easier to allow the grammar to accept more than it should, and eliminate some bad combinations after it has been parsed. This can simplify...
I actually think it will be cleaner to do it this way rather than dirty which is why I asked, but yeh I was referring to the philosophical side of things From:...
... If you perceive the problems to be inherent, then perhaps you are trying to do it the wrong way. If you try to shoehorn a traditional generic bottom up...
Rainer Thonnes
rainer@...
Dec 9, 2008 2:01 pm
1150
Ok I have many questions after I sat on my hands for a day and thought about my compiler rather than coded, so here goes hopefully some can be answered - 1....
... It's possible to do it. I can't recall where I saw it, but I think it had to do with the preamble of the procedure when called. There was some sort of...