题目描述
Problem Description
There is a simple scripting language that consists of only assignment statements, conditional statements, and return statements. Variable names must be single uppercase letters, and all variables are 32-bit signed integers.
Each statement in this language must occupy a single line. The program does not contain empty lines, and there are no spaces at the beginning or end of each line. Different tokens on the same line are separated by a single space. The BNF of this language is as follows:
<line> ::= <head> | <assignment> | <if> | ELSE | END IF | <return>
<head> ::= PARAM <paramlist> | PARAM
<assignment> ::= <variable> = <rvalue>
<if> ::= IF <variable> <relation> <value> THEN
<return> ::= RETURN <value>
<paramlist> ::= <variable> | <variable> <paramlist>
<rvalue> ::= <value> | <value> <operator> <value>
<value> ::= <variable> | <integer>
<operator> ::= + | - | * | /
<relation> ::= < | = | >
<variable> ::= A | B | ... | Z
<integer> ::= 32-bit signed integer without leading zeros
The first line of the program is a <head> statement that defines the function parameters, and the last line must be a <return> statement. The <head> statement cannot appear anywhere other than the first line, but the <return> statement can appear multiple times in the program. Line numbers start from 1.
Each IF statement must have a corresponding END IF statement and an optional ELSE statement (note that there is no ELSE IF statement). IF statements can be nested and always compare a variable with an integer or another variable.
You should analyze a given program and output two types of warning messages (format shown in the sample output):
-
First type of warning: unreachable code lines. Regardless of whether the boolean expressions in the
IFstatements are true or false (assume eachIFstatement's boolean expression can be either true or false, unaffected by the results of otherIFstatements). -
Second type of warning: variables that might not have been initialized. A statement uses the value of a variable, but this variable is neither specified in the parameter list on the first line nor assigned a value by an assignment statement before this statement. If this statement is unreachable, it should not generate this type of warning.
Note that the statements ELSE and END IF are not executable statements and should not receive any warning messages.
Input Format
The input contains at most 50 lines, which is the program you need to process. The program is guaranteed to be valid.
Output Format
Warnings should be sorted by line number in ascending order. If there are multiple potentially uninitialized variables on the same line, they should be sorted alphabetically in ascending order. If there are no warning messages, your output should be empty.
Sample Input and Output
Input Sample #1
PARAM A B
IF A > 5 THEN
C = B * A
END IF
D = B - C
Z = Y + X
E = T
F = E + E
V = G + G
RETURN F
Output Sample #1
Line 5: variable C might not have been initialized
Line 6: variable X might not have been initialized
Line 6: variable Y might not have been initialized
Line 7: variable T might not have been initialized
Line 9: variable G might not have been initialized
Input Sample #2
PARAM G
RETURN G
B = K
RETURN C
Output Sample #2
Line 3: unreachable code
Line 4: unreachable code
Input Sample #3
PARAM T C
B = T
A = 4
IF A < 4 THEN
IF B > 3 THEN
Q = 100 + F
ELSE
IF C = -1111111111 THEN
Q = T - A
IF Q = 0 THEN
V = V - 1
END IF
ELSE
RETURN I
E = A
END IF
END IF
ELSE
Q = 1
END IF
RETURN Q
Output Sample #3
Line 6: variable F might not have been initialized
Line 11: variable V might not have been initialized
Line 14: variable I might not have been initialized
Line 15: unreachable code
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分