F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Script Z

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 824    Accepted Submission(s): 172


Problem Description
Recently, Programmer Zero have made a new script programming language, named Script Z. He is so proud of his new language, that he wrote many programs in Script Z. Unfortunately, he found his script works strangely, and he had no idea what happened. So he wants you to write a Script Z Interpreter for him.
Here are some information about Script Z:
1. Variable: All variable names start with symbol $, and the name of the variable should only contains letters (upper case and lower case), numbers and underlines (_). The first character of the number can be any legal character for the variable. For example, $a $c $t $0 $2 $_ are all legal variable names, while $0-a, $0%b are illegal ones. Variables can be assigned many times during the processing of the script. The length of variable name is no larger than 32. (Does not include the first $ symbol, so the max length of variable name will be 33 with symbol $).
2. Constant: All constant names must start with letters (upper case and lower case), and should only contains letters (upper case or lower case), numbers and underlines (_). For example, A B A10 B_123 are legal constant names, while 5A 4_b are illegal ones. Constants can be assigned at most once. The length of constant name is no larger than 32.
3. White spaces: Spaces (' ', ord(' ') == 32) and tabs ('\t', ord('\t') == 9).
4. Lines: All lines are terminated with character LF('\n', ord('\n') == 10). Each line should be a statement or a blank line.
5. Statement: There will be exactly one statement in one line (except blank lines). The white spaces at the beginning and the end of the statement should be ignored.
6. Blank lines: One line that contains only white spaces or no character.
7. Data Types:
Integer: All integer contains only numbers ([0-9]). The length of integer is not larger than 100.
String: All string values are quoted with double quotes ("), and there won’t be any other double quotes in the string value. All characters in the string are printable[ We call a character printable, if and only if the ASCII code of the character is not smaller than 32 and is not larger than 127.]. The length of string (without double quotes) is not larger than 100. (The length is not larger than 102 if with double quotes.)
There are 5 kinds of statement in Script Z:
1. Assignment:
$Variable = Value
Constant = Value
Notice: there may be none or any number of white spaces before and after the equal sign (=).
The value can be either an integer or a string, and won’t be a reference of variable or constant.
The following assignment are legal:
$a = 1
$b = 2
$b = 3
$_ = "a"
$ok = "true"
$long = 123456789012345678901234567890
CONST = 1
CONST_STRING = "sample"
EMPTY = ""
And these are illegal:
$a = $b
CONST_STRING = a
BOOLEAN = false
FLOAT = 1.5
EMPTY =
2. Output:
Print $Variable
Print Constant
There are at least one white space between Print and variable or constant. For each output statement, your program should print the value of the variable or the constant. No double quotes are needed if the value is string. If the variable is undefined, you should print NULL, and if the constant is undefined, you should print the name of the constant. And also remember to take a look of error reporting part.
3. Dump:
Dump $Variable
Dump Constant
There are at least one white space between Dump and variable or constant. For each dump statement, your program should print the type and the value of the variable or the constant. Double quotes are needed if the value is string. If the variable is undefined, you should print NULL, and if the constant is undefined, you should regard the constant name as a string to be the value of the constant. And also remember to take a look of error reporting part. Use the format in sample output.
4. Error reporting:
Errmsg ON|OFF
There are at least one white space between Errmsg and ON or OFF. Errmsg ON turns on the error reporting while Errmsg OFF turns off. Error reporting is turned on if not specified. If error reporting is turned on, after each statement, you should:
(1) You should print one line if there are undefined variable in Print or Dump statement:
NOTICE: Undefined Variable ${var_name}.
You should replace ${var_name} with the name of variable.
(2) You should print one line if there are undefined constant in Print or Dump statement:
NOTICE: Undefined Constant {const_name}.
You should replace {const_name} with the name of constant.
(3) You should print one line if an assignment are trying to assign an assigned constant:
WARNING: Constant {const_name} Already Defined!
You should replace {const_name} with the name of constant. And you should ignore this assign statement even if the error reporting is turned off (The value of the constant should not be changed).
5. Terminate:
Panic
Your program should print one line and exit after this statement:
Script was KILLED.
You should ignore all statements after the terminate statement.
 

Input
Input contains multiple test cases. The first line of the input contains exactly one integer T, which means the number of test cases. (T <= 10)
For each test case, the first line contains exactly one integer N, which means the lines of the script. (N <= 100000)
The next N lines, contains the statement of the script. Each line is no longer than 256 characters.
You are guaranteed that all statement, variable name, constant name are legal.
 

Output
For each test case, print the output of the script.
Use one blank line to split test cases, no blank line should exist at the end of the last test case. (Only one line terminator '\n')
 

Sample Input
2 13 Errmsg ON $a = 1 $b = 2 $c = 3 Print $a Print $d Dump $c Errmsg OFF Print $_ Print OK Panic Errmsg ON Print A 13 Errmsg ON $A = 3 $B = 5 Print $a Print $B A = 5 A = 10 Print A Errmsg OFF B = "" B = "A" Dump B Dump C
 

Sample Output
1 NULL NOTICE: Undefined Variable $d. integer: 3 NULL OK Script was KILLED. NULL Notice: Undefined Variable $a. 5 WARNING: Constant A Already Defined! 5 string: "" string: "C"
 

Hint

The problem itself is easy of course. But some of the test cases of this problem are strange and annoying. Be careful!
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-04 05:10:28, Gzip enabled