[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] use of ;; as terminator, request for grammar help
From: |
Richard Hansen |
Subject: |
Re: [bug-gawk] use of ;; as terminator, request for grammar help |
Date: |
Fri, 11 Apr 2014 18:38:33 -0400 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 2014-04-03 12:18, Eric Blake wrote:
> 2. Based on existing implementations, there is consensus that the POSIX
> grammar is overly restrictive, and that we should change it to permit:
> awk '{print} {print}'
> and:
> awk '/foo/; {print}'
>
> since existing implementations all support it. But to do that, we need
> someone with help in writing grammars to propose the changes to the one
> appearing on the POSIX page. Any input would be appreciated.
Attached are two files:
* awk-posix.y: the current POSIX awk grammar (Issue 7 2013 Edition)
* awk-proposed.y: my attempt at modifying the grammar to accept the
above examples and to reject actionless BEGIN and END patterns (to
match the normative text)
For convenience you will find a unified diff of the two files below.
I am not an expert in either awk or yacc, so reviews would be appreciated.
Thanks,
Richard
diff --git a/awk.y b/awk.y
index b12ecd9..21f7357 100644
--- a/awk.y
+++ b/awk.y
@@ -49,23 +49,18 @@
program : item_list
- | actionless_item_list
+ | item_list actionless_item
;
-item_list : newline_opt
- | actionless_item_list item terminator
- | item_list item terminator
- | item_list action terminator
+item_list : terminator_opt
+ | item_list item terminator_opt
+ | item_list actionless_item terminator
;
-actionless_item_list : item_list pattern terminator
- | actionless_item_list pattern terminator
- ;
-
-
-item : pattern action
+item : action
+ | pattern action
| Function NAME '(' param_list_opt ')'
newline_opt action
| Function FUNC_NAME '(' param_list_opt ')'
@@ -73,6 +68,10 @@ item : pattern action
;
+actionless_item : normal_pattern
+ ;
+
+
param_list_opt : /* empty */
| param_list
;
@@ -83,13 +82,20 @@ param_list : NAME
;
-pattern : Begin
- | End
- | expr
+pattern : normal_pattern
+ | special_pattern
+ ;
+
+normal_pattern : expr
| expr ',' newline_opt expr
;
+special_pattern : Begin
+ | End
+ ;
+
+
action : '{' newline_opt '}'
| '{' newline_opt terminated_statement_list '}'
| '{' newline_opt unterminated_statement_list '}'
@@ -103,6 +109,11 @@ terminator : terminator ';'
;
+terminator_opt : /* empty */
+ | terminator
+ ;
+
+
terminated_statement_list : terminated_statement
| terminated_statement_list terminated_statement
;
awk-posix.y
Description: Text document
awk-proposed.y
Description: Text document