User Tools

Site Tools


compilers:sample

Sample exam programming task

Extend the While language with (limited) string support.

  • The name of the new type: string
  • String literals start and end with the character. There can be any number of any characters except newlines and characters. Backslach is allowed inside string literals, but it has no special meaning (unlike in real programming languages).
    • Examples: “”, “apple”, “123asdf>#&@\”
  • It is possible to declare variables of type string.
  • Expressions of type string are string literals and string variables.
  • It is possible to assign a string typed expression to a string variable.
  • There are two functions working with strings:
    • length: takes a string and returns an integer, the number of characters in the string
    • concat: takes two strings and returns a string, the concatenation of the parameters
  • Attention: It is not possibe to input or output strings!

Taks:

  • Extend the lexical analyser with the new type name and string literals.
  • Extend the grammar rules as needed.
  • Add string related type checking.
  • Extend assembly code generation.
    • Hint: Do not store strings as character sequences, store only their lengths! This way the length function just returns the stored number, and concat becomes addition.
compilers/sample.txt · Last modified: 2015/12/15 22:46 by deva