Formally, the language’s grammar is defined as
G
= {
C
,
N
,
P
,
S
}, where:
C
is the alphabet or a set of terminal signs
N
is a set of special grammar units called nonterminal signs
P
is a set of rules, which defines whether a string belongs to the language
S
is a special nonterminal sign called start sign
A special system of signs is required to write the rules from the set
P
. The Backus-Naur form (or Backus’ Normal Form – BNF) is such a system. In this system, the nonterminal signs are enclosed in angle brackets – < and >. The rules of the set
P
must be written as: <
Z
> :: =
A
| B
| …|
W
, where:
Z
is a nonterminal sign;
A
,
B
,…,
W
are strings that are generated from concatenated strings from
S
and
N
. The vertical lines ( | ) give alternatives in defining the nonterminal sign Z, which stays on the left of the sign for defining “ :: =“.
For example:
<digit> :: = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
– or?
– zero or one repetition of the terminal or nonterminal sign in the brackets(token)? :: = null | token
+
– at least one repetition of the terminal or nonterminal sign in brackets or a list of this sign(token)+ :: = token | list_of_token
*
– zero repetitions of the terminal or nonterminal sign in
<EOL_symbol> ::
= \r | \n | \r\n
<Input_symbol>
:: = everything except <EOL_symbol>
<Ignore_symbols> :: = <EOL_symbol> | \t | \f.
These symbols are ignored while parsing<Letter_or_digit> :: = unicode_digit | unicode_letter | _
<Indentificator> :: = unicode_letter (Letter_or_digit)*
<Var_indentificator> :: = $(Letter_or_digit)+
<Number> :: = (0 .. 9)+
<Oct_digit> :: = (0 .. 7)
<Symbol_of_word> :: = everything except (<EOL_symbol> | “ | \t | \f | ‘ ‘ | ‘|’ | $ | # | >
| < | (|))
<Word> :: = (<Symbol_of_word>)+
<Symbol_of_string> :: = everything except (<EOL_symbol> | “
| \)
<String> :: = “(<Symbol_of_string>)| \b | \t | \n | \f | \r| \” | \’ | \\ | ((0..3)? (<Oct_digit>)? <Oct_digit>))*”
<Comment> :: = #(<Input_symbol>)
<Interpretative_unit> :: = <Command_line> | <If_construction> | <While_construction> | <For_construction>
<Interpretative_unit>
ends with a
<EOL_symbol>
. It is interpreted only after the <Interpretative_unit> was parsed successfully (if there is a semantic mistake in the construction, the whole construction fails and will not be interpreted).<Script_file> :: = (<Interpretative_unit>)*
EOF
<Parameter> :: = <Var_indentificator> | <Word> | <String> | (<Expression>)
<Filename> :: = <Parameter>
I<Command> :: = <Indentificator> (<Parameter>)*
, where the indentificator is the name of the command<Redirected_input> :: = < <Filename>
– the file content is the input for the command<Redirected_input> :: = > <Filename>
– the command output is redirected to the specified file<Pipe> :: = | <Command>
– the command output is an input data for command after the |<Command_line> :: = <Command> (<Redirected_input>)? (<Pipe>)* (<Redirected_output>)? <EOL_symbol>| Set_construction
<If_construction> :: = if (<Expression>)
<EOL_symbol> (<Interpretative_unit>)*
// if_block(else EOL_symbol (<Interpretative_unit>)*
// else_block )?
end_if
EOL_symbol>
<While_construction> :: =
while
(<Expression>) <EOL_symbol>
(<Interpretative_unit>)*
end_while
<EOL_symbol>
<For_construction> :: =
for
<Var_indentificator> <For_generator>
<EOL_symbol>
(<Interpretative_unit>)*
// for_block
end_for
<EOL_symbol>
<Var_indentificator>
by
<For_generator>
is made and for_block is executed for every element, which is generated by for_generator<For_generator> :: = (<Parameter>)+
// generator_1| *
// generator_2|
file
<Filename >
// generator_3|
token
<Parameter> (<Parameter>)?
(<Parameter>)+
(
$1
,
$2
,....)
<Filename>
<Parameter>
, tokenized with
(<Parameter>)?
. If there is not a second parameter, the Java token symbols are used.<Set_construction>:: =
set
// set_1|
set
<Var_indentificator>
// set_2|
set
<Var_indentificator> = (<Parameter>)*
// set_3Var_indentificator
variable(Parameter)
, divided by space, to the
Var_indentificator
variable<Expression> :: = <Or_expression>
<Or_expression> :: = <And_expression>
or
(<And_expression>)*
– returns the string
FALSE
if the left and right expressions are false, otherwise returns
TRUE
<And_expression> :: = <Bool_expression>
and
(Bool_expression)*
– returns the string T
RUE
if the left and the right
<Expression>
are true, otherwise returns
FALSE
<Bool_expression> :: = Additive_expression ((< | > | = | != | <= | >=) Additive_expression)?
–
if the left and the right
<Expression>
can be represented as numbers, this operation compares the two
<Expression>
as numbers, otherwise they are compared as strings<Additive_expression> :: = <Multiplicative_expression> ((+ | - | ..) (<Multiplicative_expression>)*
– when the operation is + or –, the arithmetic operation is performed if the left and the right <Expression> can be represented as numbers; otherwise, an ERROR
is returned. When the operation is .. ,
the left and the right <Expression> are concatenated.<Multiplicative_expression> :: = <Unary_expression> ((* | / | %) <Unary_expression>)*
– the arithmetic operations are performed if the left and right <Expression> can be referred to as a number, otherwise
ERROR
is returned<Unary_expression> :: =
not
<Unary_expression>
|
def
<Unary_expression>
| <Primary_expression>
<Unary_expression>
returns
TRUE
if the
<Expression>
has value that is not
true
, otherwise it returns
FALSE
. If the operation is
def
,
the
<Unary_expression>
returns
TRUE
if a command with name equal to the
<Expression>
value is defined.<Primary_expression> :: = <Parameter> | (<Expression>)
Each expression must be enclosed in brackets. When an expression is met it is computed. The value of the expression is a string. There are two types of expressions:
TRUE
or
FALSE
There are three types of operations:
The logical operations are described according to their priority:
NOT
– unary operation
Example:> SET $A = TRUE
> SET $B = (NOT $A)
> ECHO $B
FALSE
DEF
– unary operation. The result of this operation is
TRUE
if its argument corresponds to an already defined command> ECHO (DEF SET)
TRUE
AND
– binary operation. The result from this operation is
TRUE
if the values of both operands are
TRUE
. Otherwise, the result is
FALSE
> SET $A = TRUE
> SET $B = FALSE
> ECHO ($A AND $B)
FALSE
> SET $B = TRUE
> ECHO ($A AND $B)
TRUE
OR
– binary operation. The result is
TRUE
if one of the operands is
TRUE
. Otherwise, the result is
FALSE
> SET $A = TRUE
> SET $B = FALSE
> ECHO ($A OR $B)
TRUE
> SET $A = FALSE
> ECHO ($A OR $B)
FALSE
> ECHO (1 = 1)
TRUE
> ECHO (5 != 3)
TRUE
> ECHO (1 = A)
FALSE
> ECHO (V >= 2)
TRUE
> ECHO (A > B)
FALSE
> ECHO (a > B)
TRUE
The arithmetic operations are described according to their priority:
Note: If one or both of the arguments cannot be represented as numbers, the result from the operation is ERROR.
Examples:
ECHO (5 / 2)
>2
ECHO (5 % 2)
>1
There is only one operation:
.. binary operation – the result is the concatenation of the arguments.> ECHO (con .. cat .. enation)
> concatenation
IF (expression)
......
[ ELSE
....
]
END_IF
IF
is executed, if the expression value is
TRUE
. Otherwise, the block after
ELSE
is executed (if
ELSE
block does not exist, the block after
END_IF
is executed)
FOR
: FOR VarName ((Param)*) | (*) | (FILE FileName) | (TOKEN String [ParsString])
....
END_FOR
Note:
* means that all input parameters
($1, $2 ... $n)
are traversed.
FILE FileName
– iteration of the lines in FileName fileTOKEN [p ParsString] String
– iteration of the words in “String” divided by the symbols in
ParsString
WHILE
: WHILE (expression)
....
END_WHILE
Note:
The block is executed while the expression value is
TRUE
.
Command < FileName
When the input is redirected, the command input is the specified fileCommand > FileName
Command1 | Command2 [| Command]*