Hey tim, have you seen this? http://people.cs.uchicago.edu/~varmaa/mini_c/ Seems quite cleanly written. You might be able to pick up some useful ideas from...
No I hadn't seen that, I'll have a look at it, though I'm not sure how much I'm going to get from it at this stage since it uses a lexer and parser generator. ...
... Or possibly bite you in the AST :-) We haven't really talked about your internal data structure yet. Getting that right will be key to code generation...
... Ok well let's talk :) I've got a node based system which I'm reusing from the old code, but I'm refactoring it as I use the nodes in the new parser. ... ...
... It's *not* a string... It's a single-character integer constant. Treat it exactly the same as IF a < 65 I guess python doesn't have that construct, but...
... (I'm back.) I had a quick look at your AST code and although it's regular and consistent, I'm wondering if it's *too* clean, ie by being encapsulated in...
... (ie ... jump ... along. And what I used to do too - my last 'toy' compiler was a top-level loop that parsed a simple statement at a time, and kept track of...
... Python objects a super flexible, any attribute can be accessed from the outside since Python doesn't really have a notion of private members. The code...
... Why are semicolons providing you with such issue? Oh wait do you mean semicolons in the input stream, or outputting them in the right places in the C...
... Well, when you have a node that was built like MkNode(IFTHENELSE, cond1, statement1, MkNode(IFTHENELSE, cond2, statement2, statement3)) a simple walk of...
... No it isn't/doesn't. The semicolons aren't statement separators, they're statement terminators, so they "belong to" the subordinate statements. Therefore...
Rainer Thonnes
rainer@...
May 4, 2008 8:55 am
1047
... All I can say is try it yourself! Unless you do the peepholing/post-processing trick, there is no simple rule that puts them in the right places - I tried...
... Is this real C code? I never knew C had gotos/labels...and do you really need the ; after a label? Wait I didn't know C had do statement either, kinda...
... It's mostly genuine C although there are bits that aren'ty finished. The semi-colon may or may not be optional depending on whether there are "if"s...
... One day perhaps.. ... Yes there is. OK, that's easy to say not having tried it myself, but I can't really see any difficulty at all. The simple rule is...
Rainer Thonnes
rainer@...
May 4, 2008 10:39 pm
1051
Rainer, could you have a look at this and see if you can see any obvious problems in the translation? ...
... rainer.c.txt ... It was in, but wrongly. I was bracketing on the wrong comparison, and the problem was caused by non-binary-ops all having a default...
... Done. Ecce works! Just need to add the small amount of support code in C at the start of the output file (as opposed to currently editing it in by hand)...
... Beware of C's calling convention, it caught me out when I was learning to interface assembly and C. The compiler pushes function operands onto the stack...
... I think that's a C language standard rather than an architecture-specific decision. It may be possible to write a C compiler that doesn't evaluate...
... Yeh it is part of the ansi standard calling convention, but it's unlike any other compiled language I know of which all push the parameters in forward ...
... you've digested this lot. For the moment it's just filed with a bright red 'pending' flag next to it. I'll look at it more closely when I start writing...
... the ... the ... Absolutely not. In Edinburgh compiler terms, what you're describing is the 'A[]' array that represents the concrete syntax. But the AST ...
... Surely the trick is *not* to treat 'if (...) then ... else ...' as a statement, but as a kind of bracketing structure around statements. The semicolons...
Rainer Thonnes
rainer@...
May 6, 2008 4:30 pm
1060
... Yep it's offsets from the base register. On function entry EBP is set to point to ESP, then a near CALL is issued which implicitly pushes the callee's...
... That's not true. The CALL instruction doesn't push the callee's address, it jumps to it, having pushed the return address. At the point of call, the...
Rainer Thonnes
rainer@...
May 7, 2008 9:39 am
1062
... I was under the impressed GCC only 'does' 32 bit protected mode. -Tim...
... You're probably right, I don't know if it can be configured not to assume that the default operand and address sizes are 32 bits, and I had forgotten that...
Rainer Thonnes
rainer@...
May 7, 2008 2:02 pm
1064
... That's exactly how I knew it isn't possible, my measly attempt at kernel dev(and how i know a fair bit about gcc's assembly output) :). You are always...
... Yes, plain left to right, unless explicitly overridden with brackets, but there don't seem to be any instances of those in ecce. ... They are equivalent to...