BNF de C++

<c++prog> ::= <sysdirectives> <decdefs> main () {<body>}
<sysdirectives> ::= | #<includedir>
<includedir> ::= include '<'<filename>'>' for <filename> name of file from system library
<decdefs> ::= | <typedef>

             | <constdef>

             |<decdefs><typedef>

             | <decdefs> <constdef>
<typedef> ::= <type><idlist>;
<type> ::= int

             | float

             | char
<idlist> ::= <iditem>

             | <iditem>, <idlist>
<iditem> ::= <id>

             | <id> = <idvalue> for <idvalue> an initial value of the correct type
<id> ::= <letter><restofid>

             | _ <restofid>
<restofid> ::= | <validchar>

             | <restofid><validchar>
<validchar> ::= <letter>

             | <digit> | _
<letter> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
<digit> ::= 1|2|3|4|5|6|7|8|9|0
<idlist> ::= <id>

             | <id>, <idlist>
<constdef> ::= const <type> <id> = <idvalue>; for <idvalue> an initial value of the correct type
<body> ::= | <statement>

             | <decdef>

             |<body> <statement>

             | <body> <decdef>
<statement> ::= <assignment>;

             | <inputstatement>;

             | <outputstatement>;

             | <condstatement>;

             | <iterativestatement>;
<assignment> ::= <id>++ | ++<id> | <id>-- | --<id> | <equalassign>
<equalassign> ::= <id> <equalsymbol> <expression> | <id> <equalsymbol> <equalassign>
<equalsymbol> ::= = | += | -= | *= | /=
<expression> ::= <term> | <sign><term> | <expression> <addoperator> <term>
<term> ::= <term> <multoperator> <factor> | <factor>
<factor> ::= <id> | (<expression>)
<multoperator> ::= * | / | %
<addoperator> ::= + | -
<inputstatement> ::= cin >> <inputlist>

             | cin.get(<charid>) for <charid> an <id> of type char
<inputlist> ::= <id> | <id> >> <inputlist>
<outputstatement> ::= cout << <outputlist> | cout.put(<charid>)
<outputlist> ::= <outputitem> | <outputitem> << <outputlist>
<outputitem> ::= <id> | '<character>'

             | "<characterstring>" for <character> any printable character including blank, tab, end-of-line
<characterstring> ::= <character> | <character><characterstring>
<conditionalstatement> ::= <ifstatement>

             | <arithmeticif>

             | <switchstatement>
<ifstatement> ::= <ifthen> | <ifthenelse>
<ifthen> ::= if (<condition>) <statement> | if (<condition>) {<body>}
<condition> ::= <expression><relop><expression>

             | <condition><logicop><condition>
<relop> ::= < | > | <= | >= | == | !=
<logicop> ::= ! | && | ||
<ifthenelse> ::= <ifthen> else <body>
<arithmeticif> ::= <condition> ? <expression> : <expression>
<switchstatement> ::= switch (<expression>) {<cases>}
<cases> ::= case <valx>: <body> break;

             | <cases> case <valy>: <body> break;

             | <cases> default: <body> for <valx> and <valy> discrete values
<iterativestatement> ::= <while>

            | <for>

            | <dowhile>
<while> ::= while (<condition>) <statement>

            | while (<condition>) {<body>}
<dowhile> ::= do <statement> while (<condition>);

            | do {<body>} while (<condition>);

 

Fonte:

otal.umd.edu/drweb/c++tutorial/lessons/BNF.HTM