aspose file tools*
The moose likes Java in General and the fly likes Java I/O Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java I/O" Watch "Java I/O" New topic
Author

Java I/O

Kevin Luludis
Ranch Hand

Joined: Feb 13, 2001
Posts: 30
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
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.

Enjoy,
Manfred.
Kevin Luludis
Ranch Hand

Joined: Feb 13, 2001
Posts: 30
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:

Turbo Pascal Code Ends
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
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).]
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
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).]
Kevin Luludis
Ranch Hand

Joined: Feb 13, 2001
Posts: 30
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java I/O