Patchwork [Fortran] F2008 - allow a semicolon at the beginning of a line

login
register
mail settings
Submitter Tobias Burnus
Date June 25, 2010, 6:19 p.m.
Message ID <4C24F34D.2080209@net-b.de>
Download mbox | patch
Permalink /patch/56940/
State New
Headers show

Comments

Tobias Burnus - June 25, 2010, 6:19 p.m.
Fortran 2008 allows - for free format - a semicolon as first item in a line:

F2003 has (3.3.1.3 Free form statement termination)
"A statement may alternatively be terminated by a “;” character that
appears other than in a character
context or in a comment. The “;” is not part of the statement. After a
“;” terminator, another statement
11 may appear on the same line, or begin on that line and be continued.
A “;” shall not appear as the first
12 nonblank character on a line. [...]"

F2008 has (3.3.2.5 Free form statement termination):
"A statement may alternatively be terminated by a ';' character that
appears other than in a character context or in a comment. The ';' is
not part of the statement. After a ';' terminator, another statement may
appear on the same line, or begin on that line and be continued. [...]"

Similarly for fixed form: Here, the text
'A “;” shall not appear as the first nonblank character on a line,
except in character position 6.'
disappeared.

Note: If there is a label, a ";" is still not allowed as:
"If a statement is labeled, the statement shall contain a nonblank
character."
and as ";" does not count as statement ...

Build and regtested on x86-64-linux.
OK for the trunk?

Tobias
Jerry DeLisle - June 25, 2010, 6:47 p.m.
On 06/25/2010 11:19 AM, Tobias Burnus wrote:
> Fortran 2008 allows - for free format - a semicolon as first item in a line:
>
> F2003 has (3.3.1.3 Free form statement termination)
> "A statement may alternatively be terminated by a “;” character that
> appears other than in a character
> context or in a comment. The “;” is not part of the statement. After a
> “;” terminator, another statement
> 11 may appear on the same line, or begin on that line and be continued.
> A “;” shall not appear as the first
> 12 nonblank character on a line. [...]"
>
> F2008 has (3.3.2.5 Free form statement termination):
> "A statement may alternatively be terminated by a ';' character that
> appears other than in a character context or in a comment. The ';' is
> not part of the statement. After a ';' terminator, another statement may
> appear on the same line, or begin on that line and be continued. [...]"
>
> Similarly for fixed form: Here, the text
> 'A “;” shall not appear as the first nonblank character on a line,
> except in character position 6.'
> disappeared.
>
> Note: If there is a label, a ";" is still not allowed as:
> "If a statement is labeled, the statement shall contain a nonblank
> character."
> and as ";" does not count as statement ...
>
> Build and regtested on x86-64-linux.
> OK for the trunk?
>
> Tobias

OK, Thanks,

Jerry

Patch

2010-06-25  Tobias Burnus  <burnus@net-b.de>

	* parse.c (next_free, next_fixed): Allow ";" as first character.

2010-06-25  Tobias Burnus  <burnus@net-b.de>

	* gfortran.dg/semicolon_fixed.f: Update.
	* gfortran.dg/semicolon_fixed_2.f: New.
	* gfortran.dg/semicolon_free_2.f90: New.
	* gfortran.dg/semicolon_free.f90: Update.

Index: gcc/fortran/parse.c
===================================================================
--- gcc/fortran/parse.c	(Revision 161388)
+++ gcc/fortran/parse.c	(Arbeitskopie)
@@ -717,7 +717,9 @@  next_free (void)
  
   if (at_bol && c == ';')
     {
-      gfc_error_now ("Semicolon at %C needs to be preceded by statement");
+      if (!(gfc_option.allow_std & GFC_STD_F2008))
+	gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
+		       "statement");
       gfc_next_ascii_char (); /* Eat up the semicolon.  */
       return ST_NONE;
     }
@@ -853,7 +855,11 @@  next_fixed (void)
 
   if (c == ';')
     {
-      gfc_error_now ("Semicolon at %C needs to be preceded by statement");
+      if (digit_flag)
+	gfc_error_now ("Semicolon at %C needs to be preceded by statement");
+      else if (!(gfc_option.allow_std & GFC_STD_F2008))
+	gfc_error_now ("Fortran 2008: Semicolon at %C without preceding "
+		       "statement");
       return ST_NONE;
     }
 
Index: gcc/testsuite/gfortran.dg/semicolon_fixed_2.f
===================================================================
--- gcc/testsuite/gfortran.dg/semicolon_fixed_2.f	(Revision 0)
+++ gcc/testsuite/gfortran.dg/semicolon_fixed_2.f	(Revision 0)
@@ -0,0 +1,12 @@ 
+! { dg-do compile }
+! { dg-do options "-std=f2008" }
+
+! PR 19259 Semicolon cannot start a line
+! but it F2008 it can!
+      x=1; y=1;
+      x=2;;
+      x=3;
+      ;                         ! OK
+      ;;                        ! OK
+ 900  ;                         ! { dg-error "Semicolon at" }
+      end
Index: gcc/testsuite/gfortran.dg/semicolon_fixed.f
===================================================================
--- gcc/testsuite/gfortran.dg/semicolon_fixed.f	(Revision 161388)
+++ gcc/testsuite/gfortran.dg/semicolon_fixed.f	(Arbeitskopie)
@@ -1,9 +1,11 @@ 
 ! { dg-do compile }
-! PR 19259 Semicolon cannot start a line
+! { dg-do options "-std=f2003" }
+!
+! PR 19259 Semicolon cannot start a line (in F2003)
       x=1; y=1;
       x=2;;
       x=3;
-      ;                         ! { dg-error "Semicolon at" }
-      ;;                        ! { dg-error "Semicolon at" }
+      ;                         ! { dg-error "Fortran 2008: Semicolon at" }
+      ;;                        ! { dg-error "Fortran 2008: Semicolon at" }
  900  ;                         ! { dg-error "Semicolon at" }
       end
Index: gcc/testsuite/gfortran.dg/semicolon_free_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/semicolon_free_2.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/semicolon_free_2.f90	(Revision 0)
@@ -0,0 +1,10 @@ 
+! { dg-do compile }
+! { dg-options "-std=f2008" }
+! PR 19259 Semicolon cannot start a line
+x=1; y=1;
+x=2;;
+x=3;
+ ; ! OK
+;; ! OK
+111 ; ! { dg-error "Semicolon at" }
+end
Index: gcc/testsuite/gfortran.dg/semicolon_free.f90
===================================================================
--- gcc/testsuite/gfortran.dg/semicolon_free.f90	(Revision 161388)
+++ gcc/testsuite/gfortran.dg/semicolon_free.f90	(Arbeitskopie)
@@ -1,4 +1,5 @@ 
 ! { dg-do compile }
+! { dg-options "-std=f2003" }
 ! PR 19259 Semicolon cannot start a line
 x=1; y=1;
 x=2;;