pcod

One time when he was bored Ionel created the following simplified pseudo-code language.
A variable identifier is represented by a lowercase letter of the English alphabet. The values of a variable are integers having at most 9 digits.
Before using a variable, it must be defined via an assignment statement.
Constants are positive integers
having at most 9 digits.

Allowed
statements are:
Assignment:
let v = const

(variable v takes the value of constant const )
Display:
write v
(displays the value of variable v; the equivalent of writeln(v) or cout<<v<<'\n'; or printf("%ld\n",v);)
Increment:
inc a, b
(the value of variable a is incremented by the value of variable b)
Initial test loop:
while a < b
    instruction_1
    instruction_2
    ...
    instruction_n
endwhile
(while expression a<b is true execute the
statements instruction_1 are executed. . . , instruction_n )
where:
   a, b - variables
   const - constant
instruction_1, instruction_2,. . ., instruction_n - any allowed
statement (let, write, inc or while)

From a syntactical point of view Ionel writes his algorithms correctly, it's only the endwhile keyword that gives him problems quite often (he misplaces it or uses it more/fewer times than he should). Also, Ionel forgets to define all the variables he uses.

Task

Write a program that interprets algorithms written in simplified pseudo-code, by determining any errors they may contain.

Input data

Input file pcod.in contains an algorithm in simplified pseudo-code.
Statements are written only in lowercase letters and may contain an infinite number of separating spaces.
Each
statement is written on one line, except for the while statement, which expands on more lines.

Output data

Output file pcod.out will contain the data displayed by the algorithm. If an error is detected the proper error code will be displayed and algorithm interpretation ends. In this case the output file will contain only the error message.
The error messages can be:

Constraints

  • The number of lines contained in an algorithm is between 1 and 100, including.
  • An algorithm line does not exceed 30 characters.
  • Values obtained after executing the statemenst in the algorithm are integers having at most 9 digits.
  • Each line of the output file is going to end in an endline character.
  • There can be no errors in an algorithm other than those specified in the problem.

Example

pcod.in

pcod.out

Explanations

let s = 0
let p= 1
let t=1
inc t,p
inc s,t
write s
write w

undefined symbol

a non-stated variable (w) is detected

let p=1
let s=0
let n=4
let t=1
while t<n
    inc s,t
    inc t,p
endwhile
write s
write n

6
4

 

let p=1
let s=0
let n=4
let t=1
while t<n
    inc s,t
endwhile
write s

runtime error

The algorithm loops infinitely because the value of variable t does not change during execution

let x=2
let y=0
let z=0
while y<x
   inc y,x
   let z=0
   while z<x
      inc z,x
   endwhile
write y

nesting error

The first while loop has no endwhile correspondent

Time limit: 0.3 seconds/test

 

prof. Alin Burta
Buzau "B.P. Hasdeu" National High-School
Contact: allbu2003@yahoo.com