1.类的定义
1 class a [inherit Object]
2 end class
2.类中可以包含(声明,函数,新类。其中除了class都含有public、private、protected和static属性)
1 class a
2 [public] declare a as string // 声明
3
4 [private] [static] function main() // 函数
5 end function
6
7 class b // 新类
8 end class
9 end class
3.变量声明
1 declare a as integer[,b as integer]
4.函数
1 function main([a as integer[,b as integer]])[as integer]
2 end function
5.stmt_list包含声明语句、if语句、do语句、while语句、for语句、switch语句和experience表达式
6.if语句
1 if experience then
2 stmt_list
3 [else stmt_list]
4 end if
7.do语句
1 do
2 stmt_list
3 while experience end
8.while语句
1 while experience do
2 stmt_list
3 end while
9.for语句
1 for stmt_list to experience by stmt_list do
2 stmt_list
3 next
10.switch语句
1 switch experience do
2 case experience:
3 [stmt_list]
4 [case experience:
5 [stmt_list]]
6 [default:
7 [stmt_list]]
8 end switch
11.experience表达式
1 函数调用语句
2 赋值语句
3 symbol
4 string
5 number
6 true
7 false
8 (+|-)experience
9 not experience
10 experience (&|||^|%) experience
11 experience (>|<|>=|<=|==|!=) experience
12 experience (+|-|*|/) experience
13 ++symbol
14 --symbol
15 symbol++
16 symbol--
12.函数调用语句
1 函数名(参数表)
13.赋值语句
1 变量=experience
组合子代码
1 program = *item;
2 item = declare_desc |
3 class_desc |
4 function_desc;
5 property_desc = str_public |
6 str_private |
7 str_protected;
8 declare_type = str_integer |
9 str_string |
10 str_bool |
11 str_real |
12 type_symbol;
13 paramter_desc_list = (type_symbol + str_as + declare_type) +
14 *(str_comma + type_symbol + str_as + declare_type);
15 paramter_value_list = exp_desc + *(str_comma + exp_desc);
16 declare_desc = str_declare + type_symbol + str_as + declare_type +
17 *(str_comma + type_symbol + str_as + declare_type);
18 class_desc = str_class + type_symbol +
19 Parser_Combinator_Node::opt(str_inherit + type_symbol +
20 *(str_comma + (type_symbol & Parser_Combinator_Node::not(str_class | str_function | property_desc | str_static)))
21 ) + *class_content_desc + str_end + str_class;
22 class_content_desc = (Parser_Combinator_Node::opt(property_desc) + Parser_Combinator_Node::opt(str_static) +
23 (declare_desc | function_desc)) |
24 class_desc;
25 function_desc = (str_function + type_symbol) +
26 (str_leftbracket + Parser_Combinator_Node::opt(paramter_desc_list) + str_rightbracket) +
27 Parser_Combinator_Node::opt(str_as + declare_type) +
28 stmt_list +
29 (str_end + str_function);
30 stmt_list = *(stmt & Parser_Combinator_Node::not(str_end));
31 stmt = declare_desc |
32 if_desc |
33 do_desc |
34 while_desc |
35 for_desc |
36 switch_desc |
37 exp_desc;
38 if_desc = (str_if + exp_desc) +
39 (str_then + stmt_list) +
40 Parser_Combinator_Node::opt(str_else + stmt_list) +
41 (str_end + str_if);
42 do_desc = (str_do + stmt_list) +
43 (str_while + exp_desc + str_end);
44 while_desc = str_while + exp_desc + str_do + stmt_list + str_end + str_while;
45 for_desc = str_for + stmt_list + str_to + exp_desc + str_by + stmt_list + str_do + stmt_list + str_next;
46 switch_desc = str_switch + exp_desc + str_do + case_list + str_end + str_switch;
47 case_list = *case_desc;
48 case_desc = (str_case + exp_desc + str_colon + stmt_list) |
49 (str_default + str_colon + stmt_list);
50 assign_desc = type_symbol + str_equal + exp_desc;
51 call_desc = type_symbol + str_leftbracket + Parser_Combinator_Node::opt(paramter_value_list) + str_rightbracket;
52 logic_desc = (str_not + compare_desc) |
53 (compare_desc + *((str_operator_and | str_operator_or | str_xor | str_mod) + compare_desc));
54 compare_desc = term_desc + *((str_bigger | str_smaller |
55 str_bigger_equal | str_smaller_equal |
56 str_equal_equal | str_not_equal) + term_desc);
57 term_desc = factor_desc + *((str_add | str_sub) + factor_desc);
58 factor_desc = self_desc + *((str_mul | str_div) + self_desc);
59 self_desc = (str_add_add + type_symbol) |
60 (str_sub_sub + type_symbol) |
61 (type_symbol + str_add_add) |
62 (type_symbol + str_sub_sub) |
63 value_desc;
64 value_desc = call_desc |
65 assign_desc |
66 type_symbol |
67 type_string |
68 type_number |
69 str_true |
70 str_false |
71 ((str_add | str_sub) + logic_desc) |
72 (str_leftbracket + logic_desc + str_rightbracket);
73 exp_desc = logic_desc;
如有任何补充将会在此文档更新。
posted on 2011-06-27 16:36
lwch 阅读(1123)
评论(0) 编辑 收藏 引用 所属分类:
QLanguage