|Advice sought: Parsing a line of COBOL in C. firstname.lastname@example.org (1996-01-12)|
|Re: Advice sought: Parsing a line of COBOL in C. email@example.com (John Lindsay) (1996-01-16)|
|From:||firstname.lastname@example.org (Darrin Smith)|
|Date:||12 Jan 1996 17:42:32 -0500|
First off, thanks for reading.
Now, its been many moons since I've written anything resembling a
compiler (I wrote one in college about 8 years ago!) so PLEASE give me
as much guidance as you can.
I'm trying to convert a COMPUTE statement in COBOL from:
COMPUTE variable1 = variable2 * -1
COMPUTE variable1 = 0 - variable2
It would be no problem if the compute always followed this format, but
of course it does not. In fact, it can look like any (and more) of the
VARIABLE1 = VARIABLE2 * -1
2) COMPUTE VARIABLE1
= VARIABLE2 * -1
3) COMPUTE VARIABLE1 =
VARIABLE2 * -1
4) COMPUTE VARIABLE1 =
5) COMPUTE VARIABLE1 = VARIABLE2 * VARIABLE3 * -1
Well, you get the idea. Also, the final line may or may not be terminated by
Anyway, I could write some massive nested if statement (I'll be writing this
in C\C++), but I thought that there should be some sort of algorythm that I
should follow (building tokens, pushing them on the stack...)
Any help is appreciated.
[I'd convert it to a string of tokens, squashing out the confusing white space
and all, then do some simple pattern matching on the token string. -John]
Return to the
Search the comp.compilers archives again.