Related articles |
---|
Advice sought: Parsing a line of COBOL in C. fignet05.darrins@eds.com (1996-01-12) |
Re: Advice sought: Parsing a line of COBOL in C. lindsay-j@rmc.ca (John Lindsay) (1996-01-16) |
From: | fignet05.darrins@eds.com (Darrin Smith) |
Newsgroups: | comp.compilers |
Date: | 12 Jan 1996 17:42:32 -0500 |
Organization: | CUSD |
Keywords: | parse, question |
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
to
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
following:
1) COMPUTE
VARIABLE1 = VARIABLE2 * -1
2) COMPUTE VARIABLE1
= VARIABLE2 * -1
3) COMPUTE VARIABLE1 =
VARIABLE2 * -1
4) COMPUTE VARIABLE1 =
VARIABLE2 *
-1
5) COMPUTE VARIABLE1 = VARIABLE2 * VARIABLE3 * -1
Well, you get the idea. Also, the final line may or may not be terminated by
a period.
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.
Thanks.
[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
comp.compilers page.
Search the
comp.compilers archives again.