#P2314. POJ language
POJ language
Description
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 [-231, 231)):
- The syntax of this language is similar with C language, but much more simple. And the different will be mentioned as below.
<li>The length of a program written in the language will not exceed 1000 letters.</li>
<li>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.</li>
<li>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.</li>
<li>There are three kind of normal expression I, II and III.</li>
<li>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.</li>
<li>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.</li>
<li>There are only two key words in the language, "if" and "while". There kinds of structures are considered as normal expression III.</li>
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}".
<li>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.</li>
<li>The program consists of some normal expressions.</li>
Input
The input contains a program written in the POJ language.
Output
The output contains an integer, which is the result of the program.
aaaaa=2;
bbb=5;
while ( aaaaa<=bbb ) {
if(ccc<10){
ccc=ccc+aaaaa;
}
bbb=bbb-1;
if(100<ccc){#aaaaa; }
}
#ccc;
8
Source
POJ Monthly,kicc