ASCII::= See http://www.csci.csusb.edu/dick/samples/c...
Used_in The definition of C++ [ c++.syntax.html ]
Used_in The definition of Java [ java.syntax.html ]
Notation
This uses my XBNF Extended BNF Notation where "|" indicates "or", "(...)" indicates priority. For more information see [ intro_ebnf.html ]
The following abbreviations are also used:
--------------------------------------...
O(_)::= 0 or 1 occurrences,
N(_)::= 1 or more occurrence
L(_)::= a comma separated list
#(_)::= 0 or more occurrences.
S(E,Op)::=serial_operator_expression(E... Op)
serial_operator_expression(E,Op)::= E #(Op E).
S(E,Op) = E Op E Op E Op ... E
--------------------------------------...
It also uses the following shorthand
Lexemes
identifier::=nondigit #(nondigit | digit),
nondigit::="_" | "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | "E" | "f" | "F" | "g" | "G" | "h" | "H" | "i" | "I" | "j" | "J" | "k" | "K" | "l" | "L" | "m" | "M" | "n" | "N" | "o" | "O" | "p" | "P" | "q" | "Q" | "r" | "R" | "s" | "S" | "t" | "T" | "u" | "U" | "v" | "V" | "w" | "W" | "x" | "X" | "y" | "Y" | "z" | "Z",
digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",
punctuator::="[" | "]" | "(" | ")" | "{" | "}" | "*" | "," | ":" | "=" | ";" | "..." | "#",
operator::="[" | "]" | "(" | ")" | "." | "-%26gt;" | "++" | "--" | "%26amp;" | "*" | "+" | "-" | "~" | "!" | "sizeof" | "/" | "%" | "%26lt;%26lt;" | "%26gt;%26gt;" | "%26lt;" | "%26gt;" | "%26lt;=" | "%26gt;=" | "==" | "!=" | "^" | "|" | "%26amp;%26amp;" | "||" | "?" | ":" | "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "%26lt;%26lt;=" | "%26gt;%26gt;=" | "%26amp;=" | "^=" | "||=" | "," | "#" | "##",
infix::= "-%26gt;" | "%26amp;" | "*" | "+" | "-" | "/" | "%" | "%26lt;%26lt;" | "%26gt;%26gt;" | "%26lt;" | "%26gt;" | "%26lt;=" | "%26gt;=" | "==" | "!=" | "^" | "|" | "%26amp;%26amp;" | "||" | "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "%26lt;%26lt;=" | "%26gt;%26gt;=" | "%26amp;=" | "^=" | "||=" | "," ,
prefix::= "++" | "--" | "%26amp;" | "*" | "+" | "-" | "~" | "!" | "sizeof" ,
postfix::= "++" | "--",
integer_suffix::=#(unsigned_suffix) | #(long_suffix),
unsigned_suffix::="u" | "U",
long_suffix::="l" | "L",
sign::="+" | "-",
octal_constant::="0" #(octal_digit),
octal_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7",
hex_constant::=("0x" | "0X") (hex_digit),
hex_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d" | "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F",
decimal_constant::=non_zero_digit #(digit),
non_zero_digit::="1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",
integer_constant::=(decimal_constant | octal_constant | hex_constant) | integer_suffix,
float_suffix::="f" | "l" | "F" | "L",
fraction::=#digit "." digit #digit,
exponent_part::=("e" | "E") sign #(digit),
float_constant::=fraction (exponent_part|) (float_suffix|)|(decimal_constant (exponent_part|) float_suffix,
enumeration_constant::=identifier,
char_constant::=char~(double_quote|eol... escape_sequence,
escape_sequence::=backslash (char | "0" #octal_digit |"0x"#hexadecimal_digit),
character_constant::="'" char_constant"'" ,
constant :=::=float_constant | integer_constant | enumeration_constant | character_constant,
string__char::=char~(double_quote|eoln... escape_sequence,
string_literal::=double_quote #(string_char) double_quote,
. . . . . . . . . ( end of section Lexemes) %26lt;%26lt;Contents | End%26gt;%26gt;
Expressions
Expressions are made up by applying operators to primary_expressions.
primary_expression::= variable | constant | string_literal | "(" expression ")",
variable::= identifier %26amp; declared and in scope of declaration.
argument_list::=List(assignment_expres...
Operators
Symbol See
"("... ")" primary_expression cast_expression function_call
"." part of a structure
"-" additive_expression unary_expression
"-%26gt;" part of a pointed at structure
"--" unary_expression postfix_expression
"-=" assignment_expression
"%26amp;" AND_expression address_of unary_expression
"%26amp;=" assignment_expression
"%26amp;%26amp;" logical_AND_expression
"*" multiplicative_expression contents of pointer unary_expression
"*=" assignment_expression
"+" additive_expression unary_expression
"++" unary_expression postfix_expression
"+=" assignment_expression
"~" bitwise negation prefix
"!" logical negation prefix
"!=" equality_expression
"sizeof" unary_expression
"/" multiplicative_expression divide
"/=" assignment_expression
"%" multiplicative_expression mod
"%=" assignment_expression
"%26lt;" relational_expression
"%26lt;%26lt;" shift_expression left
"%26lt;%26lt;=" assignment_expression
"%26lt;=" relational_expression
"%26gt;" relational_expression
"%26gt;%26gt;" shift_expression right
"%26gt;=" relational_expression
"%26gt;%26gt;=" assignment_expression
"==" equality_expression
"=" assignment_expression
"^" XOR_expression
"^=" assignment_expression
"|" OR_expression
"||" logical_OR_expression
"||=" assignment_expression
..."?"... ":"... conditional_expression
"," expression (discard previous value)
Arithmetic
post_fix::="++" | "--",
post_fix_expression::=(primary_express... #(post_fix),
unary_operator::="%26amp;" | "*" | "+" | "-" | "!" | "-",
pre_fix::="++" | "--" | "sizeof",
unary_expression::=#(pre-fix) post_fix_expression | unary_operator cast_expression | "sizeof" "(" type_name")",
cast_expression::=#(type_name) unary_expression. This implies that casts are done after doing post-fix operations..
multiplicative_expression::=S(cast_exp... multiplicative_operator). [ serial_operator_expression ]
The rule above means that 'casts' are done before multiplication and division, and that multiplication and division are done from left to right.
multiplicative_operator::="*" | "%" | "/",
additive_expression::=S(multiplicative... additive_operator). This means that addition and subtraction occurs after multiplication and from left to right.
additive_operator::="+" | "-",
Shifts
shift_expression::=S(additive_expressi... shift_operator),
shift_operator::="%26gt;%26gt;" | "%26lt;%26lt;", "%26lt;%26lt;" is left shift of bits (multiply by 2), and "%26gt;%26gt;" is the reverse and divides by 2.
Relations
relational_expression::= S(shift_expression, relational_operator),
relational_operator::="%26lt;" | "%26gt;" | "%26lt;=" | "%26gt;=",
equality_expression::=S(relational_exp... equality_operator),
equality_operator::="==" | "!=",
Bitwise Expressions
AND_expression::=S(equality_expression... and_operator),
and_operator::="%26amp;", This operator takes each bit in the value of its arguments in turn to calculate the bit in the answer. A bit is 1 if and only if both arguments have bits in that palce that are 1.
XOR_expression::=S(AND_expression, XOR_operator),
XOR_operator::="^", XOR is short for eXclusive-OR. The n'th bit in the value is 1 precisly when the n'th bits in the two arguments are different.
OR_expression::=S(XOR_expression, OR_operator),
OR_operator::="|", This operator takes each bit in the value of its arguments in turn to calculate the bit in the answer. The n'th bit is 1 if either n'th bits is 1.
Logical Expressions
In C, logical false is reresented by any zero value and true by any nonzero value.
logical_AND_expression::=S(OR_expressi... logical_AND_operator),
logical_AND_operator::="%26amp;%26amp;", A%26amp;%26amp;B is true precisely when both A and B evaluate to be true.
logical_OR_expression::=S(logical_AND_... logical_OR_operator),
logical_OR_operator::="||", A||B is true if A evaluates to be true, or when A is false and B evaluates to be true. If both evaluate to false (zero) then A||B is false.
Conditional Expressions
conditional_expression::=logical_OR_ex... | logical_OR_expression "?" expression ":" conditional_expression,
Assignment Statements
assignment_expression::=S(unary_expres... assignment_operator),
assignment_operator::="=" | "*=" | "/=" | "%=" | "+=" | "%26lt;%26lt;=" | "%26gt;%26gt;=" | "%26amp;=" | "^=" | "|=",
expression::=List(assignment_expressio... ),
constant_expression::=conditional_expr...
. . . . . . . . . ( end of section Expressions) %26lt;%26lt;Contents | End%26gt;%26gt;
Declarations
declaration::=declaration_specifier | declarator_list,
declarator_list::=List(declarator_init...
declaration_specifier::=(storage_class | type_specifier | type_qualifier),
storage_class::="typedef" | "extern" | "static" | "auto" | "register",
Types
type_specifier::="void" | "char" | "short" | "int" | "long" | "float" | "double" | "signed" | "unsigned" | struct_union_specifier | enumeration_specifier | typedef_name,
type-qualifier::="const" | "volatile",
typedef_name::=identifier,
Initialization
initializer::=assignment_expression | initializer_list,
initializer_list::=List(initializer),
declarator_initialized::=declarator ("=" initializer),
Structs and Unions
structure_declarator::=declarator | declarator ":" constant_expression,
structure_declarator_list::=List(struc...
structure_declaration::=(type_specifie... | type_qualifier) structure_declarator_list ";" ,
struct_union_specifier::=struct_union identifier | struct_union identifier "{"structure_declarator_list "}",
struct_union::=( "struct" | "union" ),
Enums
enumeration_value::=enumeration_consta... ("=" constant_expression|)
enumeration_list::=List(enumeration_va... ),
enumeration_specifier::=enumeration_id... | "enum" identifier "{"enumeration_list"}",
Functions
function_definition::=declaration_spec... declarator | declaration_list | compound_statement,
parameter_declaration::=#declaration_s... declarator | abstract_declarator,
parameter_list::=List(parameter_declar... (",..."|),
Pointers
pointer::=#( "*" | #type_qualifier),
declarator::=pointer | direct_declarator,
Functions and Arrays
post_declarator::="["constant_expressi... | "("parameter_list")" | "("identifier_list")"
direct_declarator::=identifier | "("declarator")" | direct_declarator post_declarator,
abstract_declarator::=pointer | pointer direct_abstract_declarator,
direct_abstract_declarator::= "(" abstract_declarator ")" | O( direct_abstract_declarator) O("[" O(constant_expression) "]" | "(" O(parameter_list) ")" ),
. . . . . . . . . ( end of section Declarations) %26lt;%26lt;Contents | End%26gt;%26gt;
Statements
statement::=labeled_statement | compound_statement | expression_statement | selection_statement | iteration_statement | jump_statement
Branch
jump_statement::="goto" identifier";" | "continue" ";" | "break;" | "return" expression ";",
Structured
loop::=iteration_statement.
iteration_statement::="while" "("expression")" statement | "do" statement "while" "("expression")" ";" | for_statement.
for_statement::="for" "("expression ";" expression ";" expression")" statement,
selection_statement::=if_statement | "switch" "("expression")" statement,
if_statement::="if ("expression")" statement | "if" "("expression")" statement "else" statement.
expression_statement::= expression ";",
labeled_statement::=identifier ":" statement | "case" constant_expression ":" statement | "default" ":" statement,
Compound
compound_statement::=block | "{" #statement "}",
block::="{" declaration #declaration #statement "}",
. . . . . . . . . ( end of section Statements) %26lt;%26lt;Contents | End%26gt;%26gt;
Pre-Processor Commands
preprocess_token::=identifier | constant | string_literal | operator | punctuator | each Non-white space not one of the previous,
header_char::=any character except new_line | and | %26gt;,
header_name::=#(header_char),
new_line::=new_line character,
Left_paren::=left parenthesis with no white space before it,
control_line::="#include" (#(preprocess_token | header_name) new_line | "#define" identifier #(preprocess_token) new_line | "#define" identifier left_paren identifier_list #(preprocess_token) new_line, | "#undef" identifier new_line | "#line" preprocess_token new_line | "#error" preprocess_token new_line | "#pragma" preprocess_token new_line | "#"new_line,
endif_line::="#endif" new_line,
elif_group::="#elif" constant_expression new_line pp_group,
else_group::="#else" new_line pp_group,
if_group::=("#if" constant_expression | "#ifdef" identifier | "#ifndef" identifier) new_line pp_group,
if_part::=if_group #(elif_group) else_group endif_line,
pp_part::=#preprocess_token new_line | if_part | control_line,
pp_group::=#(pp_part),
What are the syntax in java programming and in C programming?
you can use the following link to learn c syntax
http://www.geocities.com/learnprogrammin...
use the following link for java programming
http://java.sun.com/docs/books/tutorial/...
don't waste the time,
all the best.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment