Browsable Fortran Grammar

CC-BY

Grammar extracted by Vadim Zaytsev, see the Grammar Zoo entry for details: fortran/f90/derricks/extracted
Source used for this grammar: Jan Derricks, Fortran90.sdf, 12 July 2007

Summary

Syntax

ExecutableProgram ::=
	StartCommentBlock? ProgramUnit+
ProgramUnit ::=
	MainProgram
	FunctionSubprogram
	SubroutineSubprogram
	Module
	BlockDataSubprogram
MainProgram ::=
	ProgramStmt? MainRange
ProgramStmt ::=
	LblDef "program" ProgramName EOS
LblDef ::=
	Label?
ProgramName ::=
	Ident
MainRange ::=
	BodyConstruct+ EndProgramStmt
	InternalSubProgPart EndProgramStmt
	EndProgramStmt
BodyConstruct ::=
	SpecificationPartConstruct
	ExecutableConstruct
SpecificationPartConstruct ::=
	ImplicitStmt
	ParameterStmt
	FormatStmt
	EntryStmt
	DeclarationConstruct
	UseStmt
ImplicitStmt ::=
	LblDef "implicit" "none" EOS
	LblDef "implicit" ImplicitSpec ("," ImplicitSpec)* EOS
ImplicitSpec ::=
	TypeSpec "(" LetterSpec ("," LetterSpec)* ")"
TypeSpec ::=
	"integer" KindSelector
	"real" KindSelector
	"double" "precision"
	"complex" KindSelector
	"character" CharSelector
	"logical" KindSelector
	"type" "(" TypeName ")"
	"integer"
	"real"
	"complex"
	"logical"
	"character"
	"character" LengthSelector
KindSelector ::=
	"(" ("kind" "=")? Expr ")"
	"*" Icon
Expr ::=
	(Expr DefinedBinaryOp)? Level5Expr
DefinedBinaryOp ::=
	Dop
Level5Expr ::=
	(Level5Expr EquivOp)? EquivOperand
EquivOp ::=
	".eqv."
	".neqv."
EquivOperand ::=
	(EquivOperand OrOp)? OrOperand
OrOp ::=
	".or."
OrOperand ::=
	(OrOperand AndOp)? AndOperand
AndOp ::=
	".and."
AndOperand ::=
	NotOp? Level4Expr
NotOp ::=
	".not."
Level4Expr ::=
	(Level3Expr RelOp)? Level3Expr
Level3Expr ::=
	(Level3Expr ConcatOp)? Level2Expr
ConcatOp ::=
	"//"
Level2Expr ::=
	(Level2Expr AddOp)? AddOperand
	Sign AddOperand
AddOp ::=
	"+"
	"-"
AddOperand ::=
	(AddOperand MultOp)? MultOperand
MultOp ::=
	"*"
	"/"
MultOperand ::=
	Level1Expr (PowerOp MultOperand)?
Level1Expr ::=
	DefinedUnaryOp? Primary
DefinedUnaryOp ::=
	Dop
Primary ::=
	ArrayConstructor
	UnsignedArithmeticConstant
	Name
	DataRef
	FunctionReference
	"(" Expr ")"
	Scon
	LogicalConstant
ArrayConstructor ::=
	"(/" AcValueList "/)"
AcValueList ::=
	AcValue ("," AcValue)*
AcValue ::=
	Expr
	AcImpliedDo
AcImpliedDo ::=
	"(" Expr "," ImpliedDoVariable "=" Expr "," Expr ")"
	"(" Expr "," ImpliedDoVariable "=" Expr "," Expr "," Expr ")"
	"(" AcImpliedDo "," ImpliedDoVariable "=" Expr "," Expr ")"
	"(" AcImpliedDo "," ImpliedDoVariable "=" Expr "," Expr "," Expr ")"
ImpliedDoVariable ::=
	Ident
UnsignedArithmeticConstant ::=
	Icon "_" KindParam
	Rcon "_" KindParam
	Icon
	Rcon
	ComplexConst
KindParam ::=
	Icon
	NamedConstantUse
NamedConstantUse ::=
	Ident
ComplexConst ::=
	"(" Expr "," Expr ")"
Name ::=
	Ident
DataRef ::=
	Name "%" Name
	DataRef "%" Name
	Name "(" SectionSubscriptList ")"
	DataRef "(" SectionSubscriptList ")"
SectionSubscriptList ::=
	SectionSubscript ("," SectionSubscript)*
SectionSubscript ::=
	Expr
	SubscriptTriplet
SubscriptTriplet ::=
	Expr? ":" Expr? (":" Expr)?
FunctionReference ::=
	Name "(" FunctionArgList? ")"
FunctionArgList ::=
	FunctionArg
	FunctionArgList "," FunctionArg
	SectionSubscriptList "," FunctionArg
FunctionArg ::=
	Name "=" Expr
LogicalConstant ::=
	".true." "_" KindParam
	".false." "_" KindParam
	".true."
	".false."
PowerOp ::=
	"**"
Sign ::=
	"+"
	"-"
RelOp ::=
	"=="
	"/="
	"<"
	"<="
	">"
	">="
	".eq."
	".ne."
	".lt."
	".le."
	".gt."
	".ge."
CharSelector ::=
	"(" "len" "=" TypeParamValue "," "kind" "=" Expr ")"
	"(" "len" "=" TypeParamValue "," Expr ")"
	"(" "len" "=" TypeParamValue ")"
	"(" ("kind" "=")? Expr ")"
TypeParamValue ::=
	SpecificationExpr
	"*"
SpecificationExpr ::=
	Expr
TypeName ::=
	Ident
LengthSelector ::=
	"(" TypeParamValue ")"
	"*" CharLength
CharLength ::=
	"(" TypeParamValue ")"
	ScalarIntLiteralConstant
LetterSpec ::=
	Letter ("-" Letter)?
ParameterStmt ::=
	LblDef "parameter" "(" NamedConstantDefList ")" EOS
NamedConstantDefList ::=
	NamedConstantDef ("," NamedConstantDef)*
NamedConstantDef ::=
	NamedConstant "=" Expr
NamedConstant ::=
	Ident
FormatStmt ::=
	LblDef "format" "(" FormatItemList? ")" EOS
FormatItemList ::=
	FormatItem ("," FormatItem)*
FormatItem ::=
	Icon? DataEditDescr
	ControlEditDescr
	CharStringEditDescr
	Icon? "(" FormatItemList ")"
	FormatItem ":" FormatItem
DataEditDescr ::=
	"I" Icon ("." Icon)?
	"O" Icon ("." Icon)?
	"B" Icon ("." Icon)?
	"Z" Icon ("." Icon)?
	"F" Icon "." Icon
	"E" Icon "." Icon ("E" Icon)?
	"EN" Icon "." Icon ("E" Icon)?
	"ES" Icon "." Icon ("E" Icon)?
	"G" Icon "." Icon ("E" Icon)?
	"L" Icon
	"A" Icon?
	"D" Icon "." Icon
ControlEditDescr ::=
	PositionEditDescr
	Icon? "/"
	":"
	SignEditDescr
	("-" | "+")? Icon "P" (Icon? DataEditDescr)?
	BlankInterpEditDescr
PositionEditDescr ::=
	"T" Icon
	"TL" Icon
	"TR" Icon
	Icon "X"
SignEditDescr ::=
	"S"
	"SP"
	"SS"
BlankInterpEditDescr ::=
	"BN"
	"BZ"
CharStringEditDescr ::=
	Scon
	Icon "H" Character+
EntryStmt ::=
	LblDef "entry" EntryName SubroutineParList EOS
	LblDef "entry" EntryName SubroutineParList "result" "(" Name ")" EOS
EntryName ::=
	Ident
SubroutineParList ::=
	"(" (SubroutinePar ("," SubroutinePar)*)? ")"
SubroutinePar ::=
	DummyArgName
	"*"
DummyArgName ::=
	Ident
DeclarationConstruct ::=
	TypeDeclarationStmt
	SpecificationStmt
	DerivedTypeDef
	InterfaceBlock
TypeDeclarationStmt ::=
	LblDef TypeSpec ("," AttrSpec)* ":" ":" EntityDecl ("," EntityDecl)* EOS
	LblDef TypeSpec EntityDecl ("," EntityDecl)* EOS
AttrSpec ::=
	"parameter"
	AccessSpec
	"allocatable"
	"dimension" "(" ArraySpec ")"
	"external"
	"intent" "(" IntentSpec ")"
	"intrinsic"
	"optional"
	"pointer"
	"save"
	"target"
AccessSpec ::=
	"public"
	"private"
ArraySpec ::=
	AssumedShapeSpecList
	DeferredShapeSpecList
	ExplicitShapeSpecList
	AssumedSizeSpec
AssumedShapeSpecList ::=
	LowerBound ":"
	DeferredShapeSpecList "," LowerBound ":"
	AssumedShapeSpecList "," AssumedShapeSpec
LowerBound ::=
	SpecificationExpr
DeferredShapeSpecList ::=
	DeferredShapeSpec ("," DeferredShapeSpec)*
DeferredShapeSpec ::=
	":"
AssumedShapeSpec ::=
	LowerBound? ":"
ExplicitShapeSpecList ::=
	ExplicitShapeSpec ("," ExplicitShapeSpec)*
ExplicitShapeSpec ::=
	(LowerBound ":")? UpperBound
UpperBound ::=
	SpecificationExpr
AssumedSizeSpec ::=
	(LowerBound ":")? "*"
	ExplicitShapeSpecList "," "*"
	ExplicitShapeSpecList "," LowerBound ":" "*"
IntentSpec ::=
	"in"
	"out"
	"in" "out"
EntityDecl ::=
	ObjectName "=" Expr
	ObjectName "(" ArraySpec ")" "=" Expr
	ObjectName "*" CharLength "=" Expr
	ObjectName "*" CharLength "(" ArraySpec ")" "=" Expr
	ObjectName
	ObjectName "*" CharLength
	ObjectName "(" ArraySpec ")"
	ObjectName "(" ArraySpec ")" "*" CharLength
ObjectName ::=
	Ident
SpecificationStmt ::=
	AccessStmt
	AllocatableStmt
	CommonStmt
	DataStmt
	DimensionStmt
	EquivalenceStmt
	ExternalStmt
	IntrinsicStmt
	SaveStmt
	IntentStmt
	NamelistStmt
	OptionalStmt
	PointerStmt
	TargetStmt
AccessStmt ::=
	LblDef AccessSpec ":" ":" AccessIdList EOS
	LblDef AccessSpec AccessIdList? EOS
AccessIdList ::=
	AccessId ("," AccessId)*
AccessId ::=
	GenericName
	GenericSpec
GenericName ::=
	Ident
GenericSpec ::=
	"operator" "(" DefinedOperator ")"
	"assignment" "(" "=" ")"
DefinedOperator ::=
	Dop
	PowerOp
	MultOp
	AddOp
	ConcatOp
	RelOp
	NotOp
	AndOp
	OrOp
	EquivOp
AllocatableStmt ::=
	LblDef "allocatable" ":" ":" ArrayAllocationList EOS
	LblDef "allocatable" ArrayAllocationList EOS
ArrayAllocationList ::=
	ArrayAllocation ("," ArrayAllocation)*
ArrayAllocation ::=
	ArrayName ("(" DeferredShapeSpecList ")")?
ArrayName ::=
	Ident
CommonStmt ::=
	LblDef "common" Comblock? CommonBlockObjectList (","? Comblock CommonBlockObjectList)* EOS
Comblock ::=
	"/" CommonBlockName? "/"
CommonBlockName ::=
	Ident
CommonBlockObjectList ::=
	CommonBlockObject ("," CommonBlockObject)*
CommonBlockObject ::=
	VariableName
	ArrayDeclarator
VariableName ::=
	Ident
ArrayDeclarator ::=
	VariableName "(" ArraySpec ")"
DataStmt ::=
	LblDef "data" Datalist EOS
Datalist ::=
	DataStmtSet ("," DataStmtSet)*
DataStmtSet ::=
	DataStmtObjectList "/" DataStmtValueList "/"
DataStmtObjectList ::=
	DataStmtObject ("," DataStmtObject)*
DataStmtObject ::=
	Variable
	DataImpliedDo
Variable ::=
	VariableName
	VariableName "(" Subscript ("," Subscript)* ")"
	VariableName SubstringRange
	VariableName "(" Subscript ("," Subscript)* ")" SubstringRange
Subscript ::=
	Expr
SubstringRange ::=
	"(" SubscriptTriplet ")"
DataImpliedDo ::=
	"(" DataIDoObjectList "," ImpliedDoVariable "=" Expr "," Expr ("," Expr)? ")"
DataIDoObjectList ::=
	DataIDoObject ("," DataIDoObject)*
DataIDoObject ::=
	ArrayElement
	DataImpliedDo
	StructureComponent
ArrayElement ::=
	StructureComponent "(" SectionSubscriptList ")"
	VariableName "(" SectionSubscriptList ")"
StructureComponent ::=
	VariableName FieldSelector
	StructureComponent FieldSelector
FieldSelector ::=
	"(" SectionSubscriptList ")" "%" Name
	"%" Name
DataStmtValueList ::=
	DataStmtValue ("," DataStmtValue)*
DataStmtValue ::=
	Constant
	NamedConstantUse "*" Constant
Constant ::=
	NamedConstantUse
	UnsignedArithmeticConstant
	"+" UnsignedArithmeticConstant
	"-" UnsignedArithmeticConstant
	Scon
	LogicalConstant
	Icon "_" Scon
	NamedConstantUse "_" Scon
	StructureConstructor
	BozLiteralConstant
StructureConstructor ::=
	TypeName "(" Expr ("," Expr)* ")"
BozLiteralConstant ::=
	BinaryConstant
	OctalConstant
	HexConstant
DimensionStmt ::=
	LblDef "dimension" ":" ":" ArrayDeclaratorList EOS
	LblDef "dimension" ArrayDeclaratorList EOS
ArrayDeclaratorList ::=
	ArrayDeclarator ("," ArrayDeclarator)*
EquivalenceStmt ::=
	LblDef "equivalence" EquivalenceSetList EOS
EquivalenceSetList ::=
	EquivalenceSet ("," EquivalenceSet)*
EquivalenceSet ::=
	"(" EquivalenceObject "," EquivalenceObject ("," EquivalenceObject)* ")"
EquivalenceObject ::=
	ArrayName
	Variable
ExternalStmt ::=
	LblDef "external" ExternalName ("," ExternalName)* EOS
ExternalName ::=
	Ident
IntrinsicStmt ::=
	LblDef "intrinsic" IntrinsicProcedureName ("," IntrinsicProcedureName)* EOS
IntrinsicProcedureName ::=
	Ident
SaveStmt ::=
	LblDef "save" ":" ":" SavedEntityList EOS
	LblDef "save" SavedEntityList? EOS
SavedEntityList ::=
	SavedEntity ("," SavedEntity)*
SavedEntity ::=
	VariableName
	"/" CommonBlockName "/"
IntentStmt ::=
	LblDef "intent" "(" IntentSpec ")" ":" ":" IntentParList EOS
	LblDef "intent" "(" IntentSpec ")" IntentParList EOS
IntentParList ::=
	IntentPar ("," IntentPar)*
IntentPar ::=
	DummyArgName
NamelistStmt ::=
	LblDef "namelist" NamelistGroup (","? NamelistGroup)* EOS
NamelistGroup ::=
	"/" NamelistGroupName "/" NamelistGroupObject ("," NamelistGroupObject)*
NamelistGroupName ::=
	Ident
NamelistGroupObject ::=
	VariableName
OptionalStmt ::=
	LblDef "optional" ":" ":" OptionalParList EOS
	LblDef "optional" OptionalParList EOS
OptionalParList ::=
	OptionalPar ("," OptionalPar)*
OptionalPar ::=
	DummyArgName
PointerStmt ::=
	LblDef "pointer" ":" ":" PointerStmtObjectList EOS
	LblDef "pointer" PointerStmtObjectList EOS
PointerStmtObjectList ::=
	PointerStmtObject ("," PointerStmtObject)*
PointerStmtObject ::=
	ObjectName
	ObjectName "(" DeferredShapeSpecList ")"
TargetStmt ::=
	LblDef "target" ":" ":" TargetObjectList EOS
	LblDef "target" TargetObjectList EOS
TargetObjectList ::=
	TargetObject ("," TargetObject)*
TargetObject ::=
	ObjectName
	ObjectName "(" ArraySpec ")"
DerivedTypeDef ::=
	DerivedTypeStmt DerivedTypeBody+ EndTypeStmt
DerivedTypeStmt ::=
	LblDef "type" TypeName EOS
	LblDef "type" ":" ":" TypeName EOS
	LblDef "type" "," AccessSpec ":" ":" TypeName EOS
DerivedTypeBody ::=
	PrivateSequenceStmt
	ComponentDefStmt
PrivateSequenceStmt ::=
	LblDef "private" EOS
	LblDef "sequence" EOS
ComponentDefStmt ::=
	LblDef TypeSpec ("," ComponentAttrSpecList)? ":" ":" ComponentDeclList EOS
	LblDef TypeSpec ComponentDeclList EOS
ComponentAttrSpecList ::=
	ComponentAttrSpec ("," ComponentAttrSpec)*
ComponentAttrSpec ::=
	"pointer"
	"dimension" "(" ComponentArraySpec ")"
ComponentArraySpec ::=
	ExplicitShapeSpecList
	DeferredShapeSpecList
ComponentDeclList ::=
	ComponentDecl ("," ComponentDecl)*
ComponentDecl ::=
	ComponentName ("(" ComponentArraySpec ")")? ("*" CharLength)?
ComponentName ::=
	Ident
EndTypeStmt ::=
	LblDef "end" "type" TypeName? EOS
InterfaceBlock ::=
	InterfaceStmt InterfaceBlockPart+ EndInterfaceStmt
InterfaceStmt ::=
	LblDef "interface" GenericName EOS
	LblDef "interface" GenericSpec EOS
	LblDef "interface" EOS
InterfaceBlockPart ::=
	InterfaceBody
	ModuleProcedureStmt
InterfaceBody ::=
	LblDef FunctionPrefix FunctionName FunctionInterfaceRange
	LblDef "subroutine" SubroutineName SubroutineInterfaceRange
FunctionPrefix ::=
	"recursive" "function"
	"recursive" TypeSpec "function"
	TypeSpec "recursive" "function"
	TypeSpec? "function"
FunctionName ::=
	Ident
FunctionInterfaceRange ::=
	FunctionParList EOS SubprogramInterfaceBody EndFunctionStmt
	FunctionParList EOS EndFunctionStmt
FunctionParList ::=
	"(" (FunctionPar ("," FunctionPar)*)? ")"
FunctionPar ::=
	DummyArgName
SubprogramInterfaceBody ::=
	SpecificationPartConstruct
	SubprogramInterfaceBody SpecificationPartConstruct
EndFunctionStmt ::=
	LblDef "end" EOS
	LblDef "end" "function" EndName? EOS
EndName ::=
	Ident
SubroutineName ::=
	Ident
SubroutineInterfaceRange ::=
	SubroutineParList EOS SubprogramInterfaceBody EndSubroutineStmt
	SubroutineParList EOS EndSubroutineStmt
EndSubroutineStmt ::=
	LblDef "end" "subroutine" EndName? EOS
	LblDef "end" EOS
ModuleProcedureStmt ::=
	LblDef "module" "procedure" ProcedureNameList EOS
ProcedureNameList ::=
	ProcedureName ("," ProcedureName)*
ProcedureName ::=
	Ident
EndInterfaceStmt ::=
	LblDef "end" "interface" EOS
UseStmt ::=
	LblDef "use" Name ("," RenameList)? EOS
	LblDef "use" Name "," "only" ":" OnlyList? EOS
RenameList ::=
	Rename ("," Rename)*
Rename ::=
	Ident "=>" UseName
UseName ::=
	Ident
OnlyList ::=
	Only ("," Only)*
Only ::=
	GenericSpec
	(Ident "=>")? UseName
ExecutableConstruct ::=
	ActionStmt
	DoConstruct
	IfConstruct
	CaseConstruct
	WhereConstruct
	EndDoStmt
ActionStmt ::=
	AllocateStmt
	CycleStmt
	DeallocateStmt
	ExitStmt
	NullifyStmt
	PointerAssignmentStmt
	WhereStmt
	ArithmeticIfStmt
	AssignmentStmt
	AssignStmt
	BackspaceStmt
	CallStmt
	CloseStmt
	ContinueStmt
	EndfileStmt
	GotoStmt
	ComputedGotoStmt
	AssignedGotoStmt
	IfStmt
	InquireStmt
	OpenStmt
	PauseStmt
	PrintStmt
	ReadStmt
	ReturnStmt
	RewindStmt
	StopStmt
	WriteStmt
AllocateStmt ::=
	LblDef "allocate" "(" AllocationList "," "stat" "=" Variable ")" EOS
	LblDef "allocate" "(" AllocationList ")" EOS
AllocationList ::=
	Allocation ("," Allocation)*
Allocation ::=
	AllocateObject AllocatedShape?
AllocateObject ::=
	VariableName
	AllocateObject FieldSelector
AllocatedShape ::=
	"(" SectionSubscriptList ")"
CycleStmt ::=
	LblDef "cycle" EndName? EOS
DeallocateStmt ::=
	LblDef "deallocate" "(" AllocateObjectList "," "stat" "=" Variable ")" EOS
	LblDef "deallocate" "(" AllocateObjectList ")" EOS
AllocateObjectList ::=
	AllocateObject ("," AllocateObject)*
ExitStmt ::=
	LblDef "exit" EndName? EOS
NullifyStmt ::=
	LblDef "nullify" "(" PointerObjectList ")" EOS
PointerObjectList ::=
	PointerObject ("," PointerObject)*
PointerObject ::=
	Name
	PointerField
PointerField ::=
	Name "(" SFExprList ")" "%" Name
	Name "(" SFDummyArgNameList ")" "%" Name
	Name "%" Name
	PointerField FieldSelector
SFExprList ::=
	SFExpr ":" Expr ":" Expr
	SFExpr ":" ":" Expr
	":" Expr ":" Expr
	":" ":" Expr
	":"
	":" Expr
	SFExpr
	SFExpr ":"
	SFExpr ":" Expr
	SFExprList "," SectionSubscript
	SFDummyArgNameList "," ":"
	SFDummyArgNameList "," ":" Expr
	SFDummyArgNameList "," SFExpr ":"
	SFDummyArgNameList "," SFExpr ":" Expr
SFExpr ::=
	SFTerm
	Sign AddOperand
	SFExpr AddOp AddOperand
SFTerm ::=
	SFFactor
	SFTerm MultOp MultOperand
SFFactor ::=
	SFPrimary
	SFPrimary PowerOp MultOperand
SFPrimary ::=
	ArrayConstructor
	Icon
	Name
	DataRef
	FunctionReference
	"(" Expr ")"
SFDummyArgNameList ::=
	SFDummyArgName ("," SFDummyArgName)*
SFDummyArgName ::=
	Ident
PointerAssignmentStmt ::=
	LblDef Name "=>" Target EOS
	LblDef Name "%" Name "=>" Target EOS
	LblDef Name "%" DataRef "=>" Target EOS
	LblDef Name "(" SFExprList ")" "%" Name "=>" Target EOS
	LblDef Name "(" SFExprList ")" "%" DataRef "=>" Target EOS
	LblDef Name "(" SFDummyArgNameList ")" "%" Name "=>" Target EOS
	LblDef Name "(" SFDummyArgNameList ")" "%" DataRef "=>" Target EOS
Target ::=
	Expr
WhereStmt ::=
	LblDef "where" "(" MaskExpr ")" AssignmentStmt
MaskExpr ::=
	Expr
AssignmentStmt ::=
	LblDef Name "%" Name "=" Expr EOS
	LblDef Name "%" DataRef "=" Expr EOS
	LblDef Name "(" SFExprList ")" "%" Name "=" Expr EOS
	LblDef Name "(" SFExprList ")" "%" DataRef "=" Expr EOS
	LblDef Name "(" SFDummyArgNameList ")" "%" Name "=" Expr EOS
	LblDef Name "(" SFDummyArgNameList ")" "%" DataRef "=" Expr EOS
	LblDef Name "=" Expr EOS
	LblDef Name "(" SFExprList ")" "=" Expr EOS
	LblDef Name "(" SFExprList ")" SubstringRange "=" Expr EOS
ArithmeticIfStmt ::=
	LblDef "if" "(" ScalarNumericExpr ")" LblRef "," LblRef "," LblRef EOS
ScalarNumericExpr ::=
	Expr
LblRef ::=
	Icon
AssignStmt ::=
	LblDef "assign" LblRef "to" VariableName EOS
BackspaceStmt ::=
	LblDef "backspace" UnitIdentifier EOS
	LblDef "backspace" "(" PositionSpec ("," PositionSpec)* ")" EOS
UnitIdentifier ::=
	UFExpr
	"*"
UFExpr ::=
	UFTerm
	Sign UFTerm
	UFExpr AddOp UFTerm
UFTerm ::=
	UFFactor
	UFTerm MultOp UFFactor
	UFTerm ConcatOp UFPrimary
UFFactor ::=
	UFPrimary
	UFPrimary PowerOp UFFactor
UFPrimary ::=
	Icon
	Scon
	Name
	FunctionReference
	DataRef
	"(" UFExpr ")"
PositionSpec ::=
	"unit="? UnitIdentifier
	"iostat=" ScalarVariable
	"err=" LblRef
ScalarVariable ::=
	VariableName
	ArrayElement
CallStmt ::=
	LblDef "call" SubroutineNameUse EOS
	LblDef "call" SubroutineNameUse "(" (ActualArg ("," ActualArg)*)? ")" EOS
SubroutineNameUse ::=
	Ident
ActualArg ::=
	(Name "=")? Expr
	(Name "=")? "*" LblRef
CloseStmt ::=
	LblDef "close" "(" CloseSpecList ")" EOS
CloseSpecList ::=
	CloseSpec ("," CloseSpec)*
CloseSpec ::=
	UnitIdentifier
	"unit" "=" UnitIdentifier
	"iostat" "=" ScalarVariable
	"err" "=" LblRef
	"status" "=" CExpr
CExpr ::=
	(CExpr ConcatOp)? CPrimary
CPrimary ::=
	COperand
	"(" CExpr ")"
COperand ::=
	Scon
	Name
	DataRef
	FunctionReference
ContinueStmt ::=
	LblDef "continue" EOS
EndfileStmt ::=
	LblDef "end" "file" UnitIdentifier EOS
	LblDef "end" "file" "(" PositionSpec ("," PositionSpec)* ")" EOS
GotoStmt ::=
	LblDef GoToKw LblRef EOS
GoToKw ::=
	"go" "to"
ComputedGotoStmt ::=
	LblDef GoToKw "(" LblRef ("," LblRef)* ")" ","? ScalarIntExpr EOS
ScalarIntExpr ::=
	Expr
AssignedGotoStmt ::=
	LblDef GoToKw VariableName EOS
	LblDef GoToKw VariableName ","? "(" LblRef ("," LblRef)* ")" EOS
IfStmt ::=
	LblDef "if" "(" ScalarLogicalExpr ")" ActionStmt
ScalarLogicalExpr ::=
	Expr
InquireStmt ::=
	LblDef "inquire" "(" InquireSpecList ")" EOS
	LblDef "inquire" "(" "iolength" "=" ScalarVariable ")" OutputItemList EOS
InquireSpecList ::=
	UnitIdentifier "," InquireSpec ("," InquireSpec)*
	InquireSpec ("," InquireSpec)*
InquireSpec ::=
	"unit" "=" UnitIdentifier
	"file" "=" CExpr
	"iostat" "=" ScalarVariable
	"err" "=" LblRef
	"exist" "=" ScalarVariable
	"opened" "=" ScalarVariable
	"number" "=" ScalarVariable
	"named" "=" ScalarVariable
	"name" "=" ScalarVariable
	"access" "=" ScalarVariable
	"sequential" "=" ScalarVariable
	"direct" "=" ScalarVariable
	"form" "=" ScalarVariable
	"formatted" "=" ScalarVariable
	"unformatted" "=" ScalarVariable
	"recl" "=" Expr
	"nextrec" "=" ScalarVariable
	"blank" "=" ScalarVariable
	"position" "=" ScalarVariable
	"action" "=" ScalarVariable
	"read" "=" ScalarVariable
	"write" "=" ScalarVariable
	"readwrite" "=" ScalarVariable
	"delim" "=" ScalarVariable
	"pad" "=" ScalarVariable
OutputItemList ::=
	OutputItem ("," OutputItem)*
OutputItem ::=
	Expr
	OutputImpliedDo
OutputImpliedDo ::=
	"(" OutputItemList "," ImpliedDoVariable "=" Expr "," Expr ")"
	"(" OutputItemList "," ImpliedDoVariable "=" Expr "," Expr "," Expr ")"
OpenStmt ::=
	LblDef "open" "(" ConnectSpecList ")" EOS
ConnectSpecList ::=
	ConnectSpec ("," ConnectSpec)*
ConnectSpec ::=
	UnitIdentifier
	"unit" "=" UnitIdentifier
	"iostat" "=" ScalarVariable
	"err" "=" LblRef
	"file" "=" CExpr
	"status" "=" CExpr
	"access" "=" CExpr
	"form" "=" CExpr
	"recl" "=" Expr
	"blank" "=" CExpr
	"position" "=" CExpr
	"action" "=" CExpr
	"delim" "=" CExpr
	"pad" "=" CExpr
PauseStmt ::=
	LblDef "pause" (Icon | Scon)? EOS
PrintStmt ::=
	LblDef "print" FormatIdentifier ("," OutputItemList)? EOS
FormatIdentifier ::=
	LblRef
	CExpr
	"*"
ReadStmt ::=
	LblDef "read" RdCtlSpec InputItemList? EOS
	LblDef "read" RdFmtId EOS
	LblDef "read" RdFmtId "," InputItemList EOS
RdCtlSpec ::=
	RdUnitId
	"(" RdIoCtlSpecList ")"
RdUnitId ::=
	"(" UFExpr ")"
	"(" "*" ")"
RdIoCtlSpecList ::=
	UnitIdentifier "," IoControlSpec
	UnitIdentifier "," FormatIdentifier
	IoControlSpec
	RdIoCtlSpecList "," IoControlSpec
IoControlSpec ::=
	"unit" "=" UnitIdentifier
	"fmt" "=" FormatIdentifier
	"nml" "=" NamelistGroupName
	"rec" "=" Expr
	"iostat" "=" ScalarVariable
	"err" "=" LblRef
	"end" "=" LblRef
	"advance" "=" CExpr
	"size" "=" Variable
	"eor" "=" LblRef
InputItemList ::=
	InputItem ("," InputItem)*
InputItem ::=
	Name
	DataRef
	InputImpliedDo
InputImpliedDo ::=
	"(" InputItemList "," ImpliedDoVariable "=" Expr "," Expr ")"
	"(" InputItemList "," ImpliedDoVariable "=" Expr "," Expr "," Expr ")"
RdFmtId ::=
	LblRef
	"*"
	COperand
	COperand ConcatOp CPrimary
	RdFmtIdExpr ConcatOp CPrimary
RdFmtIdExpr ::=
	"(" UFExpr ")"
ReturnStmt ::=
	LblDef "return" Expr? EOS
RewindStmt ::=
	LblDef "rewind" UnitIdentifier EOS
	LblDef "rewind" "(" PositionSpec ("," PositionSpec)* ")" EOS
StopStmt ::=
	LblDef "stop" (Icon | Scon)? EOS
WriteStmt ::=
	LblDef "write" "(" IoControlSpecList ")" OutputItemList? EOS
IoControlSpecList ::=
	UnitIdentifier "," FormatIdentifier?
	UnitIdentifier "," IoControlSpec
	IoControlSpec
	IoControlSpecList "," IoControlSpec
DoConstruct ::=
	BlockDoConstruct
	LabelDoStmt
BlockDoConstruct ::=
	LblDef "do" LblRef EOS
	LblDef "do" LoopControl EOS
	LblDef "do" EOS
	LblDef Name ":" "do" LblRef LoopControl EOS
	LblDef Name ":" "do" LblRef EOS
	LblDef Name ":" "do" LoopControl EOS
	LblDef Name ":" "do" EOS
LoopControl ::=
	"while" "(" Expr ")"
	VariableName "=" Int-Real-Dp-Expression "," Int-Real-Dp-Expression ("," Int-Real-Dp-Expression)?
Int-Real-Dp-Expression ::=
	Expr
LabelDoStmt ::=
	LblDef "do" LblRef ","? LoopControl EOS
IfConstruct ::=
	IfThenStmt ExecutionPartConstruct* (ElseIfStmt ExecutionPartConstruct*)* (ElseStmt ExecutionPartConstruct*)? EndIfStmt
IfThenStmt ::=
	LblDef (IfConstructName ":")? "if" "(" ScalarLogicalExpr ")" "then" EOS
IfConstructName ::=
	Ident
ExecutionPartConstruct ::=
	ExecutableConstruct
	FormatStmt
	DataStmt
	EntryStmt
ElseIfStmt ::=
	LblDef "else" "if" "(" ScalarLogicalExpr ")" "then" IfConstructName? EOS
ElseStmt ::=
	LblDef "else" IfConstructName? EOS
EndIfStmt ::=
	LblDef "end" "if" IfConstructName? EOS
CaseConstruct ::=
	LblDef Name ":" "select" "case" "(" Expr ")" EOS SelectCaseRange
	LblDef "select" "case" "(" Expr ")" EOS SelectCaseRange
SelectCaseRange ::=
	SelectCaseBody EndSelectStmt
	EndSelectStmt
SelectCaseBody ::=
	CaseBodyConstruct+
CaseBodyConstruct ::=
	CaseStmt
	ExecutionPartConstruct
CaseStmt ::=
	LblDef "case" CaseSelector Name? EOS
CaseSelector ::=
	"(" CaseValueRange ("," CaseValueRange)* ")"
	"default"
CaseValueRange ::=
	Expr
	Expr ":"
	":" Expr
	Expr ":" Expr
EndSelectStmt ::=
	LblDef "end" "select" EndName? EOS
WhereConstruct ::=
	WhereConstructStmt AssignmentStmt* (ElsewhereStmt AssignmentStmt*)? EndWhereStmt
WhereConstructStmt ::=
	LblDef "where" "(" MaskExpr ")" EOS
ElsewhereStmt ::=
	LblDef "elsewhere" EOS
EndWhereStmt ::=
	LblDef "end" "where" EOS
EndDoStmt ::=
	LblDef "end" "do" Name? EOS
EndProgramStmt ::=
	LblDef "end" EOS
	LblDef "end" "program" EndName? EOS
InternalSubProgPart ::=
	Body ContainsStmt InternalSubprogram
	ContainsStmt InternalSubprogram
	InternalSubProgPart InternalSubprogram
Body ::=
	BodyConstruct+
ContainsStmt ::=
	LblDef "contains" EOS
InternalSubprogram ::=
	FunctionSubprogram
	SubroutineSubprogram
FunctionSubprogram ::=
	LblDef FunctionPrefix FunctionName FunctionRange
FunctionRange ::=
	FunctionParList EOS Body? EndFunctionStmt
	FunctionParList "result" "(" Name ")" EOS InternalSubProgPart EndFunctionStmt
	FunctionParList "result" "(" Name ")" EOS Body EndFunctionStmt
	FunctionParList "result" "(" Name ")" EOS EndFunctionStmt
	FunctionParList EOS InternalSubProgPart EndFunctionStmt
SubroutineSubprogram ::=
	LblDef "recursive"? "subroutine" SubroutineName SubroutineRange
SubroutineRange ::=
	SubroutineParList? EOS Body? EndSubroutineStmt
	SubroutineParList EOS InternalSubProgPart EndSubroutineStmt
Module ::=
	ModuleStmt ModuleBody EndModuleStmt
	ModuleStmt EndModuleStmt
ModuleStmt ::=
	LblDef "module" ModuleName EOS
ModuleName ::=
	Ident
ModuleBody ::=
	SpecificationPartConstruct
	ModuleSubprogramPartConstruct
	ModuleBody SpecificationPartConstruct
	ModuleBody ModuleSubprogramPartConstruct
ModuleSubprogramPartConstruct ::=
	ContainsStmt
	ModuleSubprogram
ModuleSubprogram ::=
	FunctionSubprogram
	SubroutineSubprogram
EndModuleStmt ::=
	LblDef "end" EOS
	LblDef "end" "module" EndName? EOS
BlockDataSubprogram ::=
	BlockDataStmt BlockDataBody EndBlockDataStmt
	BlockDataStmt EndBlockDataStmt
BlockDataStmt ::=
	LblDef "block" "data" BlockDataName? EOS
BlockDataName ::=
	Ident
BlockDataBody ::=
	BlockDataBodyConstruct+
BlockDataBodyConstruct ::=
	SpecificationPartConstruct
EndBlockDataStmt ::=
	LblDef "end" "block" "data" EndName? EOS
	LblDef "end" EOS

GrammarLabMaintained by Dr. Vadim Zaytsev a.k.a. @grammarware. Last updated in September 2015. []