The problem wants you to understand a new programming language, POJ language, and ask you to calculate the result of a program, which is written in this language.
The language may be described as follow (the integers mentioned here are in [-2
31, 2
31)):
- The syntax of this language is similar with C language, but much more simple. And the different will be mentioned as below.
- The length of a program written in the language will not exceed 1000 letters.
- The variables need not declaration. If a variable is first mentioned, the value of the variable is set to be 0. And once a variable is mentioned, it will have a global scope. The length of the name of a variable will not exceed 5.
- A Boolean expression has the structures: "A<B", "A==B" and "A<=B", here A is a variable or an integer, and so is B.
- There are three kind of normal expression I, II and III.
- The Normal expression I has one of the follow structures: "A=B;", "A=B+C;", "A=B-C;" and "A=B*C;", here A is an variable, B is an variable or a positive integer and C is also an variable or a positive integer. It's confirmed that the new value of A is also in [-231, 231). And it's assumed that a program will execute these expressions at most 100000 times before terminated.
- In the language there is a new expression that is not defined in C language, and we consider this expression as normal expression II. The expression is as: "#A;", here A is a variable. This expression terminates the program and gives the result of the program, and it is the only way to terminate a program. And it's confirmed that during the processing of the program it must meet this expression.
- There are only two key words in the language, "if" and "while". There kinds of structures are considered as normal expression III.
a) The "if" sentence is as: "if(a Boolean expression){some normal expressions}".
b) The "while" sentence is as: "while(a Boolean expression){some normal expressions}".
- There may be white spaces, which includes " ", "\t" and "\n", at any position except in key words, Boolean expressions, normal expressions I and normal expressions II.
- The program consists of some normal expressions.