antlr3 - ANTLR 3.5 generates "extraneous parentheses" warning with C++ target -
i using c++ target in antlr v 3.5 , generated lexer.cpp file has bunch of extraneous parentheses warnings. warning is:
warning: equality comparison extraneous parentheses [-wparentheses-equality]
this happens in 5 places, corresponding generated lexer code is:
void qualifiednamelexer::mtokens() { { // qualifiedname.g:1:8: ( t__11 | t__12 | t__13 | t__14 | t__15 | pn_chars_base | helper_rule_for_other_punctuation_chars | pn_chars_others | digit ) antlr_uint32 alt2; alt2=9; { int la2_0 = this->la(1); if ( (la2_0 == '-')) { alt2=1; } else if ( (la2_0 == '.')) { alt2=2; } else if ( (la2_0 == ':')) { alt2=3; } else if ( (la2_0 == 0x00b7)) { alt2=4; } else if ( (la2_0 == '_')) { alt2=5; } ... } } }
here grammar corresponds generated lexer warnings.
grammar qualifiedname; options { language = cpp; k = 2; backtrack = true; memoize = true; } @parser::includes { #include "qualifiednamelexer.hpp" } @lexer::namespace { user } @parser::namespace { user } @lexer::traits { class qualifiednamelexer; class qualifiednameparser; typedef antlr3::traits< qualifiednamelexer, qualifiednameparser > qualifiednamelexertraits; typedef qualifiednamelexertraits qualifiednameparsertraits; } /******************** parser rules *****************************/ qualified_name : ( pn_prefix ':' )? pn_local | pn_prefix ':' ; pn_prefix : pn_chars_base ((pn_chars | '.')* pn_chars)? ; pn_local : ( pn_chars_u | digit | pn_chars_others ) ( ( pn_chars | '.' | pn_chars_others )* ( pn_chars | pn_chars_others ) )? ; pn_chars_u : pn_chars_base | '_' ; pn_chars : pn_chars_u | '-' | digit | '\u00b7' | helper_rule_for_other_punctuation_chars ; /************************* lexer rules ******************************/ pn_chars_base : 'a'..'z' | 'a'..'z' | '\u00c0'..'\u00d6' | '\u00d8'..'\u00f6' | '\u00f8'..'\u02ff' | '\u0370'..'\u037d' | '\u037f'..'\u1fff' | '\u200c'..'\u200d' | '\u2070'..'\u218f' | '\u2c00'..'\u2fef' | '\u3001'..'\ud7ff' | '\uf900'..'\ufdcf' | '\ufdf0'..'\ufffd' // | '\ud800\udc00'..'\udb7f\udfff' (u+10000 u+effff) not supported grammar. ; helper_rule_for_other_punctuation_chars : '\u0300'..'\u036f' | '\u203f'..'\u2040' ; pn_chars_others : '/' | '@' | '~' | '&' | '+' | '*' | '?' | '#' | '$' | '!' | percent | pn_chars_esc ; fragment pn_chars_esc : '\\' ( '=' | '\'' | '(' | ')' | ',' | '-' | ':' | ';' | '[' | ']' | '.' ) ; fragment percent : '%' hex hex ; fragment hex : '0'..'9' | 'a'..'f' | 'a'..'f' ; digit : '0'..'9' ;
is there can change in grammar rid of these warnings when antlr generates lexer? or antlr bug?
i fix gave up. code generated nested templates , it's hard predict @ end.
also g++ , clang treats code differently. afaik clang generates different warnings , extraneous parentheses somehow treat warning generated.
i think best way push-ignore warning @ beginning of header , pop-ignore @ and. tried got stuck somewhere.
maybe because warning not triggered while reading source while instantiating template. not remember.
ps: grammar quite simple, generated conditions might complex.
Comments
Post a Comment