Assume that a string is any non-empty sequence of lower-case
letters, and that "E" denotes the empty string. We define the
following operations on strings:
- Concatenation, denoted by the operator "+", which joins
two string together; thus abc + def is abcdef
- k-prefix, denoted by the operator ">", which gets (at
most) the first k symbols of a string; thus 3 > abcd is abc
- k-suffix, denoted by the operator "<", which gets (at
most) the last k symbols of a string; thus abcd < 3 is bcd
Write a program that takes in strings separated by these operators
(and possibly using brackets), and evaluates the resulting string.
Concatenation has highest precedence (i.e. gets done first), followed
by k-prefix and then k-suffix; both concatenation and k-suffix are
left-associative, whereas k-prefix is right associative.
You can use the following grammar:
StringExpr -> StringExpr + StringExpr
StringExpr -> num > StringExpr
StringExpr -> StringExpr < num
StringExpr -> ( StringExpr )
StringExpr -> string
Solution