#P2509. [SCOI2008] 警告
[SCOI2008] 警告
Description
There is a simple scripting language with only three kinds of statements: assignment, conditional, and return. Variable names must be single uppercase letters, and all variables are 32-bit signed integers.
Each statement of this language must occupy its own line. The program contains no empty lines, and there are no spaces at the beginning or end of any line. Different tokens on the same line are separated by a single space. The BNF of the 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> :: 不含前导 0 的 32 位带符号整数
The first line of the program is a <head> statement that defines the function’s parameters, and the last line is guaranteed to be a <return> statement. A <head> statement cannot appear anywhere except the first line, but <return> statements may appear multiple times in the program. Line numbers start from .
Every IF statement always has a matching END IF statement, and may have an optional ELSE statement (note that there is no ELSE IF statement). IF statements may be nested, and they always compare a variable with an integer or another variable.
You should analyze a given program and output two kinds of warning messages (see the sample output format):
-
Type 1 warning: unreachable code lines. These are lines that cannot be executed no matter whether the boolean expressions of the
IFstatements evaluate to true or false (assume that eachIFcondition is independently both possibly true and possibly false, unaffected by otherIFresults). -
Type 2 warning: possibly uninitialized variables. A statement uses the value of some variable, but this variable is neither listed in the parameter list on the first line nor assigned by an assignment statement before this point. If a statement is unreachable, you should not report this warning for it.
Note that the statements ELSE and END IF are not executable, so they should not receive any warnings.
Input Format
At most lines, i.e., the program you need to process. The program is guaranteed to be legal.
Output Format
Output warnings sorted by line number in ascending order. If there are multiple possibly uninitialized variables on the same line, list them in alphabetical order. If there are no warnings, your output should be empty.
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
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
PARAM G
RETURN G
B = K
RETURN C
Line 3: unreachable code
Line 4: unreachable code
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
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
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号