1 ;;; wisent-awk.wy --- GNU AWK Grammar
3 ;; Copyright (C) 2002 David Ponce
4 ;; Copyright 2001 Free Software Foundation, Inc.
6 ;; Author: David Ponce <david@dponce.com>
7 ;; Maintainer: David Ponce <david@dponce.com>
8 ;; Created: 27 Feb 2002
10 ;; X-RCS: $Id: wisent-awk.wy,v 1.1 2007-11-26 15:12:28 michaels Exp $
12 ;; This file is not part of GNU Emacs.
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.
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.
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.
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.
39 ;;%package wisent-awk-wy
41 %token FUNC_CALL NAME REGEXP
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
51 %token LEX_AND LEX_OR INCREMENT DECREMENT
52 %token LEX_BUILTIN LEX_LENGTH
61 %left FUNC_CALL LEX_BUILTIN LEX_LENGTH
64 %nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
71 %left INCREMENT DECREMENT
77 : opt_nls program opt_nls
91 | LEX_BEGIN statement_term
92 | LEX_END statement_term
95 | pattern statement_term
96 | function_prologue function_body
111 : LEX_FUNCTION {} func_name '\(' opt_param_list r_paren opt_nls
115 : l_brace statements r_brace opt_semi opt_nls
116 | l_brace r_brace opt_semi opt_nls
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.
133 : l_brace statements r_brace opt_semi opt_nls
134 | l_brace r_brace opt_semi opt_nls
139 | statements statement
152 | l_brace statements r_brace
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
178 : LEX_IF '\(' exp r_paren opt_nls statement
179 | LEX_IF '\(' exp r_paren opt_nls statement
180 LEX_ELSE opt_nls statement
213 | param_list comma NAME
216 | param_list comma error
219 ;; optional expression, as in for loop
232 | rexpression_list comma rexp
234 | rexpression_list error
235 | rexpression_list error rexp
236 | rexpression_list comma error
246 | expression_list comma exp
248 | expression_list error
249 | expression_list error exp
250 | expression_list comma error
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
263 | '!' regexp %prec UNARY
268 | exp '?' exp ':' exp
270 | exp simp_exp %prec CONCAT_OP
274 : variable ASSIGNOP {} rexp
277 | LEX_GETLINE opt_variable input_redir
279 | '!' regexp %prec UNARY
283 | rexp '?' rexp ':' rexp
285 | rexp simp_exp %prec CONCAT_OP
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
302 : '!' simp_exp %prec UNARY
305 '\(' opt_expression_list r_paren
306 | LEX_LENGTH '\(' opt_expression_list r_paren
308 | FUNC_CALL '\(' opt_expression_list r_paren
314 | '-' simp_exp %prec UNARY
315 | '+' simp_exp %prec UNARY
325 | NAME '[' expression_list ']'
326 | '$' non_post_simp_exp
356 ;;; wisent-awk.wy ends here