| Translate a program from one programming language to another | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Complexity (1-100): 90
Translate a program on the programming language Beta to the equivalent program on the programming language Psi. Beta language syntax & semantics A Beta program consists of a sequence of operators, each on separate line of text, and each starting with a natural number - a label, - in the range [1;10000]. All labels are different and in ascending order. An operator is separated from its label with spaces. A variable name consists of one or more latin letters (no more than 8 letters), case-insensitive. Variable names should differ from keywords. Program starts with the first operator, the last operator in the program should be END. Variable, constant and intermediate values are integer and ranged from -32768 to 32767. At the start, all variables are set to 0. A program may contain any number of spaces between its lexemes, but it does not contain empty lines. Operators of Beta language:
Psi language syntax & semantics A Psi program consists variable definitions and a body. Variable definitions starts with the keyword DEF, followed by variable names used in the body.Variable names are divided by comma and cannot repeat. Definitions end with a semicolon. The program body consists of an operator sequence, enclosed in keywords START and FINISH. Operators are separated by a semicolon. The notion of variable, constant, expression, and condition are the same as in Beta. A Psi program can contain empty lines and extra spaces. Variable values at the start are random. Operators of Psi language:
An example of translation Beta program an equivalent Psi program Note. The input text is always syntactically correct and contains no more than 100 lines with up to 80 characters in each line. |
||||||||||||||||||||||||||||||||||
| Solution: | solution.pas | |||||||||||||||||||||||||||||||||
Book of programming problems is powered by UseBB 1 Forum Software | Contact Admin