- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This made me giggle. Prepare for parser perplexion!
[fortran]PROGRAM ReadMeOne IMPLICIT NONE CHARACTER(10) :: var READ ('(A)'), var PRINT *, var END PROGRAM ReadMeOne [/fortran] (noting that the bit after the read is a parenthesized character expression that evaluates to a valid format specification)
[plain]>ifort /check:all /warn:all /standard-semantics ReadMeOne.f90 Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.1.3.300 Build 20120130 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. ReadMeOne.f90(4): error #7395: A CHARACTER constant or a CHARACTER expression is not permitted here ['(A)'] READ ('(A)'), var --------^ ReadMeOne.f90(4): error #6442: Internal READ and WRITE statements must not use the list, namelist (Fortran 90/95 only), or unformatted forms. READ ('(A)'), var ^[/plain]and similarly:
[fortran]PROGRAM ReadMeTwo IMPLICIT NONE CHARACTER(10) :: var READ ('(') // 'A' // ')', var PRINT *, var END PROGRAM ReadMeTwo [/fortran]
[plain]>ifort /check:all /warn:all /standard-semantics ReadMeTwo.f90 Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.1.3.300 Build 20120130 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. ReadMeTwo.f90(4): error #5082: Syntax error, found '//' when expecting one of: ( , ; ...
READ ('(') // 'A' // ')', var
-------------^[/plain]This is some nasty syntax!
[fortran]PROGRAM ReadMeOne IMPLICIT NONE CHARACTER(10) :: var READ ('(A)'), var PRINT *, var END PROGRAM ReadMeOne [/fortran] (noting that the bit after the read is a parenthesized character expression that evaluates to a valid format specification)
[plain]>ifort /check:all /warn:all /standard-semantics ReadMeOne.f90 Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.1.3.300 Build 20120130 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. ReadMeOne.f90(4): error #7395: A CHARACTER constant or a CHARACTER expression is not permitted here ['(A)'] READ ('(A)'), var --------^ ReadMeOne.f90(4): error #6442: Internal READ and WRITE statements must not use the list, namelist (Fortran 90/95 only), or unformatted forms. READ ('(A)'), var ^[/plain]and similarly:
[fortran]PROGRAM ReadMeTwo IMPLICIT NONE CHARACTER(10) :: var READ ('(') // 'A' // ')', var PRINT *, var END PROGRAM ReadMeTwo [/fortran]
[plain]>ifort /check:all /warn:all /standard-semantics ReadMeTwo.f90 Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.1.3.300 Build 20120130 Copyright (C) 1985-2012 Intel Corporation. All rights reserved. ReadMeTwo.f90(4): error #5082: Syntax error, found '//' when expecting one of: ( ,
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that is nasty. The problem is created by our allowing a comma between the control list and the I/O list as an extension. But you've highlighted a situation where that creates an ambiguity.
Expect it to be a while before we get to this...
Expect it to be a while before we get to this...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I certainly wasn't expecting this to be high on the list of priorities - I'd much rather be drinking my semillon ;)
I've been trying to work out how to "parse" this in the context of F2008. I reckon you can construct cases where even the standard's language syntax becomes ambiguous. Perhaps that's a sign that I should stop fooling around and get back to paid work.
I've been trying to work out how to "parse" this in the context of F2008. I reckon you can construct cases where even the standard's language syntax becomes ambiguous. Perhaps that's a sign that I should stop fooling around and get back to paid work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In standard F2008 there is no ambiguity. The syntax rule is:
R910 read-stmt is
READ (io-control-spec-list) [input-item-list]
or READ format [, input-item-list]
The form in both of your cases is the second one with a comma between the format and the input-item-list. If no comma were there, then both examples would be an error in the way the compiler complains.
However, as I noted, we allow a comma to separate the input-item-list in the first form, leading to an ambiguity. The only solution I can think of is to recognize this case and reparse it as the second form.
R910 read-stmt is
READ (io-control-spec-list) [input-item-list]
or READ format [, input-item-list]
The form in both of your cases is the second one with a comma between the format and the input-item-list. If no comma were there, then both examples would be an error in the way the compiler complains.
However, as I noted, we allow a comma to separate the input-item-list in the first form, leading to an ambiguity. The only solution I can think of is to recognize this case and reparse it as the second form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As posted on c.l.f - it is very, very contrived, but I think you get issues with the extension of variable in F2008 to include function references returning a data pointer. Well, I can't work out how to pick the difference. Presumably I should err on the side of the pre F2008 interpretation of the syntax, not that I've found a compiler yet that accepts that syntax!
Ambiguous.f90
For the sake of clarity, an alternative main program that ifort can compile now, using the module out of the file attached above.
[fortran]PROGRAM ConfuseMe USE SomeOperators IMPLICIT NONE INTEGER :: unit REAL, POINTER :: p ! REAL :: b !************************************* unit = 10 thing = 1.0 PRINT *, (unit) .op. 666 ! /default-char-expr/ p => .op. 666 ! function ref with data ptr result ! READ (unit) .op. 666, b ! Which form of read would this be? PRINT *, p END PROGRAM ConfuseMe [/fortran]
Ambiguous.f90
For the sake of clarity, an alternative main program that ifort can compile now, using the module out of the file attached above.
[fortran]PROGRAM ConfuseMe USE SomeOperators IMPLICIT NONE INTEGER :: unit REAL, POINTER :: p ! REAL :: b !************************************* unit = 10 thing = 1.0 PRINT *, (unit) .op. 666 ! /default-char-expr/ p => .op. 666 ! function ref with data ptr result ! READ (unit) .op. 666, b ! Which form of read would this be? PRINT *, p END PROGRAM ConfuseMe [/fortran]
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page