There is probably no programmer that had not heard of a famous problem set by Norbert Wiener. The problem is to write a program that, being run, sends its source code to the output device. Note, that it is not allowed to use the files containing the source code, or system-dependent features (e.g. knowing the address of a memory area that could possibly contain the source code). Such a program is called an introspective one. A theorem is well known, which states that it is possible to write an introspective program in almost any programming language.
It would be unfair to demand writing an introspective program in a language known to a different degree by different participants. Therefore we describe a formal syntax for a new language called PIBAS. And your task is to write a program that writes an introspective PIBAS program to the output.
Testing this PIBAS program includes a syntax check and a test run. A program is considered correct if it outputs a string equal to its source code.
- A PIBAS program consists of one or more operators separated with ";" (semicolon). A program is written in one line that is no longer than 32000 characters.
- Two types of operators exist: string assignment operator and output operator.
- Assignment operator is used as follows: <String variable>=<String expression>
- String variable is denoted with a single capital Latin letter.
- String expression is either a string variable, or a string constant, or a substring function, or a concatenation of string expressions with the use of "+" (plus) character.
- String constant is a sequence of any printable characters enclosed in double (") or single (') quotes. This sequence cannot contain the quote character it is enclosed in. Examples: 'Rybinsk', "O key!", "I don't know solution."
- A substring function is used in the following way: $(<string variable>,<unsigned integer>,<unsigned integer>). The second parameter sets the starting character of the substring and the third one sets its length. Character numeration is one-based.
- Output operator: ?<string expression>.
The total length of all strings sent to output may not exceed 32000 characters.
A='World, Hello!';?$(A,8,5);?", ";B=$(A,1,5)+'!';?B
The output must contain an introspective PIBAS program.
Problem Source: 2002-2003 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 2002