Im trying (keyword is totally trying here) to create a REALLY simple compiler here for a project at school. So far I have tried building the lexical analyzer which is basically reading in the file and passing it to the parser(sytactical analyzer) After reading the file in, I get pretty much lost. I have got it to print the file to the screen. I have even got it to make another file and write to that (but not the same output on the screen) I get anything from null to jibberish. What I am trying to do is read the file in and pass everything to the parser as an array. Here is what I have so far this is probably really nasty, can I have some help? Thanks alot
Hi Kevin, First of all you are not using very efficient reader or writers to perform your work. Assuming it is all textual then you should make sure of Buffered streams and readers/writers. Your problem seems to be that you are not storing the file contents that you are reading in. You must have some class variable that holds the strings so that you can perform manipulation and output them again. My favorite is Vector, which can be converted into an array once it is filled.
WOW! Manfred, I really appreciate the help with that one. I really didn't want it to get that complicated. I am just trying to write something simple. It is taken from the Text of "Let's Build a Compiler" wriiten by Jack W. Crenshaw. The programming he uses is in Turbo Pascal and it is so simple and easy to follow. DO you think you or anyone else can kinda translate the code or come up with something just as easy and elementary in Java. That would be the best!! Thanks again. Best regards. Kevin Turbo Pascal Code Begins:
If you really want a literal tranlation from Turbo Pascal. Just write a Java class with all static methods, that will work exact the same as turbo pascal for you. The tip is after the working translation finished, then thinking how to add OO concepts for teaching purposes. I assume you are a teacher. Roseanne [This message has been edited by Roseanne Zhang (edited February 14, 2001).]
Using Java class with all static methods, you can write as beautiful (or ugly ) procedural program as Turbo Pascal. The main will serve you as your main begin/end pair in Pascal. This will really help you understand the algorithm, and build you confidence to write next OO version of it.
[This message has been edited by Roseanne Zhang (edited February 14, 2001).]
Thanks alot for your help I am not a teacher, a student actually. My task is to write a compiler given a certain grammar. I was going through this tutorial about writing a compiler by Jack Crenshaw http://compilers.iecc.com/crenshaw/ He has broken it down VERY simply and it would help me tremendously to translate it. Everyone keeps telling me Pascal is similar to Java. I know Java looks just like C++, but im not too good with the syntaz of Java to begin with rather than trying to translate the Pascal. I just want to keep it as simple as possible the way the pascal looks, but written in Java.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop