Initial Commit
[packages] / xemacs-packages / semantic / wisent / wisent-awk.wy
1 ;;; wisent-awk.wy --- GNU AWK Grammar
2
3 ;; Copyright (C) 2002 David Ponce
4 ;; Copyright 2001 Free Software Foundation, Inc.
5
6 ;; Author: David Ponce <david@dponce.com>
7 ;; Maintainer: David Ponce <david@dponce.com>
8 ;; Created: 27 Feb 2002
9 ;; Keywords: syntax
10 ;; X-RCS: $Id: wisent-awk.wy,v 1.1 2007-11-26 15:12:28 michaels Exp $
11
12 ;; This file is not part of GNU Emacs.
13
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License as
16 ;; published by the Free Software Foundation; either version 2, or (at
17 ;; your option) any later version.
18
19 ;; This program is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 ;; General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this program; see the file COPYING.  If not, write to
26 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30 ;;
31 ;; This is a port of the Bison 1.31 GNU awk grammar found in file
32 ;; tests/torture.at.  It is good to torture Wisent too ;-).
33 ;; It should report 65 SR conflicts.
34 ;; Implementation is in the file wisent-awk.el.
35
36 ;;; History:
37 ;; 
38
39 ;;%package wisent-awk-wy
40
41 %token FUNC_CALL NAME REGEXP
42 %token ERROR
43 %token YNUMBER YSTRING
44 %token RELOP APPEND_OP
45 %token ASSIGNOP MATCHOP NEWLINE CONCAT_OP
46 %token LEX_BEGIN LEX_END LEX_IF LEX_ELSE LEX_RETURN LEX_DELETE
47 %token LEX_WHILE LEX_DO LEX_FOR LEX_BREAK LEX_CONTINUE
48 %token LEX_PRINT LEX_PRINTF LEX_NEXT LEX_EXIT LEX_FUNCTION
49 %token LEX_GETLINE LEX_NEXTFILE
50 %token LEX_IN
51 %token LEX_AND LEX_OR INCREMENT DECREMENT
52 %token LEX_BUILTIN LEX_LENGTH
53
54 ;; Lowest to highest
55 %right ASSIGNOP
56 %right '?' ':'
57 %left LEX_OR
58 %left LEX_AND
59 %left LEX_GETLINE
60 %nonassoc LEX_IN
61 %left FUNC_CALL LEX_BUILTIN LEX_LENGTH
62 %nonassoc ','
63 %nonassoc MATCHOP
64 %nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
65 %left CONCAT_OP
66 %left YSTRING YNUMBER
67 %left '+' '-'
68 %left '*' '/' '%'
69 %right '!' UNARY
70 %right '^'
71 %left INCREMENT DECREMENT
72 %left '$'
73 %left '(' ')'
74 %%
75
76 start_
77   : opt_nls program opt_nls
78   ;
79
80 program
81   : rule
82   | program rule
83   | error
84   | program error
85   | ;; empty
86   ;
87
88 rule
89   : LEX_BEGIN {} action
90   | LEX_END {}   action
91   | LEX_BEGIN statement_term
92   | LEX_END statement_term
93   | pattern action
94   | action
95   | pattern statement_term
96   | function_prologue function_body
97   ;
98
99 func_name
100   : NAME
101   | FUNC_CALL
102   | lex_builtin
103   ;
104
105 lex_builtin
106   : LEX_BUILTIN
107   | LEX_LENGTH
108   ;
109
110 function_prologue
111   : LEX_FUNCTION {} func_name '\(' opt_param_list r_paren opt_nls
112   ;
113
114 function_body
115   : l_brace statements r_brace opt_semi opt_nls
116   | l_brace r_brace opt_semi opt_nls
117   ;
118
119
120 pattern
121   : exp
122   | exp ',' exp
123   ;
124
125 regexp
126   :
127  ;; In this rule, want_regexp tells yylex that the next thing is a
128  ;; regexp so it should read up to the closing slash.
129     '/' {} REGEXP '/'
130   ;
131
132 action
133   : l_brace statements r_brace opt_semi opt_nls
134   | l_brace r_brace opt_semi opt_nls
135   ;
136
137 statements
138   : statement
139   | statements statement
140   | error
141   | statements error
142   ;
143
144 statement_term
145   : nls
146   | semi opt_nls
147   ;
148
149 statement
150   : semi opt_nls
151   | l_brace r_brace
152   | l_brace statements r_brace
153   | if_statement
154   | LEX_WHILE '\(' exp r_paren opt_nls statement
155   | LEX_DO opt_nls statement LEX_WHILE '\(' exp r_paren opt_nls
156   | LEX_FOR '\(' NAME LEX_IN NAME r_paren opt_nls statement
157   | LEX_FOR '\(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement
158   | LEX_FOR '\(' opt_exp semi opt_nls semi opt_nls opt_exp r_paren opt_nls statement
159   | LEX_BREAK statement_term
160   | LEX_CONTINUE statement_term
161   | print '\(' expression_list r_paren output_redir statement_term
162   | print opt_rexpression_list output_redir statement_term
163   | LEX_NEXT statement_term
164   | LEX_NEXTFILE statement_term
165   | LEX_EXIT opt_exp statement_term
166   | LEX_RETURN {} opt_exp statement_term
167   | LEX_DELETE NAME '[' expression_list ']' statement_term
168   | LEX_DELETE NAME  statement_term
169   | exp statement_term
170   ;
171
172 print
173   : LEX_PRINT
174   | LEX_PRINTF
175   ;
176
177 if_statement
178   : LEX_IF '\(' exp r_paren opt_nls statement
179   | LEX_IF '\(' exp r_paren opt_nls statement
180     LEX_ELSE opt_nls statement
181   ;
182
183 nls
184   : NEWLINE
185   | nls NEWLINE
186   ;
187
188 opt_nls
189   : ;; empty
190   | nls
191   ;
192
193 input_redir
194   : ;; empty
195   | '<' simp_exp
196   ;
197
198 output_redir
199   : ;; empty
200   | '>' exp
201   | APPEND_OP exp
202   | '|' exp
203   | TWOWAYIO exp
204   ;
205
206 opt_param_list
207   : ;; empty
208   | param_list
209   ;
210
211 param_list
212   : NAME
213   | param_list comma NAME
214   | error
215   | param_list error
216   | param_list comma error
217   ;
218
219 ;; optional expression, as in for loop
220 opt_exp
221   : ;; empty
222   | exp
223   ;
224
225 opt_rexpression_list
226   : ;; empty
227   | rexpression_list
228   ;
229
230 rexpression_list
231   : rexp
232   | rexpression_list comma rexp
233   | error
234   | rexpression_list error
235   | rexpression_list error rexp
236   | rexpression_list comma error
237   ;
238
239 opt_expression_list
240   : ;; empty
241   | expression_list
242   ;
243
244 expression_list
245   : exp
246   | expression_list comma exp
247   | error
248   | expression_list error
249   | expression_list error exp
250   | expression_list comma error
251   ;
252
253 ;; Expressions, not including the comma operator.
254 exp     : variable ASSIGNOP {} exp
255         | '\(' expression_list r_paren LEX_IN NAME
256         | exp '|' LEX_GETLINE opt_variable
257         | exp TWOWAYIO LEX_GETLINE opt_variable
258         | LEX_GETLINE opt_variable input_redir
259         | exp LEX_AND exp
260         | exp LEX_OR exp
261         | exp MATCHOP exp
262         | regexp
263         | '!' regexp %prec UNARY
264         | exp LEX_IN NAME
265         | exp RELOP exp
266         | exp '<' exp
267         | exp '>' exp
268         | exp '?' exp ':' exp
269         | simp_exp
270         | exp simp_exp %prec CONCAT_OP
271         ;
272
273 rexp
274   : variable ASSIGNOP {} rexp
275   | rexp LEX_AND rexp
276   | rexp LEX_OR rexp
277   | LEX_GETLINE opt_variable input_redir
278   | regexp
279   | '!' regexp %prec UNARY
280   | rexp MATCHOP rexp
281   | rexp LEX_IN NAME
282   | rexp RELOP rexp
283   | rexp '?' rexp ':' rexp
284   | simp_exp
285   | rexp simp_exp %prec CONCAT_OP
286   ;
287
288 simp_exp
289   : non_post_simp_exp
290  ;; Binary operators in order of decreasing precedence.
291   | simp_exp '^' simp_exp
292   | simp_exp '*' simp_exp
293   | simp_exp '/' simp_exp
294   | simp_exp '%' simp_exp
295   | simp_exp '+' simp_exp
296   | simp_exp '-' simp_exp
297   | variable INCREMENT
298   | variable DECREMENT
299   ;
300
301 non_post_simp_exp
302   : '!' simp_exp %prec UNARY
303   | '\(' exp r_paren
304   | LEX_BUILTIN
305     '\(' opt_expression_list r_paren
306   | LEX_LENGTH '\(' opt_expression_list r_paren
307   | LEX_LENGTH
308   | FUNC_CALL '\(' opt_expression_list r_paren
309   | variable
310   | INCREMENT variable
311   | DECREMENT variable
312   | YNUMBER
313   | YSTRING
314   | '-' simp_exp    %prec UNARY
315   | '+' simp_exp    %prec UNARY
316   ;
317
318 opt_variable
319   : ;; empty
320   | variable
321   ;
322
323 variable
324   : NAME
325   | NAME '[' expression_list ']'
326   | '$' non_post_simp_exp
327   ;
328
329 l_brace
330   : '\{' opt_nls
331   ;
332
333 r_brace
334   : '\}' opt_nls
335   ;
336
337 r_paren
338   : '\)'
339   ;
340
341 opt_semi
342   : ;; empty
343   | semi
344   ;
345
346 semi
347   : ';'
348   ;
349
350 comma
351   : ',' opt_nls
352   ;
353
354 %%
355
356 ;;; wisent-awk.wy ends here