Closed mingodad closed 3 years ago
And here is the preprocessor Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/CPP/CPP.jj
/*
From https://raw.githubusercontent.com/NationalSecurityAgency/ghidra/master/Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/CPP/CPP.jj
*/
/* converted on Mon Jul 19, 2021, 13:03 (UTC+02) by javacc-to-w3c v0.53 which is Copyright (c) 2011-2021 by Gunther Rademacher <grd@gmx.net> */
Input ::= TranslationUnit*
TranslationUnit
::= Group+
NoMas ::= EOF
Group ::= GroupPart
| IFSection+
GroupPart
::= ( Text WS* )+
| IFSection+
| ControlLine
ControlLine
::= MANIFEST ( ( MacroArgs | WS+ ) MANIFEST )* ( ( MacroArgs+ | MacroVals ) MacroVals* | MacroArgs | MacroArgs+ MacroVals? )?
| Include
| UnDef
| Pragma
| Error
| Warning
| Info
| LineInfo
| NoMas
IFSection
::= IFGroup
IFGroup ::= 'if' IfCondition
| 'elif' ElseIfCondition
| 'ifdef' IfDefExpr
| 'ifndef' IfNDefExpr
| 'else'
| 'endif'
IfCondition
::= CompoundConditionalExpression
ElseIfCondition
::= CompoundConditionalExpression
Include ::= RELATIVE
| STANDARD
| MACEXPPATH
| XSYMLINKPATH
LineInfo ::= LINEINFO
| NUMERIC
UnDef ::= CONSTITUENT
MacroArgs
::= MACROMV
MacroVals
::= Values
| ( MACRORV | MQUOTED_VALUE )+ Values*
Pragma ::= PRAGMA_EXPRN
IfDefExpr
::= IFDEF_EXPRN
IfNDefExpr
::= IFNDEF_EXPRN
Error ::= ERROR_EXPRN
Warning ::= WARNING_EXPRN
Info ::= INFO_EXPRN
Values ::= VALUES
| QuotedValue
| MOREVAL
QuotedValue
::= QUOTED_VALUE
Text ::= ( ( OUTER_TEXT NewLines* | OTHER_TEXT ) NewLines? QuotedText? ( OTHER_TEXT NewLines* )? )+
| ( ( QuotedText NewLines? | OTHER_TEXT ) NewLines? OTHER_TEXT? NewLines? )+
| NewLines
NewLines ::= NEWLINE
| ERRLINE
| LINLINE
| PRGLINE
| INCLINE
QuotedText
::= QUOTED_TEXT
CompoundConditionalExpression
::= ConditionalExpression
| CompoundOrExpression
| CompoundAndExpression
CompoundAndExpression
::= ConditionalExpression ( '&&' ConditionalExpression )*
CompoundOrExpression
::= ConditionalExpression ( '||' ConditionalExpression )*
ConditionalExpression
::= LogicalOrExpression ( '?' LogicalOrExpression ':' LogicalOrExpression )*
LogicalOrExpression
::= LogicalAndExpression ( '||' LogicalAndExpression )*
LogicalAndExpression
::= EqualityExpression ( '&&' EqualityExpression )*
EqualityExpression
::= InEqualityExpression ( '==' InEqualityExpression )*
InEqualityExpression
::= RelationalExpression ( '!=' RelationalExpression )*
RelationalExpression
::= LessExpression ( '<' LessExpression )*
GreaterThanExpression
::= LogNegation ( '>' LogNegation )*
GreaterThanOrEqualExpression
::= GreaterThanExpression ( '>=' GreaterThanExpression )*
LessThanOrEqualExpression
::= GreaterThanOrEqualExpression ( '<=' GreaterThanOrEqualExpression )*
LessExpression
::= LessThanOrEqualExpression ( '<' LessThanOrEqualExpression )*
LogNegation
::= '!'* Expression
Negation ::= '-'* Expression
Assertion
::= 'defined' Expression
| ( '__option' | '__has_include' | '__has_include_next' ) '(' Expression ')'
Expression
::= ValueExpression ( SubtractFrom ValueExpression )*
SubtractFrom
::= '-'
| '+'
| '*'
| '&'
| '|'
| '>>'
| '<<'
ValueExpression
::= ( '-' | '+' )? ( NUMERIC | ITEM ( '(' ( ITEM | NUMERIC )+ ')' )? )
| FP_NUMERIC
| 'else'
| 'if'
| '(' CompoundConditionalExpression ')'
| Assertion
<?TOKENS?>
_CTRL ::= WSP* '#' WSP*
_LCMT ::= '//' [^#xA#xD]* ( #xA | #xD #xA? )
_CMT ::= '/' '*' [^*]* '*' ( ( [^*/] [^*]* )? '*' )* '/'
_BLANKLINE
::= WSP+
_LINECOMMENT
::= '//' [^#xA#xD]* ( #xA | #xD #xA? )
_COMMENT ::= '/' '*' [^*]* '*' ( ( [^*/] [^*]* )? '*' )* '/'
COD ::= '\' WSP* ( #xA | #xD #xA? )
ENDL ::= #xA
| #xD #xA?
UNDIR ::= ( [^"/ #x23#xA#xD#x9] | "'"'" | "'"'" | "'#'" )+
UNDIRALL ::= ( [^"/#xA#xD] | "'"'" | "'"'" | "'#'" )+
NOPAR ::= [^()]
WSP ::= [ #x9]
STD ::= [^>]
REL ::= [^"]
NOTENDL ::= [^#xA#xD]
NOTENDLC ::= [^ /#x9#xA#xD]
NOTENDLSTAR
::= [^*/#xA#xD]
NOTCMT ::= [^/*"#xA#xD]
NOTCMTCOD
::= [^\/"#xA#xD]
NOTWS ::= [^ #x9]
NOTWSQ ::= [^ "#x9#xA#xD]
NOTWQC ::= [^ /"#x9#xA#xD]
NOTWWSQLT
::= [^ <"#x9#xA#xD]
NOTWSQLT ::= [^<"#x9#xA#xD]
INTEGER_LITERAL
::= DECIMAL_LITERAL [lL]?
| HEX_LITERAL [lLU]*
| OCTAL_LITERAL [lL]*
DECIMAL_LITERAL
::= [0-9]+
HEX_LITERAL
::= '0' [xX] [0-9a-fA-F]+
HEX_DIGIT
::= [0-9a-fA-F]
OCTAL_LITERAL
::= '0' [0-7]*
FP_LITERAL
::= [0-9]+ ( ( '.' [0-9]* EXPONENT? | EXPONENT ) [fFdD]? | EXPONENT? [fFdD] )
| '.' [0-9]+ EXPONENT? [fFdD]?
EXPONENT ::= [eE] [+#x2D]? [0-9]+
WS ::= [ #x9]
OUTER_TEXT
::= WSP* UNDIR UNDIRALL*
NEWLINE ::= ENDL
OTHER_TEXT
::= .
QUOTED_TEXT
::= '"' ( [^"\#xA#xD] | '\' ( [ntbrf\'"#xA] | ( [0-3]? [0-7] )? [0-7] | #xD #xA? ) )* '"'
DIRLINE ::= ENDL
_WSP0 ::= WSP
_COD1 ::= COD
_WSP2 ::= WSP
_LCMT0 ::= '/' '/'
EIFLINE ::= ENDL
_CMT0 ::= '/' '*'
NUMERIC ::= INTEGER_LITERAL+
FP_NUMERIC
::= FP_LITERAL+
ITEM ::= [a-zA-Z_$] [a-zA-Z_$0-9]*
| ( '0'? [0-9] | [1-9] ) [0-9]*
_TOEOL ::= [^/#xA#xD]*
_LCMT11 ::= '/' '/'
_CMT11 ::= '/' '*'
_INCCOD ::= COD
_INCWSP ::= WSP
_INCSTANDARD
::= '<' [^>)(#xA#xD]* '>'
_HEX ::= HEX_DIGIT+ ENDL HEX_DIGIT+ ENDL
_XSYMENDL
::= ENDL
EXPATH ::= ENDL
XSYMLINKPATH
::= NOTENDL+
INCLINE ::= ENDL
MACEXPPATH
::= NOTWWSQLT NOTWSQLT*
_COD ::= COD
_WSP ::= WSP
STANDARD ::= STD+
RELATIVE ::= REL+
PRAGMA_EXPRN
::= NOTWS NOTENDL+
PRGLINE ::= ENDL
_WSP1 ::= WSP
IFDEF_EXPRN
::= NOTWS ( '/'? NOTENDLC )+
_LCMT20 ::= '/' '/'
_WSP3 ::= WSP
IFDLINE ::= ENDL
IFNDEF_EXPRN
::= NOTWS ( '/'? NOTENDLC )+
_LCMT21 ::= '/' '/'
_WSP4 ::= WSP
IFNDLINE ::= ENDL
ERROR_EXPRN
::= NOTENDL+
ERRLINE ::= ENDL
_WSP5 ::= WSP
WARNING_EXPRN
::= NOTWS NOTENDL+
WARNLINE ::= ENDL
_WSP6 ::= WSP
INFO_EXPRN
::= NOTWS NOTENDL+
INFOLINE ::= ENDL
_WSP_INFO
::= WSP
UNDLINE ::= ENDL
_LEADIN1 ::= WSP+
CONSTITUENT
::= MANIFEST
_LEADIN2 ::= WSP+
CONLINE ::= ENDL
_WSP7 ::= WSP
_CODC ::= COD
MANIFEST ::= [a-zA-Z_$] [a-zA-Z_$0-9]*
| ( [0-9] | [-+] ( [1-9] | '0' [0-9] ) ) [0-9]*
| '...'
LINLINE ::= ENDL
LINEINFO ::= NOTENDL+
_ECMT3 ::= [^*]* '*' ( ( [^*/] [^*]* )? '*' )* '/'
_CMT3 ::= [^#xA#xD]*
_ECMT10 ::= [^*]* '*' ( ( [^*/] [^*]* )? '*' )* '/'
_LCMT4 ::= '/' '/'
_WSP8 ::= WSP
_COD2 ::= WSP* COD
RVSLINE ::= ENDL
VALUES ::= ( '/##/' | NOTCMTCOD | '/' NOTENDLSTAR | '\' [^ #xA#xD] )+
MOREVAL ::= MANIFEST
_ECMT7 ::= ( [^*] | '*' [^/] )*
QUOTED_VALUE
::= ( [^"\] | '\' [^#xA#xD] )*
MACROMV ::= MANIFEST
_ECMT5 ::= '/' '*' [^*]* '*' ( ( [^*/] [^*]* )? '*' )* '/'
_CMT5 ::= '/' '/' [^#xA#xD]+
_COD3 ::= COD
_MACWSP ::= WSP
MOREARG ::= NOPAR+
MACRORV ::= ( NOTCMTCOD | '/' NOTENDLSTAR | '\' [^ \#x9#xA#xD] )+
_LCMT7 ::= '/' '/'
_COD4 ::= WSP* COD
_ECMT8 ::= '/' '*'
MCVLINE ::= ENDL
LEADIN3 ::= WSP+
MQUOTED_VALUE
::= ( [^\"] | '\' [^ #x9#xA#xD] )+
_ECMT9 ::= ( [^*] | '*' [^/] )*
_EECMT9 ::= '*/' WSP* ENDL
_ ::= _CTRL
| 'XSym'
| _LCMT
| _CMT
| _BLANKLINE
/* ws: definition */
EOF ::= $
Are you reporting a problem or bug that you have found in the grammar?
Sorry ! None of then, I'm reporting an alternative view of the grammar for debug, development, documentation and understand purposes.
Gotcha. It would probably be best to convert this issue to a discussion.
Using this tool https://www.bottlecaps.de/convert/ we can see a railroad diagram for the grammar in
Ghidra/Features/Base/src/main/javacc/ghidra/app/util/cparser/C/C.jj
copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui in the tab Edit Grammar then switching to the tab View Diagram.