ADD (REVERSE "ccay"), (LOWERCASE (ADD " IS", (CAPITAL "cOOL")))
produces the string "yacc is cool". Parentheses are required in the
language. You may copy and use the files str
and
str.y
in ~elenam/pub/4607 on epoxy
which have some initial lex and yacc definitions for this problem.
for
loops in a Java
program by the corresponding while
loops as follows:
for (<initialization> ; <condition> ; <increment>) {
<body>
}
rewrites to
<initialization>
while (<condition>) {
<body>
<increment>
}
Note that the condition part of a for loop cannot be empty, but the
other two components can. For simplicity you may assume that the body
of a for loop is always surrounded by braces.
Write a simple lex program that will be able to find necessary
elements to recognize a for loop. Everything else (numbers,
identifiers, punctuation symbols, etc) should be denoted by a token
other
which returns the value of yytext as a string.
Important note: you don't need to check the program for syntactic correctness. The initialization, the condition, the body, and the rest of the program surrounding the for loop may be complete gibberish, they should be left unchanged. However, your parser must handle nested for loops correctly.
Test your solution on any 2-3 Java programs with a few for loops in each.
Test your program at least on the examples given in Question 1.