Logo  

CS456 - Systems Programming

Description

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):

  1. For-loops:

    statement = "for" "(" expression ";" expression ";" expression ")" statement
  2. do-while loops:

    statement = "do" statement "while" "(" expression ")" ";"
  3. Goto statement and labels:

    statement = identifier ":" statement    (* a labeled statement *)
              | "goto" identifier ";"
  4. Add support for an else-clause to while loops (only taken if the while condition is never true.)

  5. 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.

  6. Add new operators, such as all the comparison operators (<, >, <=, >=, ==, !=, ++, --, etc.

  7. Add strings and/or arrays

  8. 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.

Solution