Baihacker develops a Script Language, which is used to complete simple calculating.
The grammar of this language is as follow:
Grammar Table
Primary expression:
Number
VariableName
FunctionName
(Expression)
Postfix expression:
Primary expression
Postfix expression (ExpressionList)
Postfix expression !
Unary expression:
Postfix expression
~ Unary expression
+ Unary expression
 Unary expression
Multiplicative expression:
Unary expression
Multiplicative expression * Unary expression
Multiplicative expression / Unary expression
Additive expression:
Multiplicative expression
Additive expression + Multiplicative expression
Additive expression  Multiplicative expression
Shift expression:
Additive expression
Shift expression << Additive expression
Shift expression >> Additive expression
Relational expression:
Shift expression
Relational expression > Shift expression
Relational expression >= Shift expression
Relational expression < Shift expression
Relational expression <= Shift expression
Equality expression:
Relational expression
Equality expression == Relational expression
Equality expression != Relational expression
And expression:
Relational expression
And expression & Relational expression
Xor expression:
And expression
Xor expression ^ And expression
Or expression:
Xor expression
Or expression  Xor expression
Assignment expression:
Or expression
Or expression = Assignment expression
Expression:
Assignment expression
Empty Expression
ExpressionList:
Expression
ExpressionList, Expression
Statement:
Expression;
StatementList:
Statement
StatementList Statement
Programme:
begin
StatementList
end
Semantics and Comments
1.Empty Expression means a empty string;
2.A number is a sequence of digitals and is always a decimal number.A number is
always positive and you
3.A variable name or a function name is consiste of letters, casesensitive, and
the length is no more than 32.
4.Neither a variable name nor a function name will be begin or end.
5.Signed 32bit operations.
6.The priority of operator, the group order can be found in the grammar list.
7.The ! means factorial, and the other operator are the same as the C++'s.
8.The variables can be declared implicit, and initialized with 0.
9.The value of relational expression and equality expression is converted to 1
or 0.When the result is true, the value is 1, otherwise 0.
10.Freestyle.Spaces can occur freely.A statement can be written in mutiple lines.
The name, number shouldn't be seperated by space or new line.
11.Function list:
max(ExpressionList)
Find the maximum value of its epression list, evaluate from left to right.
When the expression list is empty, the value is 0.
min(ExpressionList)
Find the minimum value of its epression list, evaluate from left to right.
When the expression list is empty, the value is 0.
sum(ExpressionList)
Calculate the sum of its epression list, evaluate from left to right. When
the expression list is empty, the value is 0.
input(ExpressionList)
The expression list should be a list of variable name, input the variables
from left to right. The value of the whole expression is the number of variables
it inputs.
print(ExpressionList)
Print the value of each expression from left to right in a single line, when the
list is empty, just output a empty line.The value of the whole expression is the
number of expressions it prints.
while (expression1, expression2)
While the value of expression1 is not zero, evaluate expression2. The value of
the whole expression is the value when evaluating expression2 the last time.I
expression2 is never evaluated, the value is 0.
select(expression1, expression2, expression3)
Evaluate expression1 first, if the value is nonzero then evaluate expression2
and the value of the whole expression is the value of expression2, otherwise
evaluate expression3 and the value of the whole expression is the value of
expression3.
sequence()
Evalute the expression list from left to right, and the value of the whole
expression is the value of the last expression of the expression list.If the list
is empty, the value is 0.
Now, Baihacker wants to write a programme to explain this language, can you help him?
