随笔-91  评论-137  文章-0  trackbacks-0
  1 %token "function" "as" "end";
  2 %token "integer" "string" "bool" "pointer";
  3 %token "if" "then" "else";
  4 %token "do" "while";
  5 %token "for" "to" "step" "next";
  6 %token "switch" "case" "default";
  7 %token "call" "return";
  8 %token "dll" "com" "name" "lib" "class" "alias";
  9 %token "true" "false";
 10 %token ";" "," "+" "-" "*" "/" "=" "[" "]" ":";
 11 %token ">" "<" ">=" "<=" "==";
 12 %token "not" "and" "or";
 13 
 14 %start program;
 15 
 16 var_type    ->    "integer"
 17         |    "string"
 18         |    "bool"
 19         |    "pointer"
 20         ;
 21 
 22 value_type    ->    array
 23         |    "{String}"
 24         |    "{Symbol}"
 25         |    "{digit}"
 26         |    "true"
 27         |    "false"
 28         |    function_closure
 29         ;
 30 
 31 array        ->    "{Symbol}" "[" value_list "]"
 32         ;
 33 
 34 paramter_list    ->    paramter_list "," function_closure
 35         |    paramter_list "," var_type value_type
 36         |    function_closure
 37         |    var_type value_type
 38         ;
 39 
 40 value_list    ->    value_list "," exp
 41         |    exp
 42         ;
 43 
 44 program        ->    item_list
 45         ;
 46 
 47 item_list    ->    item_list item
 48         |    item
 49         ;
 50 
 51 item        ->    function_desc
 52         |    define_desc
 53         |    array_desc
 54         ;
 55 
 56 stmt_list    ->    stmt_list stmt
 57         |    stmt
 58         ;
 59 
 60 stmt        ->    define_desc
 61         |    array_desc
 62         |    if_desc
 63         |    do_desc
 64         |    while_desc
 65         |    for_desc
 66         |    assign_desc
 67         |    call_desc
 68         |    switch_desc
 69         |    return_desc
 70         |    dll_desc
 71         |    com_desc
 72         |    ";"
 73         ;
 74 
 75 function_desc    ->    "function" "{Symbol}" "{LQ}" "{RQ}" "as" var_type stmt_list "end" "function"
 76         |    "function" "{Symbol}" "{LQ}" "{RQ}" stmt_list "end" "function"
 77         |    "function" "{Symbol}" "{LQ}" "{RQ}" "as" var_type "end" "function"
 78         |    "function" "{Symbol}" "{LQ}" "{RQ}" "end" "function"
 79         |    "function" "{Symbol}" "{LQ}" paramter_list "{RQ}" "as" var_type stmt_list "end" "function"
 80         |    "function" "{Symbol}" "{LQ}" paramter_list "{RQ}" stmt_list "end" "function"
 81         |    "function" "{Symbol}" "{LQ}" paramter_list "{RQ}" "as" var_type "end" "function"
 82         |    "function" "{Symbol}" "{LQ}" paramter_list "{RQ}" "end" "function"
 83         ;
 84 
 85 function_closure    ->    "function" "{LQ}" "{RQ}" "as" var_type stmt_list "end" "function"
 86             |    "function" "{LQ}" "{RQ}" stmt_list "end" "function"
 87             |    "function" "{LQ}" "{RQ}" "as" var_type "end" "function"
 88             |    "function" "{LQ}" "{RQ}" "end" "function"
 89             |    "function" "{LQ}" paramter_list "{RQ}" "as" var_type stmt_list "end" "function"
 90             |    "function" "{LQ}" paramter_list "{RQ}" stmt_list "end" "function"
 91             |    "function" "{LQ}" paramter_list "{RQ}" "as" var_type "end" "function"
 92             |    "function" "{LQ}" paramter_list "{RQ}" "end" "function"
 93             ;
 94 
 95 define_desc    ->    define_desc "," "{Symbol}" "[" value_list "]"
 96         |    define_desc "," "{Symbol}" "[" "]"
 97         |    define_desc "," "{Symbol}" "=" value_type
 98         |    define_desc "," "{Symbol}"
 99         |    var_type "{Symbol}" "=" value_type
100         |    var_type "{Symbol}"
101         ;
102 
103 array_desc    ->    array_desc "," "{Symbol}" "[" value_list "]"
104         |    array_desc "," "{Symbol}" "[" "]"
105         |    array_desc "," "{Symbol}" "=" value_type
106         |    array_desc "," "{Symbol}"
107         |    var_type "{Symbol}" "[" value_list "]"
108         |    var_type "{Symbol}" "[" "]"
109         ;
110 
111 if_desc        ->    "if" exp "then" "else" "end" "if"
112         |    "if" exp "then" "else" stmt_list "end" "if"
113         |    "if" exp "then" stmt_list "else" "end" "if"
114         |    "if" exp "then" stmt_list "else" stmt_list "end" "if"
115         |    "if" exp "then" "end" "if"
116         |    "if" exp "then" stmt_list "end" "if"
117         ;
118 
119 do_desc        ->    "do" stmt_list "while" exp
120         |    "do" "while" exp
121         ;
122 
123 while_desc    ->    "while" exp "do" stmt_list "end" "while"
124         |    "while" exp "do" "end" "while"
125         ;
126 
127 for_desc    ->    "for" "{Symbol}" "=" exp "to" exp "do" stmt_list "next"
128         |    "for" "{Symbol}" "=" exp "to" exp "do" "next"
129         |    "for" "{Symbol}" "=" exp "to" exp "step" exp "do" stmt_list "next"
130         |    "for" "{Symbol}" "=" exp "to" exp "step" exp "do" "next"
131         ;
132 
133 assign_desc    ->    array "=" exp
134         |    "{Symbol}" "=" exp
135         ;
136 
137 call_desc    ->    "{Symbol}" "{LQ}" "{RQ}"
138         |    "{Symbol}" "{LQ}" value_list "{RQ}"
139         |    "call" "{Symbol}" "{LQ}" "{RQ}"
140         |    "call" "{Symbol}" "{LQ}" value_list "{RQ}"
141         ;
142 
143 switch_desc    ->    "switch" exp "do" case_list "end" "switch"
144         |    "switch" exp "do" "end" "switch"
145         ;
146 
147 case_list    ->    case_list "case" exp ":"
148         |    case_list "default" ":"
149         |    "case" exp ":"
150         |    "default" ":"
151         ;
152 
153 return_desc    ->    "return" function_closure
154         |    "return" exp
155         |    "return"
156         ;
157 
158 dll_desc    ->    "dll" "lib" "{Symbol}" "function" "{Symbol}" "{LQ}" "{RQ}"
159         |    "dll" "lib" "{Symbol}" "function" "{Symbol}" "alias" "{Symbol}" "{LQ}" "{RQ}"
160         |    "dll" "lib" "{Symbol}" "function" "{Symbol}" "{LQ}" paramter_list "{RQ}"
161         |    "dll" "lib" "{Symbol}" "function" "{Symbol}" "alias" "{Symbol}" "{LQ}" paramter_list "{RQ}"
162         ;
163 
164 com_desc    ->    "com" "lib" "{Symbol}" "class" "{Symbol}" "function" "{Symbol}" "{LQ}" "{RQ}"
165         |    "com" "lib" "{Symbol}" "class" "{Symbol}" "function" "{Symbol}" "alias" "{Symbol}" "{LQ}" "{RQ}"
166         |    "com" "lib" "{Symbol}" "class" "{Symbol}" "function" "{Symbol}" "{LQ}" paramter_list "{RQ}"
167         |    "com" "lib" "{Symbol}" "class" "{Symbol}" "function" "{Symbol}" "alias" "{Symbol}" "{LQ}" paramter_list "{RQ}"
168         ;
169 
170 exp        ->    exp ">" exp1
171         |    exp "<" exp1
172         |    exp ">=" exp1
173         |    exp "<=" exp1
174         |    exp "==" exp1
175         |    exp "and" exp1
176         |    exp "or" exp1
177         |    "not" exp1
178         |    exp1
179         ;
180 
181 exp1        ->    exp1 "+" exp2
182         |    exp1 "-" exp2
183         |    exp2
184         ;
185 
186 exp2        ->    exp2 "*" exp3
187         |    exp2 "/" exp3
188         |    exp3
189         ;
190 
191 exp3        ->    "{LQ}" exp "{RQ}"
192         |    value_type
193         ;
尚未包含实数部分
posted on 2010-09-17 22:04 lwch 阅读(1054) 评论(0)  编辑 收藏 引用 所属分类: QLanguage

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理