From 543a30dfcf050c772a5ef5420c821acbfe3cac9f Mon Sep 17 00:00:00 2001 From: hake Date: Fri, 24 Jan 2020 16:53:51 +0100 Subject: fixed some parser bugs,make parser ready for javacc 7.0.5 --- src/vhdljjparser.cpp | 3 +- vhdlparser/vhdlparser.jj | 176 ++++++++++++++++++++++++++++++----------------- vhdlparser/vhdlstring.h | 20 ++++++ 3 files changed, 133 insertions(+), 66 deletions(-) mode change 100644 => 100755 vhdlparser/vhdlparser.jj mode change 100644 => 100755 vhdlparser/vhdlstring.h diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index 23335d9..cddc7c1 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -94,7 +94,8 @@ void VHDLOutlineParser::Private::parseVhdlfile(const char *fileName, vhdlParser=new VhdlParser(tokenManager); vhdlParser->setOutlineParser(thisParser); vhdlParser->setSharedState(&shared); - tokenManager->ReInit(stream,0,vhdlParser); + tokenManager->setLexParser(vhdlParser); + tokenManager->ReInit(stream,0); tokenManager->setErrorHandler(tokErrHandler); VhdlErrorHandler *parserErrHandler=new VhdlErrorHandler(fileName); vhdlParser->setErrorHandler(parserErrHandler); diff --git a/vhdlparser/vhdlparser.jj b/vhdlparser/vhdlparser.jj old mode 100644 new mode 100755 index 7b3f5e7..5ef15ba --- a/vhdlparser/vhdlparser.jj +++ b/vhdlparser/vhdlparser.jj @@ -15,8 +15,10 @@ options { NAMESPACE = "vhdl::parser"; STATIC=false; PARSER_INCLUDES="vhdljjparser.h"; - TOKEN_MANAGER_INCLUDES="VhdlParser.h"; - + TOKEN_MANAGER_INCLUDES="vhdlstring.h"; + // TOKEN_MANAGER_USES_PARSER = true; + TOKEN_MANAGER_SUPER_CLASS = "TokenParser"; + // DEBUG_PARSER = true; //OUTPUT_DIRECTORY = "."; //DEBUG_PARSER=true; //DEBUG_LOOKAHEAD=true; @@ -316,7 +318,7 @@ TOKEN: | < #LETTER: (|) > | < #UPPER_CASE_LETTER: ["A"-"Z"] > | )*["\""](((["_"])*)*)["\""] > - | <#BASE_SPECIFIER:["B","O","X","b","o","x","d","D"]> + | <#BASE_SPECIFIER: ()*(["S","U"])*["B","O","X","b","o","x","d","D"] > | <#STD_LOGIC:["0","1","L","H","X","Z","W","-","l","h","x","z","w"]> | < #DIGIT: ["0"-"9"] > | < #SPECIAL_CHARACTER: ["#","&","'","(",")","*","+",",","-",".","/",":",";","<","=",">","_","|"] > @@ -325,6 +327,7 @@ TOKEN: | < #LOWER_CASE_LETTER: ["a"-"z"] > | < #QUOTE: ["\""] > | |)+ > + | )["'"]) > } @@ -342,6 +345,7 @@ QCString access_type_definition() : tok= str1=subtype_indication() { str=tok->image.c_str(); return str+str1; } } + QCString actual_designator() : {QCString str;Token *t=0;} { @@ -349,11 +353,13 @@ t= { return t->image.c_str(); } | LOOKAHEAD(expression()) str=expression() { return str; } -| - LOOKAHEAD(name()) - str=name() { return str; } + | + str=identifier(){return str;} } + + + QCString actual_parameter_part() : {QCString s;} { @@ -368,6 +374,7 @@ QCString actual_part() : | { return "<>";} | + LOOKAHEAD(name() ) s=name() s1=actual_designator() {s+="(";s+=s1+")";return s;} } @@ -452,12 +459,15 @@ void architecture_statement_part() : {} QCString array_type_definition (): { QCString s;} { - LOOKAHEAD(unconstraint_array_definition()) + LOOKAHEAD( index_constraint() ) + s=constraint_array_definition() {return s;} + | + s=unconstraint_array_definition() {return s;} + +} + - s=unconstraint_array_definition() {return s;} - | s=constraint_array_definition() {return s;} -} QCString assertion() : {QCString s,s1,s2;Token *t=0;Token *t1=0;} { @@ -504,11 +514,11 @@ QCString attribute_designator (): {QCString s;Token *tok=0;} | tok= { return tok->image.c_str(); } } + QCString attribute_name (): {QCString s,s1;} { - s=identifier() s1=name(){ s+="'"+s1; }[LOOKAHEAD(1)s1=expression() {s+"("+s1+")";}] { return s; } -} - + s=identifier() ( | s1=name()) { s+=s1; }[LOOKAHEAD(1)s1=expression() {s+=s1;}] { return s; } + } QCString attribute_specification(): {QCString s,s1,s2;} { @@ -580,7 +590,6 @@ void block_configuration() : {} void block_declarative_item (): {} { subprogram_declaration() -//| subprogram_body() | type_declaration() | subtype_declaration() | constant_declaration() @@ -616,7 +625,7 @@ void block_header() : {} void block_specification() : {} { - name()[LOOKAHEAD(1) index_specification() ] + name() [ index_specification() ] } void block_statement() : {QCString s;} @@ -640,7 +649,7 @@ void block_statement_part() : {} void case_statement() : {QCString s;} { -[ identifier() ] +[ identifier() [] ] s=expression() { QCString ca="case "+s; @@ -674,17 +683,20 @@ QCString character_literal() : {Token *tok=0;} QCString choice() : {QCString s;} { - LOOKAHEAD(discrete_range()) - s=discrete_range(){ return s; } + LOOKAHEAD(simple_expression() direction ()) + s=range() { return s;} | LOOKAHEAD(simple_expression()) s=simple_expression(){ return s; } + | + LOOKAHEAD(discrete_range()) + s=discrete_range(){ return s; } | - LOOKAHEAD(identifier()) - s=identifier(){ return s; } + s=identifier(){ return s; } | { return " others "; } } + QCString choices() : {QCString s,s1;} { s=choice() ( s1=choice(){s+="|";s+=s1;})* { return s; } @@ -788,12 +800,7 @@ component_instantiation_statement() LOOKAHEAD(concurrent_procedure_call_statement()) concurrent_procedure_call_statement() | - /* - catch( ParseException e ) - { - outlineParser()->error_skipto(SEMI_T, "syntax error in declarative item"); - } - */ + } QCString condition() : {QCString s;} @@ -823,13 +830,7 @@ waveform() [ condition() ] } -// ( waveform() < WHEN_T> condition() )* -// waveform() [ condition() ] -//waveform() - // ( LOOKAHEAD( condition() ) - // condition() waveform() )* - //[ condition() ] void configuration_declaration() : {QCString s,s1;} { @@ -888,9 +889,10 @@ QCString constraint_array_definition (): {QCString s,s1;} s=index_constraint() s1=subtype_indication(){ return s+" "+s1;} } + void context_clause (): {} { - (context_item())* + (LOOKAHEAD(3) context_item())* } QCString constraint () :{QCString s;} @@ -906,6 +908,7 @@ void context_item() : {} { library_clause() | use_clause() +| context_ref() } QCString decimal_literal() : {Token *tok=0;} @@ -1085,13 +1088,15 @@ void entity_header() : {} [ { m_sharedState->currP=VhdlDocGen::PORT; } port_clause()] } -QCString entity_name_list() : {QCString s,s1;} +QCString entity_name_list() : {QCString s,s1,s2;} { -(s1=entity_designator() {s+=s1;})+ { return s;} +(s1=entity_designator() ) ( s=entity_designator() { s2+=s; } )* { return s2;} | { return "other";} | {return "all";} } + + QCString entity_specification() : {QCString s,s1;} { s=entity_name_list() s1=entity_class(){ return s+":"+s1;} @@ -1172,6 +1177,9 @@ QCString factor(): {QCString s,s1;} s=primary() [LOOKAHEAD(1) s1=primary(){ s+="**";s+=s1;} ] { return s;} | s=primary(){ s1 = "abs "; return s1+s; } | s=primary(){s1="not ";return s1+s;} +| s=primary(){s1="?? ";return s1;} +| s=logop() s1=primary() { return s;} + } QCString file_declaration() : {QCString s,s1,s2,s3;} @@ -1191,7 +1199,7 @@ QCString file_logical_name(): {QCString s;} QCString file_open_information() : {QCString s,s1,s2;} { - [ s=expression() ] s1=file_logical_name() {s2="open "+s+" is "+s1; return s2; } + [ s=expression() ] [inout_stat()] s1=file_logical_name() {s2="open "+s+" is "+s1; return s2; } } QCString file_type_definition() : {QCString s,s1;} @@ -1278,7 +1286,7 @@ s=identifier() void generate_scheme() : {} { parameter_specification() -| condition() +| [LOOKAHEAD(2) identifier() ] condition() } void generic_clause() : {QCString s;} @@ -1336,7 +1344,7 @@ QCString identifier() : {Token *tok=0;} QCString identifier_list() : {QCString str,str1;} { - str=identifier() ( str1=identifier() {str+=",";str+=str1;})* { return str; } + str=name() ( str1=name() {str+=",";str+=str1;})* { return str; } } void if_statement() : {QCString s,s1;} @@ -1423,8 +1431,9 @@ QCString interface_declaration() : {QCString s,s1;} LOOKAHEAD(5) s=interface_subprogram_declaration() { return s;} - -|interface_package_declaration() { return s;} +| +LOOKAHEAD(5) +interface_package_declaration() { return s;} | LOOKAHEAD(5) s=interface_variable_declaration() { return s;} @@ -1542,7 +1551,7 @@ QCString library_unit() : {QCString s;} LOOKAHEAD(2) primary_unit() { return s; } | secondary_unit() { return s; } -| context_declaration() + } @@ -1614,15 +1623,17 @@ tok= { return tok->image.c_str(); } } - QCString name() : {QCString s,s1;} +QCString name() : {QCString s,s1;} { ( - s=operator_symbol() - | s=identifier()| s=external_name() + s=operator_symbol() [LOOKAHEAD(name_ext1()) s1=name_ext1(){ s+=s1;}] { return s; } + |s=external_name() [LOOKAHEAD(name_ext1()) s1=name_ext1(){ s+=s1;}] { return s; } + | s=identifier() [LOOKAHEAD(name_ext1()) s1=name_ext1(){ s+=s1;}] { return s; } ) - [LOOKAHEAD(name_ext1()) s1=name_ext1(){ s+=s1;}] { return s; } + } + QCString name_ext1() : {QCString s,s1,s2;} { s=name_ext() (LOOKAHEAD(name_ext()) s1=name_ext(){s+=s1;})* { return s;} @@ -1633,22 +1644,22 @@ QCString name_ext1() : {QCString s,s1,s2;} ( LOOKAHEAD() - {s+="'subtype";} + {s+="'subtype"; return s;} | LOOKAHEAD( suffix()) - s1=suffix(){s+=".";s+=s1;} + s1=suffix(){s+=".";s+=s1; return s;} | LOOKAHEAD(test_att_name()) - s1=test_att_name() { s+=s1;} + s1=test_att_name() { s+=s1;return s;} | LOOKAHEAD( discrete_range() ) - s1=discrete_range() {s+="(";s+=s1;s+=")";} + s1=discrete_range() {s+="(";s+=s1;s+=")";return s;} | LOOKAHEAD( "(" expression() ("," expression() )* ")" ) - s1=expression() {s+="(";s+=s1;} (LOOKAHEAD(1) s1=expression(){s+=",";s+=s1;})* { s+=")";} + s1=expression() {s+="(";s+=s1;} (LOOKAHEAD(1) s1=expression(){s+=",";s+=s1;})* { s+=")";return s;} ) - {return s;} + } QCString test_att_name() : {QCString s,s1;} @@ -1666,8 +1677,8 @@ QCString name_ext1() : {QCString s,s1,s2;} QCString next_statement() : {QCString s,s1,s2;Token *t=0;Token *t1=0;} { -[LOOKAHEAD(1) s=identifier() t= ] [ s1=identifier() ] -[LOOKAHEAD(1) t1= s2=condition() ] +[ s=identifier() t= ] [ s1=identifier() ] +[ t1= s2=condition() ] { if(t) s+=":"; FlowChart::addFlowChart(FlowChart::NEXT_NO,"next ",s2.data(),s1.data()); @@ -1726,7 +1737,7 @@ void package_body() : {QCString s;} void package_body_declarative_item() : {} { subprogram_declaration() -//| subprogram_body() + | type_declaration() | subtype_declaration() | constant_declaration() @@ -1745,6 +1756,12 @@ void package_body_declarative_part() : {} (package_body_declarative_item() )* } +void package_header(): {QCString s;} +{ + [ generic_clause() [ generic_map_aspect() ] ] +} + + void package_declaration(): {QCString s;} { @@ -1761,6 +1778,7 @@ void package_declaration(): {QCString s;} m_sharedState->current_root->moveToSubEntryAndKeep(clone); outlineParser()->addVhdlType(s,outlineParser()->getLine(PACKAGE_T),Entry::CLASS_SEC,VhdlDocGen::PACKAGE,0,0,Package); } + package_header() package_declarative_part() [ ] [ name() ] { m_sharedState->lastEntity=0;m_sharedState->lastCompound=0; m_sharedState->genLabels.resize(0); } @@ -1773,8 +1791,7 @@ void geninter():{} void package_declarative_item() : {} { -//LOOKAHEAD(3) -//interface_subprogram_declaration() + subprogram_declaration() | type_declaration() | subtype_declaration() @@ -1863,6 +1880,7 @@ s=literal() { s.prepend(" ");return s;} LOOKAHEAD(name()) s=name() { return s;} | +LOOKAHEAD(allocator()) allocator() { return "";} | s=aggregate() { return s; } @@ -1880,6 +1898,7 @@ package_instantiation_declaration() LOOKAHEAD(4) interface_package_declaration() | package_declaration() +| context_declaration() } @@ -2018,6 +2037,13 @@ QCString relation_operator() : {} | {return ">=";} | {return "<=";} | {return "/=";} + | { return "?>=";} + | { return "?<=";} + | { return "?>";} + | { return "?<";} + | { return "?=";} + | {return "?/="; } + } @@ -2042,7 +2068,7 @@ QCString return_statement() : {QCString s,s1;} QCString scalar_type_definition() : {QCString s,s1;} { - +LOOKAHEAD(enumeration_type_definition()) s=enumeration_type_definition(){ return s;} | s=range_constraint() [LOOKAHEAD( physical_type_definition()) s1=physical_type_definition()] { return s+" "+s1+"%";} } @@ -2357,11 +2383,17 @@ QCString subtype_declaration() : {QCString s,s1;} } } +QCString reslution_indication(): {QCString s;} +{ + s=expression() { return "("+s+")"; } + // |s=name() { return s;} +} +//[LOOKAHEAD (reslution_indication()) s=reslution_indication()] +// [ resolution_indication ] type_mark [ constraint ] QCString subtype_indication() : {QCString s,s1,s2;} { - s=name() - [LOOKAHEAD (name()) s1=name()] [LOOKAHEAD(constraint() ) s2=constraint()] - { return s+" "+s1+" "+s2; } + [LOOKAHEAD(5) s=reslution_indication()] (s1=name())+ [LOOKAHEAD(constraint() ) s2=constraint()] + {return s+" "+s1+" "+s2;} } QCString suffix() : { QCString s; } @@ -2581,7 +2613,7 @@ void protected_type_declarative_part() : {} QCString context_ref() : {QCString s;} { - s=identifier_list() + s=name() { return "context "+s ; } @@ -2673,17 +2705,31 @@ void ttend(): {} void generate_statement_body() : {} { - generate_statement_body() + [(LOOKAHEAD(block_declarative_item())block_declarative_item() )* ] (concurrent_statement())* } void generate_statement_body1() : {} { - // [LOOKAHEAD(block_declarative_item() )(block_declarative_item() )* ] (concurrent_statement())* + generate_statement_body() generate_scheme_1() [generate_scheme_2()] +} + +void generate_scheme_1() : {} +{ + ( generate_scheme_3())* +} - [(LOOKAHEAD(block_declarative_item())block_declarative_item() )* ] (concurrent_statement())* - // | (concurrent_statement())* +void generate_scheme_2() : {} +{ + [LOOKAHEAD(2) identifier() ] generate_statement_body() } +void generate_scheme_3() : {} +{ + [LOOKAHEAD(2) identifier() ] expression() generate_statement_body() +} + + + QCString external_name(): {QCString s,s1,s2;} { s=sig_stat() s1=external_pathname() s2=subtype_indication() diff --git a/vhdlparser/vhdlstring.h b/vhdlparser/vhdlstring.h old mode 100644 new mode 100755 index 4c64440..ee01b06 --- a/vhdlparser/vhdlstring.h +++ b/vhdlparser/vhdlstring.h @@ -5,6 +5,26 @@ #include #include +#include "VhdlParser.h" +// super class for VhdlParserTokenManager +// is generated in vhdlparser.jj +// -option TOKEN_MANAGER_SUPER_CLASS = "TokenParser" +// sets the Vhdlparser in vhdljjparser.cpp +// tokenManager->setLexParser(vhdlParser); + +namespace vhdl { + namespace parser { + class TokenParser { + public: + VhdlParser* parser = nullptr; + void setLexParser(VhdlParser* p) + { + parser = p; + } + }; + } +} + /** @brief Minimal string class with std::string like behaviour that fulfills the JavaCC * string requirements. -- cgit v0.12