AFSim 仿真系统----脚本语言语法

以下详细描述了脚本语言允许的语法。用户通常不需要查看这些细节。

 

字符类型

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_".

digit = "0123456789".

cr = '\r'.

lf = '\n'.

tab = '\t'.

quote = '"'.

single_quote = "'".

strchar = ANY - '"' - '\' - '\n' - '\r'.

chrchar = ANY - "'" - '\' - '\n' - '\r'.

记号

ident = alpha {alpha | digit}.
// 数字不允许 '+' 或 '-' 作为前缀。
// 相反,它们被作为一元运算符处理
number = digit {digit}.
real_number =
(
( digit {digit} '.' {digit} )
| ( '.' digit {digit} )
) [ ('e' | 'E') [ '-' | '+' ] digit {digit} ].

// strchar 不包括 '',所以显式添加 '' 和 '"'
string_literal = quote { strchar | ("\" [ '"' ]) } quote.
char_literal = "'" (chrchar | "\'") "'".
dot = ".".
semicolon = ";".
lparen = "(".
rparen = ")".
assign = "=".
eq = "==".
ne = "!=".
ge = ">=".
le = "<=".
plus = "+".
minus = "-".
and = "&&".
or = "||".
rbrace = '}'.
comma = ','.
plus_assign = "+=".
minus_assign = "-=".
times_assign = "*=".
div_assign = "/=".
r_arrow = "->".
do = "do".
if = "if".
for = "for".
foreach = "foreach".
in = "in".
else = "else".
while = "while".
break = "break".
continue = "continue".
return = "return".
null = "null".
null2 = "NULL".
true = "true".
false = "false".

string = "string".
int = "int".
double = "double".
char = "char".
bool = "bool".
global = "global".
static = "static".
extern = "extern".

注释

FROM "/" TO "/" NESTED
FROM "//" TO end of line
FROM "#" TO end of line

生成规则

// 语法:
// '[ ... ]' - 可选规则(匹配 0 或 1 次)
// '{ ... }' - 重复(匹配 0 到多次)
// '( ... )' - 规则分组
// | - 或(匹配左边规则或右边规则)

basic_type =
string
| int
| double
| char
| bool
.

type
= basic_type
| ident
// 注意:仅允许 1 或 2 个模板参数
[ '<' type [ ',' type ] '>' ]
.

trailer
= '('
[ exp
{
',' exp
}
]
')'
| ( '[' exp1 ']' [ '=' exp ] )
| '.' ident
| "->" ident
.

static_exp =
(null | null2)
| true
| false
| string_literal
| char_literal
| real_number
| number
.

block = '{' {stat} '}'
.
block_func = {stat} EOF.

extern_stat
= ( extern type ident )
( '('
[ type [ident] { ',' type [ident] } ]
')' ';'
)
| ';'
.

var_decl_expr = type ident .

var_decl
= [ static | extern | global ] type ident
['=' ( exp ) ]
{ ',' ident ['=' ( exp ) ] }
.

do_stat
= do stat while '(' bool_exp ')' ';'
.
while_stat
= "while" '(' bool_exp ')' stat
.
bool_exp = exp
.
stat
= (
do_stat
| while_stat
| if '(' bool_exp ')'
stat
[ else stat ]
| return [ exp ] ';'
| break ';'
| continue ';'
| for '(' [ var_decl | assign_expr ] ';' exp ';' [assign_expr] ')'
stat
| foreach '(' var_decl_expr [ ':' var_decl_expr ] in exp ')'
stat
| block
| extern_stat
| stat2
)
.

// 存根:
initializer_list
='{' [
exp [ ':' exp ] { ',' exp [ ':' exp ] }
]
[','] // 允许最后的 ','
'}'
.

AssignOp = "=" | "+=" | "-=" | "*=" | "/="
.
assign_expr = identifier AssignOp exp
.

stat2
= var_decl ';'
| assign_expr ';'
| exp ';'
.

exp = exp1.
exp1 = exp2 { or exp2 }
.
exp2 = exp3 { and exp3 }
.
exp3 = exp_eq { '^' exp_eq }
.
EqOp = ( "==" | "!=")
.
exp_eq = exp_test { EqOp exp_test }
.
TestOp = '<' | '>' | "<=" | ">="
.
exp_test = exp_add { TestOp exp_add }
.
AddOp = '+' | '-'
.
exp_add = exp_mult { AddOp exp_mult }
.
MulOp = '*' | '/'
.
exp_mult = exp5 { MulOp exp5 }
.
exp5 =
'(' type ')' exp5
| '!' exp5
| exp6
.
exp6 = [( "+" | "-" ) ] exp7
.
exp7 = atom { trailer }
.
identifier = ident
.
atom
= '(' exp1 ')'
| static_exp
| type
'.' ident
| '(' [ exp { ',' exp } ] ')'
| identifier
| initializer_list
.

formal_param_list
= '(' [ type ident { ',' type ident } ] ')'
.

func_def =
type ident
formal_param_list
block_func
.

你可能感兴趣的:(HLA-仿真分布式,#,AFSim仿真系统,AFSim,仿真系统)