[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [GNU-COBOL] COBOL Grammars and Parsers



>>>>> "Chad" == Chad Slaughter <slaught@babba.advancenet.net>
>>>>> wrote the following on Thu, 15 Jul 1999 22:59:40 -0500 (CDT)

  Chad> Michael McKernan wrote :>

     ...
	
  >> I really think another alternative is k = 1 with syntactic
  >> predicates as tie-breakers.  I know, I know, I'm welcome to
  >> demonstrate that.

  Chad> yes you are. =)

     ...

  >> OK.  I'll at least try to find out how many rules break with k =
  >> 1.

  Chad> i'll save you the trouble. all of them. now with syntactic
  Chad> predicates that may be differnet, I dont know.

Things are not quite that bad, Chad.  These are the ambiguities in
the original grammar with k = 1.

    Antlr parser generator   Version 1.33MR18   1989-1998
	src/clause-file-control.g, line 8: warning: alts 3 and 8 of (..)* \
	ambiguous upon { RECORD }
	src/clause-file-descr.g, line 7: warning: alts 1 and 2 of (..)* \
	ambiguous upon { IS }
	src/clause-file-descr.g, line 44: warning: alts 1 and 2 of {..} \
	ambiguous upon { NUMERIC }
	src/clause-record-descr.g, line 7: warning: alts 2 and 3 of (..)* \
	ambiguous upon { IS }
	src/clause-condition.g, line 15: warning: alts 1 and 2 of (..) \
	ambiguous upon { IS NOT }
	src/clause-condition.g, line 15: warning: alts 1 and 3 of (..) \
	ambiguous upon { IS NOT }
	src/clause-condition.g, line 16: warning: alts 2 and 3 of (..) \
	ambiguous upon { IS NOT }
	src/clause-size-err.g, line 8: warning: alts 1 and 2 of {..} \
	ambiguous upon { NOT ON SIZE }
	src/clause-relation.g, line 4: warning: alts 2 and 4 of (..) \
	ambiguous upon { GREATER }
	src/clause-relation.g, line 5: warning: alts 3 and 5 of (..) \
	ambiguous upon { LESS }
	src/verb-accept.g, line 3: warning: alts 1 and 2 of (..) \
	ambiguous upon { PROG_NAME }
	src/verb-compute.g, line 17: warning: alts 1 and 2 of {..} \
	ambiguous upon { NOT ON SIZE }
	src/verb-compute.g, line 25: warning: alts 1 and 2 of {..} \
	ambiguous upon { END_COMPUTE }
	src/verb-go.g, line 3: warning: alts 1 and 2 of (..) \
	ambiguous upon { PROG_NAME }
	src/verb-if.g, line 9: warning: optional/exit path and alt(s) of (..)+ \
	ambiguous upon { ACCEPT COMPUTE DISPLAY ... }
	src/verb-if.g, line 13: warning: alts 1 and 2 of (..) \
	ambiguous upon { ELSE_C }
	src/verb-if.g, line 13: warning: alts 1 and 3 of (..) \
	ambiguous upon { ELSE_C }
	src/verb-if.g, line 15: warning: alts 2 and 3 of (..) \
	ambiguous upon { ELSE_C }
	src/verb-if.g, line 16: warning: optional/exit path and alt(s) of (..)+ \
	ambiguous upon { ACCEPT COMPUTE DISPLAY ... }
	src/verb-if.g, line 16: warning: alts 1 and 2 of {..} \
	ambiguous upon { END_IF }
	src/verb-if.g, line 17: warning: alts 1 and 2 of {..} \
	ambiguous upon { END_IF }
	src/verb-perform.g, line 4: warning: alts 1 and 2 of (..) \
	ambiguous upon { PROG_NAME }
	src/verb-perform.g, line 60: warning: alts 2 and 3 of (..) \
	ambiguous upon { NUMERIC }

And this is what's ledt in my modified grammar.

    Antlr parser generator   Version 1.33MR18   1989-1998
	src/clause-record-descr.g, line 7: warning: alts 2 and 3 of (..)* \
	ambiguous upon { IS }
	src/verb-compute.g, line 17: warning: alts 1 and 2 of {..} \
	ambiguous upon { NOT ON SIZE }
	src/verb-compute.g, line 25: warning: alts 1 and 2 of {..} \
	ambiguous upon { END_COMPUTE }
	src/verb-perform.g, line 4: warning: alts 1 and 2 of (..) \
	ambiguous upon { PROG_NAME }
	src/verb-perform.g, line 60: warning: alts 2 and 3 of (..) \
	ambiguous upon { NUMERIC }

The ones remaining are a bit subtle (read hard) and I won't chase
them unless we decide that pccts is a candidate generator again.
This is the diff.

diff -Naur Cobol2C/src/clause-condition.g Cobol2C.new/src/clause-condition.g
--- Cobol2C/src/clause-condition.g	Thu Dec 11 09:01:20 1997
+++ Cobol2C.new/src/clause-condition.g	Fri Jul 16 09:35:48 1999
@@ -12,9 +12,10 @@
 	; 
 general_cond
 	: arith_expr
-	  ( cond_arg
-	  | class_arg  /* need to check if above arith_expr is ident */
-	  | sign_arg
+	  ( (cond_arg)? cond_arg
+	  | ((class_arg)? class_arg  /* need to check if arith_expr is ident */
+	    | sign_arg
+	    )
 	  )
 	;
 	/*: (string_literal | arith_expr | index_name)*/
diff -Naur Cobol2C/src/clause-file-control.g Cobol2C.new/src/clause-file-contro
l.g
--- Cobol2C/src/clause-file-control.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/clause-file-control.g	Fri Jul 16 00:08:19 1999
@@ -5,8 +5,6 @@
 		<< CheckFlag(&file_control_flags, FC_ASSIGN, "ASSIGN"); >>
 	  | padding_line
 		<< CheckFlag(&file_control_flags, FC_PADDING, "PADDING"); >>
-	  | record_line
-		<< CheckFlag(&file_control_flags, FC_RECORD_DELIM, "RECORD"); >>
 	  | reserve_line
 		<< CheckFlag(&file_control_flags, FC_RESERVE, "RESERVE"); >>
 	  | org_line
@@ -15,10 +13,14 @@
 		<< CheckFlag(&file_control_flags, FC_ACCESS_MODE, "ACCESS MODE"); >>
 	  | file_status_line
 		<< CheckFlag(&file_control_flags, FC_FILE_STATUS, "FILE STATUS"); >>
-	  | record_key_line
-		<< CheckFlag(&file_control_flags, FC_RECORD_KEY, "RECORD"); >>
 	  | alt_key_line
 		<< CheckFlag(&file_control_flags, FC_ALT_RECORD, "ALTERNATE"); >>
+	  | ((record_line)?
+	       record_line
+	     << CheckFlag(&file_control_flags, FC_RECORD_DELIM, "RECORD"); >>
+	     | record_key_line
+		<< CheckFlag(&file_control_flags, FC_RECORD_KEY, "RECORD"); >>
+	     )	
 	  )*
 	  PERIOD
 		<< FileControlActions();
diff -Naur Cobol2C/src/clause-file-descr.g Cobol2C.new/src/clause-file-descr.g
--- Cobol2C/src/clause-file-descr.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/clause-file-descr.g	Fri Jul 16 02:13:53 1999
@@ -4,10 +4,11 @@
 	     #endif
 	  >>
 	  fd_line
-	  ( external_line
+	  ( ((external_line)? external_line
 		<< CheckFlag(&file_descr_flags, FD_EXTERNAL, "EXTERNAL"); >>
 	  | global_line
 		<< CheckFlag(&file_descr_flags, FD_GLOBAL, "GLOBAL"); >>
+	    )
 	  | block_line
 		<< CheckFlag(&file_descr_flags, FD_BLOCK, "BLOCK"); >>
 	  | record_line_f
@@ -41,7 +42,7 @@
 		<< WarnNotImpl("GLOBAL clause"); >>
 	;
 block_line
-	: BLOCK {CONTAINS} {integer TO} integer (RECORDS | CHARACTERS)
+	: BLOCK {CONTAINS} {(integer TO)? integer TO} integer (RECORDS | CHARACTERS)
 		<< WarnNotImpl("BLOCK clause"); >>
 	;
 record_line_f
diff -Naur Cobol2C/src/clause-relation.g Cobol2C.new/src/clause-relation.g
--- Cobol2C/src/clause-relation.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/clause-relation.g	Fri Jul 16 10:25:16 1999
@@ -1,10 +1,10 @@
 relation
 	: {IS} {NOT << SetFlag(&verb_flags, RELATION_NOT); >> } 
 	  ( geneq
-	  | gengt
-	  | genlt
-	  | genge
-	  | genle
+	  | ((genge)? genge
+	    | gengt)
+	  | ((genle)? genle
+	    | genlt)
 	  )
 	  << ClearFlag(&verb_flags, RELATION_NOT); >>
 	;
diff -Naur Cobol2C/src/clause-size-err.g Cobol2C.new/src/clause-size-err.g
--- Cobol2C/src/clause-size-err.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/clause-size-err.g	Fri Jul 16 09:47:22 1999
@@ -2,10 +2,10 @@
 
 size_err
 	: {NOT} {ON} SIZE ERROR imperative
-	  second_size_line
+	  {(second_size_line)? second_size_line}
 	;
 second_size_line
-	: {{NOT} {ON} SIZE ERROR imperative}
+	: {NOT} {ON} SIZE ERROR imperative
 	;
 /*
 	: ({NOT} {ON} SIZE ERROR imperative)?
diff -Naur Cobol2C/src/verb-accept.g Cobol2C.new/src/verb-accept.g
--- Cobol2C/src/verb-accept.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/verb-accept.g	Fri Jul 16 10:28:32 1999
@@ -1,6 +1,6 @@
 accept_stmt
 	: ACCEPT (
-		  ident << 
+		  (ident FROM ident)? ident << 
 			   { int rv = emit_accept(Ident); 
 			     if (rv != 0) ErrUndefVar(Ident);
 			   }
diff -Naur Cobol2C/src/verb-go.g Cobol2C.new/src/verb-go.g
--- Cobol2C/src/verb-go.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/verb-go.g	Fri Jul 16 11:23:51 1999
@@ -1,6 +1,6 @@
 
 go_stmt
-	: GO {TO} (ident /* procedure name */
-		  |(ident)+ DEPENDING {ON} ident
+	: GO {TO} (((ident)+ DEPENDING)? (ident)+ DEPENDING {ON} ident
+		  | ident /* procedure name */
 		  )
 	;
diff -Naur Cobol2C/src/verb-if.g Cobol2C.new/src/verb-if.g
--- Cobol2C/src/verb-if.g	Thu Dec 11 09:01:21 1997
+++ Cobol2C.new/src/verb-if.g	Fri Jul 16 11:20:43 1999
@@ -6,16 +6,15 @@
 	: IF_C << emit_if_start(); >> 
 	  condition {THEN} << emit_if_block(); >>
 		( NEXT SENTENCE << emit_if_next_sentence(); >>
-		| (statement)+ ) << emit_if_end(); >>
-	  else_clause
+		| ((statement)? statement)+ ) << emit_if_end(); >>
+	  { else_clause }
+	  ( END_IF | PERIOD )
 	;
 else_clause
-	: ( ELSE_C << emit_else_start(); >>
-		NEXT SENTENCE << emit_else_next_sentence(); >>
-	  | ELSE_C << emit_else_start(); >>
-		(statement)+ {END_IF} << emit_else_end(); >>
-	  | {END_IF} 
-	  )
+	: ELSE_C << emit_else_start(); >> 
+		( NEXT SENTENCE << emit_else_next_sentence(); >>
+		| (statement)+ << emit_else_end(); >>
+	   )
 	;
 
 



--
This message was sent through the gnu-cobol mailing list.  To remove yourself
from this mailing list, send a message to majordomo@acm.cs.umr.edu with the
words "unsubscribe gnu-cobol" in the message body.  For more information on
the GNU COBOL project, send mail to gnu-cobol-owner@acm.cs.umr.edu.