Last Friday evening I started rewriting my toy compiler from scratch, this time with the target language being a strict subset of C, rather than the 'tiny'...
1329
graham_toal
Feb 25, 2010 5:05 pm
Just checking in with a status update since it is now a month since I started on this rewrite. The compiler now accepts quite a good subset of C (lacking...
1330
Kheme
okiemute1984
Apr 23, 2010 7:54 pm
so i've been giving this topic as a graduating project. WHERE DO I START FROM???...
1331
Ed Davis
ed_davis2
Apr 23, 2010 8:13 pm
Get the complete specifications for your compiler - for instance: - What is the subset of C++ you'll be compiling? - Is it to be native code or VM? - What is...
1332
graham_toal
Apr 23, 2010 8:14 pm
... Well, it can certainly be daunting when you have an entire project ahead of you - that first step seems like the biggest. Fortunately it's not! Because...
1333
Iceman
icemanind
Sep 23, 2010 3:07 pm
Hello All! To anyone that is interested, I have put together a complete tutorial on how to create your own virtual machine, from scratch, complete with an ...
1334
Graham Toal
graham_toal
Sep 23, 2010 3:46 pm
It's a worthwhile document. I'd be interested to know why you designed a VM that is essentialy just a regular 8-bit micro (it looks like something between a...
1335
Iceman
icemanind
Sep 24, 2010 1:27 am
I will work on it more as I find time. Thanks for the comments. I chose something simple, like an 8-bit micro because I wanted to keep things simple. My idea...
1336
steve
sarbayo
Jan 13, 2011 5:02 pm
Hey guys, some of you may recall that a number of years ago I wrote Bxbasic (a C byte-code compiler/interpreter) and Bxbasm (a qbasic-ish to Masm...
1337
Jaime
james_font
Feb 2, 2011 9:13 pm
Sorry for the delayed reply Back in the heydays of the late 1980's I wrote a GUI based calculator for windows 1.04. At that time I was used to writing code...
1338
compiler5019
Feb 2, 2011 9:41 pm
For the following input: #include <stdio.h> int main() { printf("Hello world"); } I'm getting the following output: special: # string: include space: SPACE ...
1339
GrahamT
graham_toal
Feb 2, 2011 9:51 pm
... special: ( special: ) ... special: ( string: "Hello world" special: ) ... the ones I've marked above definitely need to be changed. Maybe also seperate...
1340
compiler5019
Feb 2, 2011 10:06 pm
Thanks. I've modifed the algorithm. Now for the following input: #include <stdio.h> int main() { int a = 1, b = 2; int c = a+++b; printf("Hello world"); } I'm...
1341
GrahamT
graham_toal
Feb 2, 2011 11:03 pm
... When you hit the " character, read in the whole string - don't try to rebuild a string from tokens. Store the contents of the string, with special...
1342
compiler5019
Feb 2, 2011 11:20 pm
... Thanks for the input. I'll redo the source code. But what if I wanted to do syntax coloring instead of a compiler? Would I still remove quotes and only...
1343
compiler5019
Feb 3, 2011 12:52 am
How does this look like to you: /* This is just a test */ #include <stdio.h> int main() { int a = 1, b = 2; int c = a+++b; // we need this for math float pi =...
1344
compiler5019
Feb 3, 2011 12:22 pm
I'm making some progress. I now have doubts about the few "error" handling situations. The code int abc123; should be tokenized as keyword: int name: abc123 ...
1345
Graham Toal
graham_toal
Feb 3, 2011 12:33 pm
... If you can tell at the point where yuou tokenise, report the error there and resynchronise your processing state at the next statement if possible. However...
1346
compiler5019
Feb 3, 2011 2:07 pm
... If I understood correctly, I for the following code: int 123abc; lexer should produce: keyword: int unknown: 123abc special: ; and then let parser to deal...
1347
Graham Toal
graham_toal
Feb 3, 2011 5:35 pm
... That looks about right, yep. ... That's exactly what I do - each token is a struct containing the line/column info, the original text, the canonical text,...
1348
compiler5019
Feb 6, 2011 5:55 pm
For the following input: 2 + 3 * 4 + 5 * 6 * 7 + 8 I get this tree: add(2,add(multiply(3,4),add(multiply(5,multiply(6,7)),8))) In this particular example it...
1349
Rainer Thonnes
rainer@...
Feb 6, 2011 6:21 pm
... I'm sure you can answer the question yourself if you consider what would happen if you replaced add and multiply with subtract and divide. ... Better to...
1350
Graham Toal
graham_toal
Feb 6, 2011 6:51 pm
... I think that's defined by whether the operation is left or right associative in your grammar. Can you construct an example where the results are ...
1351
compiler5019
Feb 7, 2011 11:08 am
... I tried to simplify the grammar as much as possible so I only left + and * so I can test operator precedence. But I guess I oversimplified it. Using - or /...
1352
compiler5019
Feb 7, 2011 11:21 am
... Rainer pointed out an example where tree generation like I've implemented it would fail. I'm now doing just what you suggested: rethinking whether I should...
1353
tjwakeham
Mar 3, 2011 1:33 pm
I don't write C code for a reason, but doesn't the #include line normally get removed by a preprocessor before the compiler takes over? -Tim...
1354
Graham Toal
graham_toal
Mar 3, 2011 2:29 pm
... Normally, yes, most of the # directives are removed (notable exceptions being #line and #pragma) in a pre-pass by the c pre-processor; however it is a...
1355
Timothy Wakeham
tjwakeham
Mar 5, 2011 7:19 pm
Hi guys, I've been working away at a generic object-based state machine for a while to create lexers really quickly and easily. I guess in a way its almost a ...
1356
tjwakeham
Mar 16, 2011 11:56 pm
It occurred to me today that you could theoretically parse a language on a character basis rather than on token basis and create a lexer-less parser. I have...