The second problem assignment is to write a very simple macro processor using a compiler-compiler tool (Lex and Yacc are suggested. If you have another one in mind, make sure that (1) it is installed on Rohan, and (2) you have check with me first). The macros are very simple, and should be able to be embedded into almost any programming language.
All input is to be passed thru the processor except for those parts that are enclosed between "#[[" and "]]" inclusive. The format of the macros are "#[[ directive &variable ]]", where "variable" is a supplied string, and "directive" is one of STRING, NUMBER, or EXPAND, potentially followed by additional information.
In the case of STRING, it is followed by one or more quote-delimited strings. One of these quote-delimited strings should be (randomly!) selected, and should replace the #[[...]] construct entirely. Also, it should be associated with the variable.
In the case of NUMBER, it is follow by exactly two base-10 numbers. A random number should be generated that lies between (inclusive) the numbers, and again, that number should replace the #[[...]] construct entirely, and that number should be associated with the variable.
In the case of EXPAND, it should replace the #[[...]] construct with the value of the specified variable.
The & character should be considered part of the variable name.
You shall use lex and yacc for this assigment, which means that you should be programming in C. If you prefer C++, arrange with me before the due date to discuss the issues.
(Using Java depends on finding and installing a suitable JavaCC or equivalent tool. See or email me if this is important to you.)
The program shall read from standard in, and write to standard out. This lets us run it like so:
$ p2 < infile > outfile
As before, all code should be checked into the CVS repository. The name of the module shall be "as2". DO NOT check in any binary or otherwise non-printable files.
When you are ready to turn in the assignment, and you have verified that everything is correct (and you've stated this in your gradernotes), send email from your MASC account to "stremler@rohan.sdsu.edu" with a Subject of "CS530 Assignment 2". The body of the email should contain only your name, MASC account, and CVSROOT.
Do not wait until the last minute to do this.
Do not submit before the due date. Due to the amount of junkmail I receive, I might lose your submission if you do so.
Do not touch your code after you submit your assignment.