D
darren
I can't decide how much detail to provide for this question. I don't want to
overdo the details. I'm not trying to make you dig for information either.
I just don't want you to have to sift through a lengthy question looking for
the relevant details. Anyway . . .
The question I have is how to approach translating a procedurally structured
program written in C into a properly structured Ruby program. I have a
Pascal-like compiler that was written in C by my class last semester. As an
exercise to learn Ruby and better understand the Pascal compiler, I thought
I'd try to rewrite the compiler with Ruby. But, I'm getting confused on how
to think this procedural solution in object oriented terms.
So far, in Ruby, I am opening the source code file and echoing it back out to
screen. Now, I want to parse the source file, checking that its syntax
matches the syntax rules for our Pascal-like language. Even though I don't
have all of the regular expressions written, generally, I think I can handle
the regex part. I don't even think I'm going to get bogged down in the Ruby
code (although I'm sure I'll have plenty of unexpected qestions). But, I
have the Pickaxe 2nd ed. by my side and Google is my friend. Plus, I have
had a semester of Smalltalk. So, I'm suspecting the Ruby code is going to be
less trouble than just getting the overall idea of how to visualize laying it
all out.
The C source code file is really too long to ask anybody to spend time looking
at it. But, I'll post it anyway. And, I'll post a sample Pascal source
file, too. If anyone is interested in looking at the C code. Save yourself
some time, just jump down to the bottom of the code to find "main". The
first procedure that executes in main is block(). It's kinda easy to see
what's going on in block(). We're just checking for valid block identifiers,
if we get one, we move on, if not, we call statement(). We call identifiers
"SYMS". The process is pretty much that way all the way through. And, I
don't think it is all that important for this question.
Here are the links:
C code: http://www.usmstudent.com/tmp/c.txt
Pascal-like source text: http://www.usmstudent.com/tmp/pas.txt
TIA,
Darren
overdo the details. I'm not trying to make you dig for information either.
I just don't want you to have to sift through a lengthy question looking for
the relevant details. Anyway . . .
The question I have is how to approach translating a procedurally structured
program written in C into a properly structured Ruby program. I have a
Pascal-like compiler that was written in C by my class last semester. As an
exercise to learn Ruby and better understand the Pascal compiler, I thought
I'd try to rewrite the compiler with Ruby. But, I'm getting confused on how
to think this procedural solution in object oriented terms.
So far, in Ruby, I am opening the source code file and echoing it back out to
screen. Now, I want to parse the source file, checking that its syntax
matches the syntax rules for our Pascal-like language. Even though I don't
have all of the regular expressions written, generally, I think I can handle
the regex part. I don't even think I'm going to get bogged down in the Ruby
code (although I'm sure I'll have plenty of unexpected qestions). But, I
have the Pickaxe 2nd ed. by my side and Google is my friend. Plus, I have
had a semester of Smalltalk. So, I'm suspecting the Ruby code is going to be
less trouble than just getting the overall idea of how to visualize laying it
all out.
The C source code file is really too long to ask anybody to spend time looking
at it. But, I'll post it anyway. And, I'll post a sample Pascal source
file, too. If anyone is interested in looking at the C code. Save yourself
some time, just jump down to the bottom of the code to find "main". The
first procedure that executes in main is block(). It's kinda easy to see
what's going on in block(). We're just checking for valid block identifiers,
if we get one, we move on, if not, we call statement(). We call identifiers
"SYMS". The process is pretty much that way all the way through. And, I
don't think it is all that important for this question.
Here are the links:
C code: http://www.usmstudent.com/tmp/c.txt
Pascal-like source text: http://www.usmstudent.com/tmp/pas.txt
TIA,
Darren