SP1455 ANALYSER - Program Analyser

题目描述

你需要处理一个特定格式的程序: ``` ::={} ::= ::= | | | | ::=+ ::=? ::=GO ::=IF= ::=END ::= ::= ::={} ::=A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z ::=0|1|2|3|4|5|6|7|8|9 ::=(ASCII 10) ::=(ASCII 32) ``` 程序根据以下规则运行: - 从层级最低的语句开始逐行执行,逐步向上,除非遇到或。 - 所有变量在初始时均为 0。 - 表示将加到上,类似于 `+=` 操作。 - 表示输出当前的值。(实际输出目标无关紧要,只需了解这类操作。) - 表示当且仅当的值等于时,执行指令。否则,按正常顺序执行下一个语句。 - 表示下一条执行的语句是指定层级对应的语句。 - 当遇到时,程序自终止。 在执行过程中,所有涉及的数值均在有符号 32 位整数范围内。

输入格式

A Program which has the following format: ``` ::={} ::= ::= | | | | ::=+ ::=? ::=GO ::=IF= ::=END ::= ::= ::={} ::=A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z ::= 0|1|2|3|4|5|6|7|8|9 ::=(ASCII 10) ::=(ASCII 32) ``` The program runs following the following rules: - Program starts from the sentence whose level is minimum, and executed by the level from low to high except that the sentence isor. - All variables are initialized to 0. - means+=in C++. - means write the value ofto the output file(we aren't interesting about the real output file.) - means if and only if the value of the equals to , will be executed, otherwise the next sentence executed is as usual. - After, the next sentence executed is the sentence with level which equals to the level in. - Program terminates by itself when is executed. - The numbers during the program is running will fit in a signed 32-bit integer. - The number of sentences in the program is not more than 100. - The length of each line in the input file is not more than 20. - The input is correct. - The sentence with the maximum level is always . - Any level is not more than 3000.

输出格式

输出程序执行过的语句总数。如果程序无法自行结束,输出 -1。

说明/提示

- 变量的值范围为 $0 \leq \text{变量的值} \leq 2^{31}-1$ - 语句总数不超过 100 行 - 每行长度不超过 20 个字符 - 任一层级不超过 3000 **本翻译由 AI 自动生成**