ml_ver2.md

吐槽

竟然不能被jekyll 解析

收到邮件说 两个花括号内的不能被解析

然后我把所有三层括号换成了1个{

词法

字符和字符串

1
2
3
4
5
<single character> ::= <input character> except ' and \
<character literal> ::= ' <single character> ' | ' <escape sequence> '
<string character> ::= <input character> except " and \ | <escape character>
<string characters> ::= <string character> | <string characters> <string character>
<string literal> ::= " <string characters>? "

数字

1
2
3
4
5
6
7
8
9
<sign> ::= '+' | '-'
<digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
<digits> ::= <digit> { <digit> }
<unsigned integer> ::= <digits>
<unsigned floating point literal> ::= <digits> . <digits>
<unsigned number> = <unsigned integer> | <unsigned floating point literal>
<signed integer> ::= <sign>? <unsigned integer>
<signed floating point literal> = <sign>? <unsigned floating point literal>
<signed number> = <signed integer> | <signed floating point literal>

符号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<null literal> ::= '_null'
<boolean literal> ::= '_true' | '_false'
<word symbol> ::= '_and' | '_or' | '_not' | '_public' | '_const' | '_class' | '_para' | '_var' | '_pro' | '_while'| '_for' | '_foreach' | '_func' | '_if' | '_in' | '_return' | '_beark' | '_papa' | <null literal> | <boolean literal> | <basic type>
<special symbol> = '+' | '-' | '*' | '/' | '\' | '%' | '=' | '<' | '>' | '<=' | '>=' | '==' | '<>' | '(' | ')' | '[' | ']' | '{' | '}' | '.' | ',' | ';' | '"' | <word symbol>
<letter> = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'
<identifier> = <letter> { <letter> | <digit> }
<directive> = <letter> { <letter> | <digit> }
<user type> ::= <identifier>
<simple type name> ::= <identifier>
<expression name> ::= <identifier> | <ambiguous name> . <identifier>
<method name> ::= <identifier> | <ambiguous name>. <identifier>
<ambiguous name>::= <identifier> | <ambiguous name>. <identifier>
<unsigned literal> ::= <unsigned number> | <boolean literal> | <character literal> | <string literal> | <null literal>
<literal> ::= <signed number> | <boolean literal> | <character literal> | <string literal> | <null literal>

#句法

##语句

1
2
3
4
5
6
7
8
9
<symbol> ::= <identifier> | <symbol> ( '.'<identifier> | '[' <unsigned integer> ']')*
<!-- sign???? -->
<term> ::= <literal> | <symbol> | <term> ('*' | '/') <term> | '('<term>')'
<condition> ::= <term> | <condition> ('+' | '-') <condition> | '(' <condition> ')'
<compare> ::= <condition> | <compare> ('==' | '<>' | '>' | '<' | '>=' | '<=' ) <compare> | '(' <compare> ')'
<expression> ::= <compare> | '_not' <expression> | <expression> ('_and' | '_or') <expression>
<left value> = <symbol>
<basic type> ::= '_void' | '_int' | '_char' | '_double' | '_boolean'
<type> ::= <user type> | <basic type>

控制

1
2
3
4
5
<if statement> ::= '_if(' <expression> '){' <statement> '}{' <statement> '}'
<!-- break -->
<for statement> ::= '_for (' <assignment block>? ';' <expression>? ';' <assignment block>? '){'<statement>'}'
<foreach statement> ::= '_foreach (' <var name> '_in' <array name>') {'<statement>'}'
<while statement> ::= '_while (' <expression> '){' <statement>'}'

##各个执行块

1
2
3
4
<judge block> ::= <if statement>
<cycle block> ::= <for statement> | <foreach statement> | <while statement>
<call block> ::= <function name> '(' (<expression> { ',' <expression> })? ')'
<assignment block> ::= <left value> '=' <expression>

##各个语句块

1
2
3
4
5
6
7
8
9
<var name> ::= <identifier> 
<const name> ::= <identifier>
<function name> ::= <identifier>
<class name> ::= <identifier>
<const definition> ::= <basic type> ' ' <const name> '=' <literal> ';'
<para definition> ::= <type> '[]'? <var name> ';'
<var definition> ::= <type> '[]'? <var name> { ',' '[]'? <var name> } ';'
<statement sentence> ::= <judge block> | <cycle block> | <call block> | <assignment block> ';'
<statement> ::= <statement sentence>+

##各个模块

1
2
3
4
5
<const block> ::= '_const{' <const definition>+ '};'
<para block> ::= '_para{' <para definition>+ '};'
<var block> ::= '_var{' <var definition>+ '};'
<pro block> ::= '_pro{' <statement> '};'
<class block> ::= '_class <class name>{'('_papa{'<class name>'};')? <const block>? <var block>? <function unit>+ '};'

##各个单元

1
2
3
<public unit> ::= '_public{' <const block>? <class block>* <var block>? '};'
<function unit> ::= '_func <type> <function name>{' <const block>? <para block>? <var block>? <pro block>?'};'
<main unit> ::= '_main{'<const block>? <var block>? <pro block>? '};'

##最终code

1
<compilation unit> ::= <public unit>? <function unit>? <main unit>?

类型

Booleans

1
_bool bianliang;
1
2
_true
_false

Numbers

1
2
_int bianliang;
_double bianliang;
1
2
3
4
123
-123
12.3
-12.3

Characters

1
_char bianliang;
1
2
3
4
'1'
'\t'
'\''
'\\'

Strings

1
_char [] bianliang;
1
2
3
""
"1"
"123"

Void

1
2
3
_func _void f{
return ;
}

Null

1
2
<!-- ??? -->
if(a == _null){}{};

lists

1
2
3
4
<type> '[]' <listname>
_int [] a;
Symbols[<unsigned integer>]
a[2]

Symbols

start with letter ,including letter and number, Not case sensitive

1
2
bianliang
feifeifeifeichangmeilidejutu12138

运算

优先级 运算符 举例
1 () (1+1)
2 * / 2*3
3 + - 2==2
4 > < >= <= == <> 1+2==2+1
5 _and _not _or 1==1 _and 2==2
6 = a=1

控制块

选择块

1
2
_if(<condition>){true <statements>}{false <statements>};
_if(1==1){a=1;}{};

循环块

1
2
_for(<for init>;<condition>;<for update>){<statements>};
_for(i=1;i<5;i=i+1){a=a+i;_break;};
1
2
_foreach(<item> _in <array>){<statements>};
_foreach(a _in b){s=s+a;};
1
2
_while(<condition>){<statements>};
_while(1==1){a=a+1;_break;};

break from _for or _while

1
_break;

语句块

const

1
2
3
4
_const{
_int a = 2;
_char b = '2';
}

var

1
2
3
4
5
6
_var{
_int a;
_char b;
_double c,d,e;
_int [] c, [] d;
}

执行部分

1
2
3
_pro{
{<control block> | <assignment block>}+
}

Functions

定义

1
2
3
4
5
6
7
8
9
10
_func _int f{
_const{};
_para{
_int [] a;
_int b;
_int c;
}
_var{};
_pro{};
};

调用

f(a,1,2)

定义

1
2
3
4
5
6
_class yourclass{
_papa{fulei};
_const{};
_var{};
(_func <type> <function name>{};)*
};

声明变量

1
2
yourclass a;
yourclass [] a;

调用

1
2
3
a.f;
a.q();
a.p(1,2,3);

注释

1
2
3
4
5
#12138

^#{
块注释
^#}

空语句

1
2
{}
;

样例程序

快排

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
_func _void quickSort{
_para{
_int [] s;
_int l
_int r;
};
_var{
_int i;
};
_pro{
_if (l< r){
i = l;
j = r;
x = s[l];
_while (i < j){
_while(i < j _and s[j]>= x){
j=j-1;
};
_if(i < j){
s[i] = s[j];
i=i+1;
}{};
_while(i < j _and s[i]< x){
i=i+1;
};
_if(i < j){
s[j] = s[i];
j=j-1;
}{};
};
s[i] = x;
quickSort(s, l, i - 1);
quickSort(s, i + 1, r);
}{};
};
};

_main{
_const{
_int printi 0;#print int
_int prints 1;#print string
};
_var{
_int [] array;
_int len,k;
};
_pro{
array[]=[34,65,12,43,67,5,78,10,3,70];
len = 10;#len=sizeof(array)/sizeof(int);
print(prints,"The orginal arrayare:\n");
_for(k=0;k<len;k=k+1){
print(printi,array[k]);
print(prints,",");
};
print(prints,"\n");
quickSort(array,0,len-1);
print(prints,"The sorted arrayare:\n");
_for(k=0;k<len;k=k+1){
print(printi,array[k]);
print(prints,",");
};
print(prints,"\n");
return 0;
};
};