项目地址最初文法定义为:
1 %token "void" "bool" "int" "real" "string";
2 %token "true" "false";
3 %token "{" "}" "," ";" "=";
4 %token "+" "-" "*" "/";
5 %token ">" "<" ">=" "<=" "==" "and" "not" "or";
6
7 %start program;
8
9 var_type -> "void"
10 | "bool"
11 | "int"
12 | "real"
13 | "string"
14 ;
15
16 value_type -> "{String}"
17 | "{Symbol}"
18 | "{real}"
19 | "{digit}"
20 | "true"
21 | "false"
22 ;
23
24 paramter_define_desc -> "{LQ}" paramter_defines "{RQ}"
25 | "{LQ}" "{RQ}"
26 ;
27
28 paramter_defines -> paramter_defines "," paramter_one
29 | paramter_one
30 ;
31
32 paramter_one -> var_type "{Symbol}"
33 ;
34
35 assign_type -> "{Symbol}"
36 ;
37
38 program -> item_list
39 ;
40
41 item_list -> item_list item
42 | item
43 ;
44
45 item -> function
46 | define_desc ";"
47 ;
48
49 stmt_list -> stmt_list stmt
50 | stmt
51 ;
52
53 stmt -> define_desc ";"
54 | assign_desc ";"
55 | ";"
56 ;
57
58 function -> var_type "{Symbol}" paramter_define_desc "{" stmt_list "}"
59 | var_type "{Symbol}" paramter_define_desc "{" "}"
60 ;
61
62 define_desc -> define_desc "," "{Symbol}"
63 | var_type "{Symbol}"
64 ;
65
66 assign_desc -> assign_type "=" exp
67 ;
68
69 exp -> exp ">" exp1
70 | exp "<" exp1
71 | exp ">=" exp1
72 | exp "<=" exp1
73 | exp "==" exp1
74 | exp "and" exp1
75 | exp "or" exp1
76 | "not" exp1
77 | "+" exp1
78 | "-" exp1
79 | exp1
80 ;
81
82 exp1 -> exp1 "+" exp2
83 | exp1 "-" exp2
84 | exp2
85 ;
86
87 exp2 -> exp2 "*" exp3
88 | exp2 "/" exp3
89 | exp3
90 ;
91
92 exp3 -> "{LQ}" exp "{RQ}"
93 | value_type
94 ;
由以上文法中仅有函数的定义和变量的定义
有点类C的味道.
已成功将ESLanguage大部分代码移植到这个项目里.
posted on 2011-01-13 21:38
lwch 阅读(1645)
评论(0) 编辑 收藏 引用 所属分类:
NScript