diff --git a/Parser/spec/Fortran2008.rats b/Parser/spec/Fortran2008.rats index 0100965ca3d19752580dd0562dbb81335ff87694..5d29286b7aaa62c6312c5d5a4e97eebf0dfb5a28 100644 --- a/Parser/spec/Fortran2008.rats +++ b/Parser/spec/Fortran2008.rats @@ -102,16 +102,27 @@ Comment comment = { yyValue = new Comment(new Opt<CommentContent>()); } +/ SS SEMICOLON + { + yyValue = new Comment(new Opt<CommentContent>()); + } ; // ============================================================================= // Clause 2 // ============================================================================= -//// // TODO MISSING RULE 201 +//// // R201 +//// Program ::= ProgramUnit* ; +Program program = + u:(program_unit)+ + { + yyValue = new Program(new List().addAll(u.list())); + } +; //// // R202 -//// abstract ProgramUnit ; +//// abstract ProgramUnit ::= Postamble:Comment* ; ProgramUnit program_unit = main_program / external_subprogram @@ -124,17 +135,13 @@ ProgramUnit program_unit = //// FunctionSubprogram_ExternalSubprogram:ExternalSubprogram ::= FunctionSubprogram ; //// SubroutineSubprogram_ExternalSubprogram:ExternalSubprogram ::= SubroutineSubprogram ; ExternalSubprogram external_subprogram = - f:function_subprogram + f:function_subprogram ec:(comment)* { - yyValue = new FunctionSubprogram_ExternalSubprogram(f); + yyValue = new FunctionSubprogram_ExternalSubprogram(new List().addAll(ec.list()), f); } -/ s:subroutine_subprogram - { - yyValue = new SubroutineSubprogram_ExternalSubprogram(s); - } -/ c:comment +/ s:subroutine_subprogram ec:(comment)* { - yyValue = new CommentExternalSubprogram(c); + yyValue = new SubroutineSubprogram_ExternalSubprogram(new List().addAll(ec.list()), s); } ; @@ -298,12 +305,13 @@ DeclarationConstruct declaration_construct = ; //// // R208 -//// ExecutionPart ::= ExecutableConstruct ExecutionPartConstruct* ; +//// // TODO: simplification: the first ExecutionPartConstruct must be an ExecutableConstruct +//// ExecutionPart ::= ExecutionPartConstruct* ; ExecutionPart execution_part = - ec:executable_construct el:(execution_part_construct)* + el:(execution_part_construct)+ { List el_list = new List().addAll(el.list()); - yyValue = new ExecutionPart(ec, el_list); + yyValue = new ExecutionPart(el_list); } ; @@ -313,6 +321,7 @@ ExecutionPart execution_part = //// FormatStmt_ExecutionPartConstruct:ExecutionPartConstruct ::= FormatStmt ; //// EntryStmt_ExecutionPartConstruct:ExecutionPartConstruct ::= EntryStmt ; ExecutionPartConstruct execution_part_construct = +<BEGINNING> l:label p2:format_stmt { p2.setLabel(l); @@ -702,6 +711,7 @@ DeclarationTypeSpec declaration_type_spec_without_kind = //// Real_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ; //// Double_IntrinsicTypeSpec:IntrinsicTypeSpec ; //// Complex_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ; +//// DoubleComplex_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ; //// Character_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [CharSelector] ; //// Logical_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ; IntrinsicTypeSpec intrinsic_type_spec = @@ -724,6 +734,11 @@ IntrinsicTypeSpec intrinsic_type_spec = Opt<KindSelector> k_opt = (k==null) ? new Opt<KindSelector>() : new Opt<KindSelector>(k); yyValue = new Complex_IntrinsicTypeSpec(k_opt); } +/ DOUBLE_COMPLEX k:(kind_selector)? + { + Opt<KindSelector> k_opt = (k==null) ? new Opt<KindSelector>() : new Opt<KindSelector>(k); + yyValue = new DoubleComplex_IntrinsicTypeSpec(k_opt); + } / CHARACTER c:(char_selector)? { Opt<CharSelector> c_opt = (c==null) ? new Opt<CharSelector>() : new Opt<CharSelector>(c); @@ -866,7 +881,7 @@ Sign sign = ; //// // R412 -//// SignedRealLiteralConstant ::= [Sign] RealLiteralConstant ; +//// SignedRealLiteralConstant ::= [Sign] RealLiteralConstant:AbstractRealLiteralConstant ; SignedRealLiteralConstant signed_real_literal_constant = s:(sign)? c:real_literal_constant { @@ -876,38 +891,80 @@ SignedRealLiteralConstant signed_real_literal_constant = ; //// // R413 -//// RealLiteralConstant:LiteralConstant ::= Significand [Exponent] [KindParam] ; -RealLiteralConstant real_literal_constant = - s:significand e:(EXPONENT_LETTER yyValue:exponent)? k:(UNDERSCORE yyValue:kind_param)? SS +//// abstract AbstractRealLiteralConstant:LiteralConstant ::= Significand [Exponent] [KindParam] ; +//// RealLiteralConstant:AbstractRealLiteralConstant ; +//// DoubleLiteralConstant:AbstractRealLiteralConstant ; +AbstractRealLiteralConstant real_literal_constant = + s:significand E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<Exponent> e_opt = new Opt<Exponent>(e); + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new RealLiteralConstant(s, e_opt, k_opt); + } +/ s:significand D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS { - Opt<Exponent> e_opt = (e==null) ? new Opt<Exponent>() : new Opt<Exponent>(e); + Opt<Exponent> e_opt = new Opt<Exponent>(e); + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new DoubleLiteralConstant(s, e_opt, k_opt); + } +/ s:significand k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<Exponent> e_opt = new Opt<Exponent>(); Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); yyValue = new RealLiteralConstant(s, e_opt, k_opt); } -/ d:DIGITS EXPONENT_LETTER e:exponent k:(UNDERSCORE yyValue:kind_param)? SS +/ d:DIGITS E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS { Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); yyValue = new RealLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt); } +/ d:DIGITS D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new DoubleLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt); + } ; -RealLiteralConstant real_literal_constant_without_dot = - s:significand EXPONENT_LETTER e:exponent k:(UNDERSCORE yyValue:kind_param)? SS +AbstractRealLiteralConstant real_literal_constant_without_dot = + s:significand E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS { - Opt<Exponent> e_opt = (e==null) ? new Opt<Exponent>() : new Opt<Exponent>(e); + Opt<Exponent> e_opt = new Opt<Exponent>(e); Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); yyValue = new RealLiteralConstant(s, e_opt, k_opt); } -/ s:significand_without_dot e:(EXPONENT_LETTER yyValue:exponent)? k:(UNDERSCORE yyValue:kind_param)? SS +/ s:significand D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS { - Opt<Exponent> e_opt = (e==null) ? new Opt<Exponent>() : new Opt<Exponent>(e); + Opt<Exponent> e_opt = new Opt<Exponent>(e); + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new DoubleLiteralConstant(s, e_opt, k_opt); + } +/ s:significand_without_dot E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<Exponent> e_opt = new Opt<Exponent>(e); Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); yyValue = new RealLiteralConstant(s, e_opt, k_opt); } -/ d:DIGITS EXPONENT_LETTER e:exponent k:(UNDERSCORE yyValue:kind_param)? SS +/ s:significand_without_dot D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<Exponent> e_opt = new Opt<Exponent>(e); + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new DoubleLiteralConstant(s, e_opt, k_opt); + } +/ s:significand_without_dot k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<Exponent> e_opt = new Opt<Exponent>(); + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new RealLiteralConstant(s, e_opt, k_opt); + } +/ d:DIGITS E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS { Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); yyValue = new RealLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt); } +/ d:DIGITS D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS + { + Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k); + yyValue = new DoubleLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt); + } ; //// // R414 @@ -1942,14 +1999,17 @@ UpperCobound upper_cobound = //// ExplicitShapeArraySpec:ArraySpec ::= ExplicitShapeSpec* ; //// AssumedShapeArraySpec:ArraySpec ::= AssumedShapeSpec* ; //// DeferredShapeArraySpec:ArraySpec ::= DeferredShapeSpec* ; +//// // TODO DeferredShapeArraySpec is not recognized, because the syntax is subsumed by (cont.) +//// // AssumedShapeArraySpec. This has to be rewritten later. //// AssumedSizeSpecArraySpec:ArraySpec ::= AssumedSizeSpec ; //// ImpliedShapeSpecArraySpec:ArraySpec ::= ImpliedShapeSpec* ; ArraySpec array_spec = - d:deferred_shape_spec dl:(COMMA yyValue:deferred_shape_spec)* - { - yyValue = new DeferredShapeArraySpec(new List().add(d).addAll(dl.list())); - } -/ a:assumed_size_spec +// d:deferred_shape_spec dl:(COMMA yyValue:deferred_shape_spec)* +// { +// yyValue = new DeferredShapeArraySpec(new List().add(d).addAll(dl.list())); +// } +/// + a:assumed_size_spec { yyValue = new AssumedSizeSpecArraySpec(a); } @@ -2811,7 +2871,7 @@ CoindexedNamedObject coindexed_named_object = ArrayElement array_element = p:part_ref PERCENT a:array_element { - a.getDataRef().getPartRefList().add(p); + a.getDataRef().getPartRefList().insertChild(p,0); yyValue = a; } / p:part_ref_with_subscript @@ -3136,7 +3196,7 @@ Primary primary_without_dot = Designator_OR_FunctionReference designator_OR_function_reference = pr:part_ref PERCENT df:designator_OR_function_reference { - ((Designator_OR_FunctionReference) df).getDataRef().getPartRefList().add(pr); + ((Designator_OR_FunctionReference) df).getDataRef().getPartRefList().insertChild(pr,0); yyValue = df; } / pr:(part_ref_without_subscript/part_ref) LPAREN l:substring_range_OR_actual_arg_spec_list RPAREN LPAREN s:substring_range RPAREN @@ -3887,7 +3947,7 @@ Level5Expr level_5_expr = m:equiv_operand r:level_5_expr_rest { if (m!=null) { - r = r.treeCopy(); + r = r.treeCopy(); r.getAbstractEquivOperandList().insertChild(new SimpleEquivOperand(m), 0); } yyValue = r; @@ -3895,7 +3955,7 @@ Level5Expr level_5_expr = / m:equiv_operand_without_dot r:level_5_expr_rest { if (m!=null) { - r = r.treeCopy(); + r = r.treeCopy(); r.getAbstractEquivOperandList().insertChild(new SimpleEquivOperand(m), 0); } yyValue = r; @@ -4479,6 +4539,7 @@ ForallStmt forall_stmt = //// // R801 //// Block ::= ExecutionPartConstruct* ; Block block = +<BEGINNING> el:(execution_part_construct)* { yyValue = new Block(new List().addAll(el.list())); @@ -4650,7 +4711,7 @@ DoWhileConstruct do_while_construct = ; //// // R815 -//// abstract DoStmt:AbstractStmt ::= [DoConstructName:Name]; +//// abstract DoStmt:AbstractStmt ::= [DoConstructName:Name] [GotoLabel:Label]; DoStmt do_stmt = infinite_do_stmt / simple_do_stmt @@ -4660,41 +4721,45 @@ DoStmt do_stmt = //// InfiniteDoStmt:DoStmt ; InfiniteDoStmt infinite_do_stmt = - n:(yyValue:name COLON)? DO l:label? lnc:comment + l:label? n:(yyValue:name COLON)? DO g:label? lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); - yyValue = new InfiniteDoStmt(l_opt, lnc, n_opt); + Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g); + yyValue = new InfiniteDoStmt(l_opt, lnc, n_opt, g_opt); } ; //// SimpleDoStmt:DoStmt ::= SimpleLoopControl; SimpleDoStmt simple_do_stmt = - n:(yyValue:name COLON)? DO l:label? c:simple_loop_control lnc:comment + l:label? n:(yyValue:name COLON)? DO g:label? c:simple_loop_control lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); - yyValue = new SimpleDoStmt(l_opt, lnc, n_opt, c); + Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g); + yyValue = new SimpleDoStmt(l_opt, lnc, n_opt, g_opt, c); } ; //// DoConcurrentStmt:DoStmt ::= ConcurrentLoopControl ; DoConcurrentStmt do_concurrent_stmt = - n:(yyValue:name COLON)? DO l:label? c:concurrent_loop_control lnc:comment + l:label? n:(yyValue:name COLON)? DO g:label? c:concurrent_loop_control lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); - yyValue = new DoConcurrentStmt(l_opt, lnc, n_opt, c); + Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g); + yyValue = new DoConcurrentStmt(l_opt, lnc, n_opt, g_opt, c); } ; //// DoWhileStmt:DoStmt ::= WhileLoopControl ; DoWhileStmt do_while_stmt = - n:(yyValue:name COLON)? DO l:label? c:while_loop_control lnc:comment + l:label? n:(yyValue:name COLON)? DO g:label? c:while_loop_control lnc:comment { Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n); Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l); - yyValue = new DoWhileStmt(l_opt, lnc, n_opt, c); + Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g); + yyValue = new DoWhileStmt(l_opt, lnc, n_opt, g_opt, c); } ; @@ -6198,6 +6263,7 @@ V v = //// BlankInterpControlEditDesc:ControlEditDesc ::= BlankInterpEditDesc ; //// RoundControlEditDesc:ControlEditDesc ::= RoundEditDesc ; //// DecimalControlEditDesc:ControlEditDesc ::= DecimalEditDesc ; +//// // TODO what about SignedIntLiteralEditDesc ? ControlEditDesc control_edit_desc = r:(yyValue:r)? SLASH { @@ -6383,13 +6449,13 @@ CharStringEditDesc char_string_edit_desc = //// // R1101 //// MainProgram:ProgramUnit ::= [ProgramStmt] [SpecificationPart] [ExecutionPart] [InternalSubprogramPart] EndProgramStmt ; MainProgram main_program = - p: program_stmt? s:specification_part e:execution_part? i:internal_subprogram_part? x:end_program_stmt + p: program_stmt? s:specification_part e:execution_part? i:internal_subprogram_part? x:end_program_stmt ec:(comment)* { Opt<ProgramStmt> p_opt = (p==null) ? new Opt<ProgramStmt>() : new Opt<ProgramStmt>(p); Opt<SpecificationPart> s_opt = (s==null) ? new Opt<SpecificationPart>() : new Opt<SpecificationPart>(s); Opt<ExecutionPart> e_opt = (e==null) ? new Opt<ExecutionPart>() : new Opt<ExecutionPart>(e); Opt<InternalSubprogramPart> i_opt = (i==null) ? new Opt<InternalSubprogramPart>() : new Opt<InternalSubprogramPart>(i); - yyValue = new MainProgram(p_opt, s_opt, e_opt, i_opt, x); + yyValue = new MainProgram(new List().addAll(ec.list()), p_opt, s_opt, e_opt, i_opt, x); } ; @@ -6421,11 +6487,11 @@ EndProgramStmt end_program_stmt = //// // R1104 //// Module:ProgramUnit ::= ModuleStmt [SpecificationPart] [ModuleSubprogramPart] EndModuleStmt ; Module module = - m:module_stmt s:specification_part i:(module_subprogram_part)? e:end_module_stmt + m:module_stmt s:specification_part i:(module_subprogram_part)? e:end_module_stmt ec:(comment)* { Opt<SpecificationPart> s_opt = (s==null) ? new Opt<SpecificationPart>() : new Opt<SpecificationPart>(s); Opt<ModuleSubprogramPart> i_opt = (i==null) ? new Opt<ModuleSubprogramPart>() : new Opt<ModuleSubprogramPart>(i); - yyValue = new Module(m, s_opt, i_opt, e); + yyValue = new Module(new List().addAll(ec.list()), m, s_opt, i_opt, e); } ; @@ -6462,6 +6528,7 @@ ModuleSubprogramPart module_subprogram_part = //// FunctionModuleSubprogram:ModuleSubprogram ::= FunctionSubprogram ; //// SubroutineModuleSubprogram:ModuleSubprogram ::= SubroutineSubprogram ; //// SeparateModuleModuleSubprogram:ModuleSubprogram ::= SeparateModuleSubprogram ; +//// CommentModuleSubprogram:ModuleSubprogram ::= Comment ; ModuleSubprogram module_subprogram = f:function_subprogram { @@ -6475,6 +6542,10 @@ ModuleSubprogram module_subprogram = { yyValue = new SeparateModuleModuleSubprogram(p); } +/ c:comment + { + yyValue = new CommentModuleSubprogram(c); + } ; //// // R1109 @@ -6555,10 +6626,10 @@ Only only = //// // R1120 //// BlockData:ProgramUnit ::= BlockDataStmt [SpecificationPart] EndBlockDataStmt ; BlockData block_data = - b:block_data_stmt s:specification_part x:end_block_data_stmt + b:block_data_stmt s:specification_part x:end_block_data_stmt ec:(comment)* { Opt<SpecificationPart> s_opt = (s==null) ? new Opt<SpecificationPart>() : new Opt<SpecificationPart>(s); - yyValue = new BlockData(b, s_opt, x); + yyValue = new BlockData(new List().addAll(ec.list()), b, s_opt, x); } ; @@ -6880,7 +6951,7 @@ CallStmt call_stmt = ProcedureDesignator procedure_designator = p:part_ref PERCENT d:procedure_designator { - d.getDataRef().getPartRefList().add(p); + d.getDataRef().getPartRefList().insertChild(p,0); yyValue = d; } / n:name @@ -7165,4 +7236,4 @@ ContainsStmt contains_stmt = { yyValue = new ContainsStmt(new Opt<Label>(), lnc); } -; \ No newline at end of file +; diff --git a/Parser/spec/FortranParser.rats b/Parser/spec/FortranParser.rats index 4966dd05d4e0bda897bedbb2fd491f028fd82f0d..267faada855e25fb1c25ada5b4d9ac2cf3c36b7c 100644 --- a/Parser/spec/FortranParser.rats +++ b/Parser/spec/FortranParser.rats @@ -2,11 +2,11 @@ module FortranParser(); modify OpenMp; -//// Root ::= Preamble:Comment* ProgramUnit Postamble:Comment* ; +//// Root ::= Preamble:Comment* Program ; public Root root = - bc:(comment)* s:program_unit ec:(comment)* + bc:(comment)* s:program { - yyValue = new Root(new List().addAll(bc.list()), s, new List().addAll(ec.list())); + yyValue = new Root(new List().addAll(bc.list()), s); } ; diff --git a/Parser/spec/FortranTokens.rats b/Parser/spec/FortranTokens.rats index de72bb4dc1b530732341c45444f9d94c571f7ed9..7c6fc91816018223bc021e7810ee14b301e35143 100644 --- a/Parser/spec/FortranTokens.rats +++ b/Parser/spec/FortranTokens.rats @@ -76,6 +76,7 @@ transient void DELIM = D E L I M SS; transient void DIMENSION = D I M E N S I O N SS; transient void DIRECT = D I R E C T SS; transient void DO = D O SS; +transient void DOUBLE_COMPLEX = D O U B L E SS C O M P L E X SS; transient void DOUBLE_PRECISION = D O U B L E SS P R E C I S I O N SS; transient void ELEMENTAL = E L E M E N T A L SS; transient void ELSE = E L S E SS; @@ -223,3 +224,4 @@ transient void COMMA = "," SS; transient void COLONCOLON = "::" SS; transient void ASTERISK = "*" SS; transient void EXCLAMATIONMARK = "!"; +transient void SEMICOLON = ";"; diff --git a/Parser/spec/OpenAcc.rats b/Parser/spec/OpenAcc.rats index 6aac0d16958b91efb2b40f690b427cccb2275bf8..d9fe627b5e8aa102bb3b8bc5ffe1e3d25a784baf 100644 --- a/Parser/spec/OpenAcc.rats +++ b/Parser/spec/OpenAcc.rats @@ -1,6 +1,6 @@ module OpenAcc(); -modify Fortran2008; +modify ConditionalLines; import OpenAccTokens; // allow OpenACC constructs as executable_constructs diff --git a/Parser/spec/Printing.jadd b/Parser/spec/Printing.jadd index 15b9067b841e12334d9c4d04ba40e58b1c8b45bf..bb61051b1a8899ff155bd80ee3fc70fb185c907b 100644 --- a/Parser/spec/Printing.jadd +++ b/Parser/spec/Printing.jadd @@ -20,10 +20,7 @@ class PrettyPrint { for (Comment c : getPreambleList()) { c.prettyPrint(s); } - getProgramUnit().prettyPrint(s); - for (Comment c : getPostambleList()) { - c.prettyPrint(s); - } + getProgram().prettyPrint(s); } public void CommentConstruct.prettyPrint(PrettyPrinter s){ @@ -40,6 +37,8 @@ class PrettyPrint { public void Comment.prettyPrint(PrettyPrinter s){ if (hasCommentContent()) { + s.ensureWs(); + s.append("!"); getCommentContent().prettyPrint(s); } else { s.append(""); @@ -48,17 +47,12 @@ class PrettyPrint { } public void CommentContent.prettyPrint(PrettyPrinter s) { - if (!getString().isEmpty()) { - s.ensureWs(); - s.append("!"); - s.literalAppend(getString()); - } + s.literalAppend(getString()); } public void CommentExternalSubprogram.prettyPrint(PrettyPrinter s) { getComment().prettyPrint(s); } - public void CommentInternalSubprogram.prettyPrint(PrettyPrinter s) { getComment().prettyPrint(s); } @@ -67,15 +61,22 @@ class PrettyPrint { // Clause 2 // ============================================================================= + // R201 + public void Program.prettyPrint(PrettyPrinter s) { + getProgramUnitList().prettyPrintJoin(s, ""); + } + // R203 // ExternalSubprogram:ProgramUnit ; // FunctionSubprogram_ExternalSubprogram:ExternalSubprogram ::= FunctionSubprogram ; public void FunctionSubprogram_ExternalSubprogram.prettyPrint(PrettyPrinter s) { getFunctionSubprogram().prettyPrint(s); + getPostambleList().prettyPrintJoin(s, ""); } // SubroutineSubprogram_ExternalSubprogram:ExternalSubprogram ::= SubroutineSubprogram ; public void SubroutineSubprogram_ExternalSubprogram.prettyPrint(PrettyPrinter s) { getSubroutineSubprogram().prettyPrint(s); + getPostambleList().prettyPrintJoin(s, ""); } // R204 @@ -164,7 +165,6 @@ class PrettyPrint { // R208 // ExecutionPart ::= ExecutableConstruct ExecutionPartConstruct* ; public void ExecutionPart.prettyPrint(PrettyPrinter s) { - getExecutableConstruct().prettyPrint(s); for (ExecutionPartConstruct c : getExecutionPartConstructList()) { c.prettyPrint(s); } @@ -175,6 +175,10 @@ class PrettyPrint { getExecutableConstruct().prettyPrint(s); } + public void FormatStmt_ExecutionPartConstruct.prettyPrint(PrettyPrinter s) { + getFormatStmt().prettyPrint(s); + } + // R210 public void InternalSubprogramPart.prettyPrint(PrettyPrinter s) { getContainsStmt().prettyPrint(s); @@ -264,13 +268,13 @@ class PrettyPrint { } // TypeDeclarationTypeSpec:DeclarationTypeSpec ::= TypeSpec ; public void TypeDeclarationTypeSpec.prettyPrint(PrettyPrinter s) { - s.append("type("); + s.append("TYPE("); getTypeSpec().prettyPrint(s); s.append(")"); } // ClassDeclarationTypeSpec:DeclarationTypeSpec ::= [DerivedTypeSpec] ; public void ClassDeclarationTypeSpec.prettyPrint(PrettyPrinter s) { - s.append("class("); + s.append("CLASS("); if (hasDerivedTypeSpec()) { getDerivedTypeSpec().prettyPrint(s); } else { @@ -295,6 +299,12 @@ class PrettyPrint { public void Double_IntrinsicTypeSpec.prettyPrint(PrettyPrinter s) { s.append("DOUBLE PRECISION"); } + public void DoubleComplex_IntrinsicTypeSpec.prettyPrint(PrettyPrinter s) { + s.append("DOUBLE COMPLEX"); + if (hasKindSelector()) { + getKindSelector().prettyPrint(s); + } + } public void Complex_IntrinsicTypeSpec.prettyPrint(PrettyPrinter s) { s.append("COMPLEX"); if (hasKindSelector()) { @@ -391,6 +401,18 @@ class PrettyPrint { } } + public void DoubleLiteralConstant.prettyPrint(PrettyPrinter s) { + getSignificand().prettyPrint(s); + if (hasExponent()) { + s.append("D"); + getExponent().prettyPrint(s); + } + if (hasKindParam()) { + s.append("_"); + getKindParam().prettyPrint(s); + } + } + // R414 public void Significand.prettyPrint(PrettyPrinter s) { s.append(getValue()); @@ -900,17 +922,11 @@ class PrettyPrint { // DerivedTypeSpec:TypeSpec ::= Name TypeParamSpec* ; public void DerivedTypeSpec.prettyPrint(PrettyPrinter s) { getName().prettyPrint(s); - s.append("("); - boolean first = true; - for (TypeParamSpec t : getTypeParamSpecList()) { - if (first) { - first = false; - } else { - s.append(","); - } - t.prettyPrint(s); + if (getTypeParamSpecList().numChildren()>0) { + s.append("("); + getTypeParamSpecList().prettyPrintJoin(s, ", "); + s.append(")"); } - s.append(")"); } // R454 @@ -1023,7 +1039,7 @@ class PrettyPrint { getAcValueList().prettyPrintJoin(s, ","); s.append(","); getAcImpliedDoControl().prettyPrint(s); - s.append("("); + s.append(")"); } // R474 @@ -1034,7 +1050,7 @@ class PrettyPrint { getLower().prettyPrint(s); s.append(","); getUpper().prettyPrint(s); - if (hasStep()) { + if (hasStep() && !"1".equals(getStep().prettyPrint())) { s.append(","); getStep().prettyPrint(s); } @@ -1055,6 +1071,12 @@ class PrettyPrint { s.append(","); as.prettyPrint(s); } + // if (getAttrSpecList().numChildren() > 0) { +// if (s.useColons()) { +// s.append(" :: "); +// } else { +// s.append(" "); +// } s.append(" :: "); getEntityDeclList().prettyPrintJoin(s, ","); getComment().prettyPrint(s); @@ -1633,7 +1655,6 @@ class PrettyPrint { s.append("parameter("); getNamedConstantDefList().prettyPrintJoin(s, ", "); s.append(")"); - s.append(")"); getComment().prettyPrint(s); } @@ -2874,6 +2895,132 @@ class PrettyPrint { } } + // R802 + // AssociateConstruct:ExecutableConstruct ::= AssociateStmt Block EndAssociateStmt ; + public void AssociateConstruct.prettyPrint(PrettyPrinter s) { + getAssociateStmt().prettyPrint(s); + s.ind(); + getBlock().prettyPrint(s); + s.und(); + getEndAssociateStmt().prettyPrint(s); + } + + // R803 + // AssociateStmt:AbstractStmt ::= [Name] Association* ; + public void AssociateStmt.prettyPrint(PrettyPrinter s) { + if (hasName()) { + getName().prettyPrint(s); + s.append(" "); + } + s.append("ASSOCIATE("); + for (Association a : getAssociationList()) { + a.prettyPrint(s); + } + s.append(")"); + s.lb(); + } + + // R804 + // Association ::= Name Selector ; + public void Association.prettyPrint(PrettyPrinter s) { + getName().prettyPrint(s); + s.append(" => "); + getSelector().prettyPrint(s); + } + + // R805 + // abstract Selector ; + // // TODO rewrite to variableselector! + // ExprSelector:Selector ::= Expr ; + public void ExprSelector.prettyPrint(PrettyPrinter s) { + getExpr().prettyPrint(s); + } + // VariableSelector:Selector ::= Variable ; + public void VariableSelector.prettyPrint(PrettyPrinter s) { + getVariable().prettyPrint(s); + } + + // R806 + // EndAssociateStmt:AbstractStmt ::= [Name] ; + public void EndAssociateStmt.prettyPrint(PrettyPrinter s) { + s.append("END ASSOCIATE"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + + // R807 + // BlockConstruct:ExecutableConstruct ::= BlockStmt [SpecificationPart] Block EndBlockStmt ; + public void BlockConstruct.prettyPrint(PrettyPrinter s) { + getBlockStmt().prettyPrint(s); + s.ind(); + if (hasSpecificationPart()) { + getSpecificationPart().prettyPrint(s); + } + getBlock().prettyPrint(s); + s.und(); + getEndBlockStmt().prettyPrint(s); + } + + // R808 + // BlockStmt:AbstractStmt ::= [Name] ; + public void BlockStmt.prettyPrint(PrettyPrinter s) { + if (hasName()) { + getName().prettyPrint(s); + s.append(": "); + } + s.append("BLOCK"); + s.lb(); + } + + // R809 + // EndBlockStmt:AbstractStmt ::= [Name] ; + public void EndBlockStmt.prettyPrint(PrettyPrinter s) { + s.append("END BLOCK"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + + // R810 + // CriticalConstruct:ExecutableConstruct ::= CriticalStmt Block EndCriticalStmt ; + public void CriticalConstruct.prettyPrint(PrettyPrinter s) { + getCriticalStmt().prettyPrint(s); + s.ind(); + getBlock().prettyPrint(s); + s.und(); + getEndCriticalStmt().prettyPrint(s); + } + + // R811 + // CriticalStmt:AbstractStmt ::= [Name] ; + public void CriticalStmt.prettyPrint(PrettyPrinter s) { + if (hasName()) { + getName().prettyPrint(s); + s.append(": "); + } + s.append("CRITICAL"); + s.lb(); + } + + // R812 + // EndCriticalStmt:AbstractStmt ::= [Name] ; + public void EndCriticalStmt.prettyPrint(PrettyPrinter s) { + s.append("END CRITICAL"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + + // R813 + // abstract DoConstruct:ExecutableConstruct ; + // R814 public void SimpleDoConstruct.prettyPrint(PrettyPrinter s) { getDoStmt().prettyPrint(s); @@ -2967,7 +3114,7 @@ class PrettyPrint { getLower().prettyPrint(s); s.append(","); getUpper().prettyPrint(s); - if (hasStep()) { + if (hasStep() && !"1".equals(getStep().prettyPrint())) { s.append(","); getStep().prettyPrint(s); } @@ -3001,6 +3148,17 @@ class PrettyPrint { getContinueStmt().prettyPrint(s); } + // R831 + // CycleStmt:ActionStmt ::= [Name] ; + public void CycleStmt.prettyPrint(PrettyPrinter s) { + s.append("CYCLE"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + // R832 public void IfConstruct.prettyPrint(PrettyPrinter s) { boolean first = true; @@ -3030,10 +3188,19 @@ class PrettyPrint { } getEndIfStmt().prettyPrint(s); } - -// public void IfBlock.prettyPrint(PrettyPrinter s) { -// // TODO -// } + // IfBlock ::= [Name] Expr Block ; + // ElseBlock ::= [Name] Block ; + public void ElseBlock.prettyPrint(PrettyPrinter s) { + s.append("ELSE"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + s.ind(); + getBlock().prettyPrint(s); + s.und(); + } // R836 public void EndIfStmt.prettyPrint(PrettyPrinter s) { @@ -3054,11 +3221,238 @@ class PrettyPrint { getActionStmt().prettyPrint(s); } + // R838 + // CaseConstruct:ExecutableConstruct ::= SelectCaseStmt CaseBlock* EndSelectStmt ; + public void CaseConstruct.prettyPrint(PrettyPrinter s) { + getSelectCaseStmt().prettyPrint(s); + s.ind(); + getCaseBlockList().prettyPrintJoin(s, ""); + s.und(); + getEndSelectStmt().prettyPrint(s); + } + // CaseBlock ::= CaseStmt Block ; + public void CaseBlock.prettyPrint(PrettyPrinter s) { + getCaseStmt().prettyPrint(s); + s.ind(); + getBlock().prettyPrint(s); + s.und(); + } + + // R839 + // SelectCaseStmt:AbstractStmt ::= [Name] Expr ; + public void SelectCaseStmt.prettyPrint(PrettyPrinter s) { + if (hasName()) { + getName().prettyPrint(s); + s.append(":"); + } + s.append("SELECT CASE "); + s.append("("); + getExpr().prettyPrint(s); + s.append(")"); + getComment().prettyPrint(s); + } + + /// R840 + // CaseStmt:AbstractStmt ::= CaseSelector [Name] ; + public void CaseStmt.prettyPrint(PrettyPrinter s) { + s.append("CASE "); + getCaseSelector().prettyPrint(s); + + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + getComment().prettyPrint(s); + } + + // R841 + // EndSelectStmt:AbstractStmt ::= [Name] ; + public void EndSelectStmt.prettyPrint(PrettyPrinter s) { + s.append("END SELECT"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + getComment().prettyPrint(s); + } + + // R842 + // SIMPLIFY: rule omitted and occurrences replaced by Expr + + // R843 + // abstract CaseSelector ; + // DefaultCaseSelector:CaseSelector ; + // ValueCaseSelector:CaseSelector ::= CaseValueRange* ; + public void DefaultCaseSelector.prettyPrint(PrettyPrinter s) { + s.append("DEFAULT"); + } + public void ValueCaseSelector.prettyPrint(PrettyPrinter s) { + s.append("("); + getCaseValueRangeList().prettyPrintJoin(s, ", "); + s.append(")"); + } + + // R844 + // abstract CaseValueRange ; + // SimpleCaseValueRange:CaseValueRange ::= CaseValue ; + // RangeCaseValueRange:CaseValueRange ::= [Lower:CaseValue] [Upper:CaseValue] ; + public void SimpleCaseValueRange.prettyPrint(PrettyPrinter s) { + getCaseValue().prettyPrint(s); + } + public void RangeCaseValueRange.prettyPrint(PrettyPrinter s) { + if (hasLower()) { + getLower().prettyPrint(s); + } + s.append(":"); + if (hasUpper()) { + getUpper().prettyPrint(s); + } + } + + // R845 + // CaseValue ::= Expr ; + public void CaseValue.prettyPrint(PrettyPrinter s) { + getExpr().prettyPrint(s); + } + + // R846 + // SelectTypeConstruct:ExecutableConstruct ::= SelectTypeStmt TypeGuardBlock* EndSelectTypeStmt ; + public void SelectTypeConstruct.prettyPrint(PrettyPrinter s) { + getSelectTypeStmt().prettyPrint(s); + s.ind(); + getTypeGuardBlockList().prettyPrintJoin(s, ""); + s.und(); + getEndSelectTypeStmt().prettyPrint(s); + } + // TypeGuardBlock ::= TypeGuardStmt Block ; + public void TypeGuardBlock.prettyPrint(PrettyPrinter s) { + getTypeGuardStmt().prettyPrint(s); + s.ind(); + getBlock().prettyPrint(s); + s.und(); + } + + // R847 + // SelectTypeStmt:AbstractStmt ::= [Name] [AssociateName:Name] Selector ; + public void SelectTypeStmt.prettyPrint(PrettyPrinter s) { + if (hasName()) { + getName().prettyPrint(s); + s.append(": "); + } + s.append("SELECT TYPE("); + if (hasAssociateName()) { + getAssociateName().prettyPrint(s); + } + s.append(") "); + getSelector().prettyPrint(s); + s.lb(); + } + + // R848 + // abstract TypeGuardStmt:AbstractStmt ; + // TypeTypeGuardStmt:TypeGuardStmt ::= TypeSpec [Name] ; + public void TypeTypeGuardStmt.prettyPrint(PrettyPrinter s) { + s.append("TYPE IS ("); + getTypeSpec().prettyPrint(s); + s.append(")"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + // ClassTypeGuardStmt:TypeGuardStmt ::= DerivedTypeSpec [Name] ; + public void ClassTypeGuardStmt.prettyPrint(PrettyPrinter s) { + s.append("CLASS IS ("); + getDerivedTypeSpec().prettyPrint(s); + s.append(")"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + // DefaultTypeGuardStmt:TypeGuardStmt ::= [Name] ; + public void DefaultTypeGuardStmt.prettyPrint(PrettyPrinter s) { + s.append("CLASS DEFAULT"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + + // R849 + // EndSelectTypeStmt:AbstractStmt ::= [Name] ; + public void EndSelectTypeStmt.prettyPrint(PrettyPrinter s) { + s.append("END SELECT"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + + // R850 + // ExitStmt:ActionStmt ::= [Name] ; + public void ExitStmt.prettyPrint(PrettyPrinter s) { + s.append("EXIT"); + if (hasName()) { + s.append(" "); + getName().prettyPrint(s); + } + s.lb(); + } + + // R851 + // GotoStmt:ActionStmt ::= GotoLabel:Label ; + public void GotoStmt.prettyPrint(PrettyPrinter s) { + s.append("GO TO "); + getGotoLabel().prettyPrint(s); + s.lb(); + } + + // R852 + // ComputedGotoStmt:ActionStmt ::= GotoLabel:Label* Expr ; + public void ComputedGotoStmt.prettyPrint(PrettyPrinter s) { + s.append("GO TO ("); + getGotoLabelList().prettyPrintJoin(s, ", "); + s.append("), "); + getExpr().prettyPrint(s); + s.lb(); + } + // R854 public void ContinueStmt.prettyPrint(PrettyPrinter s) { s.append("CONTINUE"); getComment().prettyPrint(s); } + + // R855 + public void StopStmt.prettyPrint(PrettyPrinter s) { + s.append("STOP"); + if (hasStopCode()) { + s.append(" "); + getStopCode().prettyPrint(s); + } + getComment().prettyPrint(s); + } + + // R856 + public void ErrorStopStmt.prettyPrint(PrettyPrinter s) { + s.append("ERROR STOP"); + if (hasStopCode()) { + s.append(" "); + getStopCode().prettyPrint(s); + } + getComment().prettyPrint(s); + } + + // R857 + public void StopCode.prettyPrint(PrettyPrinter s) { + getExpr().prettyPrint(s); + } + // ============================================================================= // Clause 9 // ============================================================================= @@ -3431,6 +3825,389 @@ class PrettyPrint { } } + +// ============================================================================= +// Clause 10 +// ============================================================================= + + // R1001 + // FormatStmt:AbstractStmt ::= FormatSpecification ; + public void FormatStmt.prettyPrint(PrettyPrinter s) { + if (hasLabel()) { + getLabel().prettyPrint(s); + s.append(" "); + } + s.append("format "); + getFormatSpecification().prettyPrint(s); + s.lb(); + } + + // R1002 + // FormatSpecification ::= [FormatItems] [UnlimitedFormatItem] ; + public void FormatSpecification.prettyPrint(PrettyPrinter s) { + s.append("("); + if (hasFormatItems()) { + getFormatItems().prettyPrint(s); + if (hasUnlimitedFormatItem()) { + s.append(", "); + } + } + if (hasUnlimitedFormatItem()) { + getUnlimitedFormatItem().prettyPrint(s); + } + s.append(")"); + } + + + // R1003 + // FormatItems ::= FormatItem* ; + public void FormatItems.prettyPrint(PrettyPrinter s) { + getFormatItemList().prettyPrintJoin(s, ", "); + } + + // R1004 + // abstract FormatItem ; + // DataEditDescFormatItem:FormatItem ::= [R] DataEditDesc ; + public void DataEditDescFormatItem.prettyPrint(PrettyPrinter s) { + if (hasR()) { + getR().prettyPrint(s); + s.append(" "); + } + getDataEditDesc().prettyPrint(s); + } + // ControlEditDescFormatItem:FormatItem ::= ControlEditDesc ; + public void ControlEditDescFormatItem.prettyPrint(PrettyPrinter s) { + getControlEditDesc().prettyPrint(s); + } + // CharStringEditDescFormatItem:FormatItem ::= CharStringEditDesc ; + public void CharStringEditDescFormatItem.prettyPrint(PrettyPrinter s) { + getCharStringEditDesc().prettyPrint(s); + } + // ParenthesizedFormatItem:FormatItem ::= [R] FormatItems ; + public void ParenthesizedFormatItem.prettyPrint(PrettyPrinter s) { + if (hasR()) { + getR().prettyPrint(s); + s.append(" "); + } + s.append("("); + getFormatItems().prettyPrint(s); + s.append(")"); + } + + // R1005 + // UnlimitedFormatItem ::= FormatItems ; + public void UnlimitedFormatItem.prettyPrint(PrettyPrinter s) { + s.append("* "); + s.append("("); + getFormatItems().prettyPrint(s); + s.append(")"); + } + + // R1006 + // R ::= IntLiteralConstant ; + public void R.prettyPrint(PrettyPrinter s) { + getIntLiteralConstant().prettyPrint(s); + } + + // R1007 + // abstract DataEditDesc ; + // IDataEditDesc:DataEditDesc ::= W [M] ; + public void IDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("I"); + getW().prettyPrint(s); + if (hasM()) { + s.append("."); + getM().prettyPrint(s); + } + } + // BDataEditDesc:DataEditDesc ::= W [M] ; + public void BDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("B"); + getW().prettyPrint(s); + if (hasM()) { + s.append("."); + getM().prettyPrint(s); + } + } + // ODataEditDesc:DataEditDesc ::= W [M] ; + public void ODataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("O"); + getW().prettyPrint(s); + if (hasM()) { + s.append("."); + getM().prettyPrint(s); + } + } + // ZDataEditDesc:DataEditDesc ::= W [M] ; + public void ZDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("Z"); + getW().prettyPrint(s); + if (hasM()) { + s.append("."); + getM().prettyPrint(s); + } + } + // FDataEditDesc:DataEditDesc ::= W D ; + public void FDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("F"); + getW().prettyPrint(s); + s.append("."); + getD().prettyPrint(s); + } + // EDataEditDesc:DataEditDesc ::= W D [E] ; + public void EDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("E"); + getW().prettyPrint(s); + s.append("."); + getD().prettyPrint(s); + if (hasE()) { + s.append("E"); + getE().prettyPrint(s); + } + } + // ENDataEditDesc:DataEditDesc ::= W D [E] ; + public void ENDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("EN"); + getW().prettyPrint(s); + s.append("."); + getD().prettyPrint(s); + if (hasE()) { + s.append("E"); + getE().prettyPrint(s); + } + } + // ESDataEditDesc:DataEditDesc ::= W D [E] ; + public void ESDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("ES"); + getW().prettyPrint(s); + s.append("."); + getD().prettyPrint(s); + if (hasE()) { + s.append("E"); + getE().prettyPrint(s); + } + } + // GDataEditDesc:DataEditDesc ::= W [D] [E] ; + public void GDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("G"); + getW().prettyPrint(s); + if (hasD()) { + s.append("."); + getD().prettyPrint(s); + if (hasE()) { + s.append("E"); + getE().prettyPrint(s); + } + } + } + // LDataEditDesc:DataEditDesc ::= W ; + public void LDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("L"); + getW().prettyPrint(s); + } + // ADataEditDesc:DataEditDesc ::= [W] ; + public void ADataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("A"); + if (hasW()) { + getW().prettyPrint(s); + } + } + // DDataEditDesc:DataEditDesc ::= W D ; + public void DDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("D"); + getW().prettyPrint(s); + s.append("."); + getD().prettyPrint(s); + } + // DTDataEditDesc:DataEditDesc ::= [CharLiteralConstant] V* ; + public void DTDataEditDesc.prettyPrint(PrettyPrinter s) { + s.append("DT"); + if (hasCharLiteralConstant()) { + getCharLiteralConstant().prettyPrint(s); + } + if (getVList().numChildren() > 0) { + s.append("("); + getVList().prettyPrintJoin(s, ", "); + s.append(")"); + } + } + + // R1008 + // W ::= IntLiteralConstant ; + public void W.prettyPrint(PrettyPrinter s) { + getIntLiteralConstant().prettyPrint(s); + } + + // R1009 + // M ::= IntLiteralConstant ; + public void M.prettyPrint(PrettyPrinter s) { + getIntLiteralConstant().prettyPrint(s); + } + + // R1010 + // D ::= IntLiteralConstant ; + public void D.prettyPrint(PrettyPrinter s) { + getIntLiteralConstant().prettyPrint(s); + } + + // R1011 + // E ::= IntLiteralConstant ; + public void E.prettyPrint(PrettyPrinter s) { + getIntLiteralConstant().prettyPrint(s); + } + + // R1012 + // V ::= SignedIntLiteralConstant ; + public void V.prettyPrint(PrettyPrinter s) { + getSignedIntLiteralConstant().prettyPrint(s); + } + + // R1013 + // abstract ControlEditDesc ; + // PositionControlEditDesc:ControlEditDesc ::= PositionEditDesc ; + public void PositionControlEditDesc.prettyPrint(PrettyPrinter s) { + getPositionEditDesc().prettyPrint(s); + } + // SlashControlEditDesc:ControlEditDesc ::= [R] ; + public void SlashControlEditDesc.prettyPrint(PrettyPrinter s) { + if (hasR()) { + getR().prettyPrint(s); + s.append(" "); + } + s.append ("/"); + } + // ColonControlEditDesc:ControlEditDesc ; + public void ColonControlEditDesc.prettyPrint(PrettyPrinter s) { + s.append(":"); + } + // SignControlEditDesc:ControlEditDesc ::= SignEditDesc ; + public void SignControlEditDesc.prettyPrint(PrettyPrinter s) { + getSignEditDesc().prettyPrint(s); + } + // PControlEditDesc:ControlEditDesc ::= K ; + public void PControlEditDesc.prettyPrint(PrettyPrinter s) { + getK().prettyPrint(s); + s.append (" P"); + } + // BlankInterpControlEditDesc:ControlEditDesc ::= BlankInterpEditDesc ; + public void BlankInterpControlEditDesc.prettyPrint(PrettyPrinter s) { + getBlankInterpEditDesc().prettyPrint(s); + } + // RoundControlEditDesc:ControlEditDesc ::= RoundEditDesc ; + public void RoundControlEditDesc.prettyPrint(PrettyPrinter s) { + getRoundEditDesc().prettyPrint(s); + } + // DecimalControlEditDesc:ControlEditDesc ::= DecimalEditDesc ; + public void DecimalControlEditDesc.prettyPrint(PrettyPrinter s) { + getDecimalEditDesc().prettyPrint(s); + } + + // R1014 + // K ::= SignedIntLiteralConstant ; + public void K.prettyPrint(PrettyPrinter s) { + getSignedIntLiteralConstant().prettyPrint(s); + } + + // R1015 + // abstract PositionEditDesc ::= N; + // TPositionEditDesc:PositionEditDesc; + public void TPositionEditDesc.prettyPrint(PrettyPrinter s) { + s.append("T "); + getN().prettyPrint(s); + } + // TLPositionEditDesc:PositionEditDesc; + public void TLPositionEditDesc.prettyPrint(PrettyPrinter s) { + s.append("TL "); + getN().prettyPrint(s); + } + // TRPositionEditDesc:PositionEditDesc; + public void TRPositionEditDesc.prettyPrint(PrettyPrinter s) { + s.append("TR "); + getN().prettyPrint(s); + } + // XPositionEditDesc:PositionEditDesc; + public void XPositionEditDesc.prettyPrint(PrettyPrinter s) { + getN().prettyPrint(s); + s.append(" X"); + } + + // R1016 + // N ::= IntLiteralConstant ; + public void N.prettyPrint(PrettyPrinter s) { + getIntLiteralConstant().prettyPrint(s); + } + + // R1017 + // abstract SignEditDesc ; + // SSSignEditDesc:SignEditDesc ; + public void SSSignEditDesc.prettyPrint(PrettyPrinter s) { + s.append("SS"); + } + // SPSignEditDesc:SignEditDesc ; + public void SPSignEditDesc.prettyPrint(PrettyPrinter s) { + s.append("SP"); + } + // SSignEditDesc:SignEditDesc ; + public void SSignEditDesc.prettyPrint(PrettyPrinter s) { + s.append("S"); + } + + // R1018 + // abstract BlankInterpEditDesc ; + // BNBlankInterpEditDesc:BlankInterpEditDesc ; + public void BNBlankInterpEditDesc.prettyPrint(PrettyPrinter s) { + s.append("BN"); + } + // BZBlankInterpEditDesc:BlankInterpEditDesc ; + public void BZBlankInterpEditDesc.prettyPrint(PrettyPrinter s) { + s.append("BZ"); + } + + // R1019 + // abstract RoundEditDesc ; + // RURoundEditDesc:RoundEditDesc ; + public void RURoundEditDesc.prettyPrint(PrettyPrinter s) { + s.append("RU"); + } + // RDRoundEditDesc:RoundEditDesc ; + public void RDRoundEditDesc.prettyPrint(PrettyPrinter s) { + s.append("RD"); + } + // RZRoundEditDesc:RoundEditDesc ; + public void RZRoundEditDesc.prettyPrint(PrettyPrinter s) { + s.append("RZ"); + } + // RNRoundEditDesc:RoundEditDesc ; + public void RNRoundEditDesc.prettyPrint(PrettyPrinter s) { + s.append("RN"); + } + // RCRoundEditDesc:RoundEditDesc ; + public void RCRoundEditDesc.prettyPrint(PrettyPrinter s) { + s.append("RC"); + } + // RPRoundEditDesc:RoundEditDesc ; + public void RPRoundEditDesc.prettyPrint(PrettyPrinter s) { + s.append("RP"); + } + + // R1020 + // abstract DecimalEditDesc ; + // DCDecimalEditDesc:DecimalEditDesc ; + public void DCDecimalEditDesc.prettyPrint(PrettyPrinter s) { + s.append("DC"); + } + + // DPDecimalEditDesc:DecimalEditDesc ; + public void DPDecimalEditDesc.prettyPrint(PrettyPrinter s) { + s.append("DP"); + } + + // R1021 + // CharStringEditDesc ::= CharLiteralConstant ; + public void CharStringEditDesc.prettyPrint(PrettyPrinter s) { + getCharLiteralConstant().prettyPrint(s); + } + // ============================================================================= // Clause 11 // ============================================================================= @@ -3452,6 +4229,7 @@ class PrettyPrint { } s.und(); getEndProgramStmt().prettyPrint(s); + getPostambleList().prettyPrintJoin(s, ""); } // R1102 @@ -3484,6 +4262,7 @@ class PrettyPrint { } s.und(); getEndModuleStmt().prettyPrint(s); + getPostambleList().prettyPrintJoin(s, ""); } // R1105 @@ -3526,6 +4305,10 @@ class PrettyPrint { public void SeparateModuleModuleSubprogram.prettyPrint(PrettyPrinter s) { getSeparateModuleSubprogram().prettyPrint(s); } + // CommentModuleSubprogram:ModuleSubprogram ::= SeparateModuleSubprogram ; + public void CommentModuleSubprogram.prettyPrint(PrettyPrinter s) { + getComment().prettyPrint(s); + } // R1109 // UseStmt ::= [ModuleNature] Name Rename* <IsOnly:Boolean> Only* ; @@ -3596,6 +4379,7 @@ class PrettyPrint { } s.und(); getEndBlockDataStmt().prettyPrint(s); + getPostambleList().prettyPrintJoin(s, ""); } // R1121 @@ -3628,7 +4412,9 @@ class PrettyPrint { // InterfaceBlock ::= InterfaceStmt InterfaceSpecification* EndInterfaceStmt ; public void InterfaceBlock.prettyPrint(PrettyPrinter s) { getInterfaceStmt().prettyPrint(s); + s.ind(); getInterfaceSpecificationList().prettyPrintJoin(s, ""); + s.und(); getEndInterfaceStmt().prettyPrint(s); } @@ -3695,11 +4481,14 @@ class PrettyPrint { // ProcedureStmt:AbstractStmt ::= <Module:Boolean> Name* ; public void ProcedureStmt.prettyPrint(PrettyPrinter s) { if (getModule()) { - s.append("module "); + s.append("MODULE "); } - s.append("procedure"); + s.append("PROCEDURE"); +// if (s.useColons()) { +// s.append("::"); +// } + s.append(" "); if (getNameList().numChildren() > 0) { - s.append (" :: "); getNameList().prettyPrintJoin(s, ", "); } getComment().prettyPrint(s); diff --git a/Parser/spec/SlotPrinting.jadd b/Parser/spec/SlotPrinting.jadd index cbb7af883a1e671edc2043365981b513f02cb3ea..7769a90314dd90db9e3dc85c4275ee77c88e8bda 100644 --- a/Parser/spec/SlotPrinting.jadd +++ b/Parser/spec/SlotPrinting.jadd @@ -1,38 +1,52 @@ aspect Printing { - // abstract Slot ::= SlotName ; - // SlotName ::= <String> ; - // SlotExpr:Expr ::= ExprSlot ; - // ExprSlot:Slot ; - - public void SlotName.prettyPrint(PrettyPrinter s) { - s.append(getString()); - } - - public void Slot.prettyPrint(PrettyPrinter s) { + public void SlotExpr.prettyPrint(PrettyPrinter s) { s.append("#"); - getSlotName().prettyPrint(s); + s.append(getSlotName()); s.append("#"); } - public void SlotExpr.prettyPrint(PrettyPrinter s) { - getExprSlot().prettyPrint(s); + public void SlotIntLiteralConstant.prettyPrint(PrettyPrinter s) { + s.append("#"); + s.append(getSlotName()); + s.append("#"); } - public void SlotIntLiteralConstant.prettyPrint(PrettyPrinter s) { - getIntLiteralConstantSlot().prettyPrint(s); + public void SlotBlock.prettyPrint(PrettyPrinter s) { + s.append("#"); + s.append(getSlotName()); + s.append("#"); + s.lb(); } public void SlotVariable.prettyPrint(PrettyPrinter s) { - getVariableSlot().prettyPrint(s); + s.append("#"); + s.append(getSlotName()); + s.append("#"); + } + + public void SlotDoConstruct.prettyPrint(PrettyPrinter s) { + s.append("#"); + s.append(getSlotName()); + s.append("#"); } public void SlotExecutableConstruct.prettyPrint(PrettyPrinter s) { - getExecutableConstructSlot().prettyPrint(s); + s.append("#"); + s.append(getSlotName()); + s.append("#"); + s.lb(); + } + public void SlotExecutionPartConstruct.prettyPrint(PrettyPrinter s) { + s.append("#"); + s.append(getSlotName()); + s.append("#"); s.lb(); } public void SlotForName.prettyPrint(PrettyPrinter s) { - getNameSlot().prettyPrint(s); + s.append("#"); + s.append(getString()); + s.append("#"); } } \ No newline at end of file diff --git a/Parser/spec/SlottableFortranParser.rats b/Parser/spec/SlottableFortranParser.rats index b963d6b014f0ee59ac53b91c46aac9752f7ea540..f3cf1fff694a38c7187984fedd8f71ecb3f5ffc2 100644 --- a/Parser/spec/SlottableFortranParser.rats +++ b/Parser/spec/SlottableFortranParser.rats @@ -19,55 +19,158 @@ body { { sb.append(line).append("\n"); } - System.out.println(preProcess(sb.toString())); - StringReader processedReader = new StringReader(preProcess(sb.toString())); + StringReader processedReader = new StringReader(removeLineBreaks(sb.toString())); return new SlottableFortranParser(processedReader, file); } - private static String preProcess(String content) { - String text = ""; + private enum State { + Normal,Error,SChar,DChar,ComAmbi,Pragma,Comment,Cont,ContStart,ContSpace,ContAmbi,ContCom,ContPrag,ContinuedSCharBeginning,ContinuedSCharEnd,ContinuedDCharBeginning,ContinuedDCharEnd; + static public final Integer length = 1 + ContinuedDCharEnd.ordinal(); + } - boolean continuedPragma = false; - boolean previousContinuedPragma = false; + public static class SuccessorState { - boolean continued = false; - boolean previousContinued = false; + private final State state; + private final Character replacement; + private final boolean keep; - for (String line : content.split("\n")) { - previousContinuedPragma = continuedPragma; - continuedPragma = false; + public SuccessorState(State state) { + this.state = state; + this.replacement = null; + this.keep = true; + } - previousContinued = continued; - continued = false; + public SuccessorState(State state, boolean keep) { + this.state = state; + this.replacement = null; + this.keep = keep; + } - line = trimRight(line); - if (line.startsWith("!$")) { - if (line.endsWith(" &")) { - continuedPragma = true; - line = trimRight(line.substring(0, line.length() - 2)) + " "; - } else { - line = line + "\n"; - } - } else if (line.startsWith("!")) { - line = line + "\n"; - } else { - if (line.endsWith(" &")) { - continued = true; - line = trimRight(line.substring(0, line.length() - 2)) + " "; + public SuccessorState(State state, Character replacement) { + this.state = state; + this.replacement = replacement; + this.keep = true; + } + + public State getState() { + return state; + } + + public Character getReplacement() { + return replacement; + } + + public boolean getKeep() { + return keep; + } + } + + + public static String removeLineBreaks(String content) { + + // state,character + SuccessorState table[][] = new SuccessorState[State.length][256]; + + int s = State.Normal.ordinal(); + table[s][0] = new SuccessorState(State.Normal); + table[s]['!'] = new SuccessorState(State.ComAmbi); + table[s]['\"'] = new SuccessorState(State.DChar); + table[s]['\''] = new SuccessorState(State.SChar); + table[s]['&'] = new SuccessorState(State.Cont, false); + table[s][';'] = new SuccessorState(State.Normal, '\n'); + + s = State.ComAmbi.ordinal(); + table[s][0] = new SuccessorState(State.Comment); + table[s]['$'] = new SuccessorState(State.Pragma); + + s = State.Pragma.ordinal(); + table[s][0] = new SuccessorState(State.Pragma); + table[s]['\n'] = new SuccessorState(State.Normal); + table[s]['&'] = new SuccessorState(State.Cont, false); + + s = State.Comment.ordinal(); + table[s][0] = new SuccessorState(State.Comment); + table[s]['\n'] = new SuccessorState(State.Normal); + + s = State.SChar.ordinal(); + table[s][0] = new SuccessorState(State.SChar); + table[s]['\''] = new SuccessorState(State.Normal); + table[s]['&'] = new SuccessorState(State.ContinuedSCharBeginning, false); + + s = State.DChar.ordinal(); + table[s][0] = new SuccessorState(State.DChar); + table[s]['\"'] = new SuccessorState(State.Normal); + table[s]['&'] = new SuccessorState(State.ContinuedDCharBeginning, false); + + s = State.Cont.ordinal(); + table[s][0] = new SuccessorState(State.Cont, false); + table[s]['\n'] = new SuccessorState(State.ContStart, false); + + s = State.ContStart.ordinal(); + table[s][0] = new SuccessorState(State.Normal); + table[s]['\n'] = new SuccessorState(State.ContStart, false); + table[s]['\t'] = new SuccessorState(State.ContStart); + table[s][' '] = new SuccessorState(State.ContStart); + table[s]['!'] = new SuccessorState(State.ContAmbi, false); + + + s = State.ContAmbi.ordinal(); + table[s][0] = new SuccessorState(State.ContCom, false); + table[s]['$'] = new SuccessorState(State.ContPrag, false); + table[s]['\n'] = new SuccessorState(State.ContStart, false); + + s = State.ContCom.ordinal(); + table[s][0] = new SuccessorState(State.ContCom, false); + table[s]['\n'] = new SuccessorState(State.ContStart, false); + + s = State.ContPrag.ordinal(); + table[s][0] = new SuccessorState(State.ContPrag, false); + table[s][' '] = new SuccessorState(State.Normal); + table[s]['&'] = new SuccessorState(State.Normal, ' '); + + s = State.ContinuedSCharBeginning.ordinal(); + table[s][0] = new SuccessorState(State.ContinuedSCharBeginning, false); + table[s]['\n'] = new SuccessorState(State.ContinuedSCharEnd, false); + + s = State.ContinuedDCharBeginning.ordinal(); + table[s][0] = new SuccessorState(State.ContinuedDCharBeginning, false); + table[s]['\n'] = new SuccessorState(State.ContinuedDCharEnd, false); + + s = State.ContinuedSCharEnd.ordinal(); + table[s][0] = new SuccessorState(State.ContinuedSCharEnd, false); + table[s][' '] = new SuccessorState(State.ContinuedSCharEnd, false); + table[s]['\t'] = new SuccessorState(State.ContinuedSCharEnd, false); + table[s]['&'] = new SuccessorState(State.SChar, false); + + s = State.ContinuedDCharEnd.ordinal(); + table[s][0] = new SuccessorState(State.ContinuedSCharEnd, false); + table[s][' '] = new SuccessorState(State.ContinuedDCharEnd, false); + table[s]['\t'] = new SuccessorState(State.ContinuedDCharEnd, false); + table[s]['&'] = new SuccessorState(State.DChar, false); + + State state = State.Normal; + StringBuilder r = new StringBuilder(); + for (char c: content.toCharArray()) { + if (c > 255) { + c = 0; + } + SuccessorState t = table[state.ordinal()][c]; + if (t == null) { + t = table[state.ordinal()][0]; + } + state = t.getState(); + if (t.getKeep()) { + Character replacement = t.getReplacement(); + if (replacement == null) { + r.append(c); } else { - line = line + "\n"; + r.append(replacement); } } - - if (previousContinuedPragma) { - line = trimLeft(line.replaceFirst("!\\$\\w+& ", "")); - } else if (previousContinued) { - line = trimLeft(line); - } - text = text + line; } - return text; + + return r.toString(); } private static String trimRight(String s) { @@ -88,116 +191,116 @@ body { // lift invisibility of potential fragments to public public Expr expr := ... ; public ExecutableConstruct executable_construct := ... ; +public ExecutionPartConstruct execution_part_construct := ... ; public Name name := ... ; +public Block block := ... ; +public DoConstruct do_construct := ... ; // == Slots ==================================================================== transient void NUMBERSIGN = "#"; -//// abstract Slot ::= SlotName ; - -//// SlotName ::= <String> ; -SlotName slot_name = - l:LETTERS - { - yyValue = new SlotName(l); - } +String slot_name = + yyValue:LETTERS ; // == Expression Slots ========================================================= -//// SlotExpr:Expr ::= ExprSlot ; +//// SlotExpr:Expr ::= <SlotName:String> ; Expr expr += - <ExprSlot> s:expr_slot + <ExprSlot> NUMBERSIGN n:slot_name (COLON E X P R)? NUMBERSIGN { - yyValue = new SlotExpr(s); + yyValue = new SlotExpr(n); } / <BEGINNING> ... ; -//// ExprSlot:Slot ; -ExprSlot expr_slot = - NUMBERSIGN n:slot_name NUMBERSIGN + +// == DoConstruct Slots ========================================================= + +//// SlotDoConstruct:DoConstruct ::= <SlotName:String> ; +DoConstruct do_construct += + <ExprSlot> NUMBERSIGN n:slot_name (COLON (D O C O N S T R U C T / S I M P L E D O C O N S T R U C T / O M P D O C O N S T R U C T / A C C L O O P C O N S T R U C T))? NUMBERSIGN LB { - yyValue = new ExprSlot(n); + yyValue = new SlotDoConstruct(n); } +/ <BEGINNING> ... ; -// == Variable Slots =========================================================== +// == Block Slots =========================================================== -//// SlotVariable:Variable ::= VariableSlot ; -Variable variable += - <VariableSlot> s:variable_slot +//// SlotBlock:Block ::= <SlotName:String> ; +Block block += + <BlockSlot> NUMBERSIGN n:slot_name (COLON B L O C K)? NUMBERSIGN LB { - yyValue = new SlotVariable(s); + yyValue = new SlotBlock(new List(), n); } / <BEGINNING> ... ; -//// VariableSlot:Slot ; -VariableSlot variable_slot = - NUMBERSIGN n:slot_name NUMBERSIGN +// == Variable Slots =========================================================== + +//// SlotVariable:Variable ::= <SlotName:String> ; +Variable variable += + <VariableSlot> NUMBERSIGN n:slot_name (COLON V A R I A B L E)? NUMBERSIGN { - yyValue = new VariableSlot(n); + yyValue = new SlotVariable(n); } +/ <BEGINNING> ... ; - // == Int Literal Slots ======================================================== -//// SlotIntLiteralConstant:IntLiteralConstant ::= IntLiteralConstantSlot ; +//// SlotIntLiteralConstant:IntLiteralConstant ::= <SlotName:String> ; IntLiteralConstant int_literal_constant += - <IntLiteralConstantSlot> s:int_literal_constant_slot + <IntLiteralConstantSlot> NUMBERSIGN n:slot_name (COLON I N T L I T E R A L C O N S T A N T)? NUMBERSIGN { - yyValue = new SlotIntLiteralConstant(new DigitString(""), new Opt<KindParam>(), s); + yyValue = new SlotIntLiteralConstant(new DigitString(""), new Opt<KindParam>(), n); } / <BEGINNING> ... ; -//// IntLiteralConstantSlot:Slot ; -IntLiteralConstantSlot int_literal_constant_slot = - NUMBERSIGN n:slot_name NUMBERSIGN SS - { - yyValue = new IntLiteralConstantSlot(n); - } -; - -// == Action Statement Slots =================================================== +// == Executable Construct Slots =================================================== -//// SlotExecutableConstruct:ExecutableConstruct ::= ExecutableConstructSlot ; +//// SlotExecutableConstruct:ExecutableConstruct ::= <SlotName:String> ; ExecutableConstruct executable_construct += - <ExecutableConstructSlot> s:executable_construct_slot + <ExecutableConstructSlot> NUMBERSIGN n:slot_name (COLON (E X E C U T A B L E C O N S T R U C T / A C C P A R A L L E L C O N S T R U C T / A C C D A T A C O N S T R U C T))? NUMBERSIGN LB { - yyValue = new SlotExecutableConstruct(s); + yyValue = new SlotExecutableConstruct(n); } / <BEGINNING> ... ; -//// ExecutableConstructSlot:Slot ; -ExecutableConstructSlot executable_construct_slot = - NUMBERSIGN n:slot_name NUMBERSIGN LB +// == Execution Part Construct Slots =================================================== + +//// SlotExecutionPartConstruct:ExecutionPartConstruct ::= <SlotName:String> ; +ExecutionPartConstruct execution_part_construct += + <ExecutionPartConstructSlot> NUMBERSIGN n:slot_name (COLON E X E C U T I O N P A R T C O N S T R U C T)? NUMBERSIGN LB { - yyValue = new ExecutableConstructSlot(n); + yyValue = new SlotExecutionPartConstruct(n); } +/ <BEGINNING> ... ; // == Name Slots =================================================== -//// SlotForName:Name ::= NameSlot ; +//// SlotForName:Name ; Name name += - <NameSlot> s:name_slot + NUMBERSIGN n:slot_name (COLON F O R N A M E)? NUMBERSIGN SS { - yyValue = new SlotForName("", s); + yyValue = new SlotForName(n); } / <BEGINNING> ... ; -//// NameSlot:Slot ; -NameSlot name_slot = - NUMBERSIGN n:slot_name NUMBERSIGN SS +// ==================================================================== +// LISTS +// ==================================================================== + +public List<ExecutableConstruct> executable_construct_list = + l:executable_construct* { - yyValue = new NameSlot(n); + yyValue = new List<ExecutableConstruct>().addAll(l.list()); } ; -