Exercise #8
Modify/add to the source given and add support for new statements and/or operators. Document the language additions you make in the file doc.txt, any feature not documented will likely not be graded.
Suggestions include (also showing the C grammar for some of them):
-
For-loops:
statement = "for" "(" expression ";" expression ";" expression ")" statement
-
do-while loops:
statement = "do" statement "while" "(" expression ")" ";"
-
Goto statement and labels:
statement = identifier ":" statement (* a labeled statement *) | "goto" identifier ";"
-
Add support for an else-clause to while loops (only taken if the while condition is never true.)
-
Switch statements (probably makes implementing goto easy as well.)
statement = "switch" "(" expression ")" statement | "case" expression ":" statement | "default" ":" statement
Note: case expressions in C are constant expressions (i.e. no variables allowed,) but that doesn't have to be a limitation of your language.
-
Add new operators, such as all the comparison operators (
<
,>
,<=
,>=
,==
,!=
,++
,--
, etc. -
Add strings and/or arrays
-
Something new?
You are free to add whatever you like, go nuts. Your language only needs to work as an interpreter, but an extra hacker points will be awarded if it also works as a compiler.