a complete c program has to have a function with name 'main'. this is the function called...

Post on 30-May-2018

214 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 1/18

1.21. A complete C program has to have a function with name 'main'. This is the

function called by the operating system. It must return an int value indicating whether the prograam executed correctly or if there was an error. In UNIX, the main program returns0 to indicate no errors. Their are several valid forms:

22. int main()23. int main(argc, argv)24. int main(argc, argv, envp) The parameters are set up by the operating system

when the program starts. The traditional arg stands for argument.

Pointers25. pointer::=#( "*" | #type_qualifier),

26. declarator::=pointer | direct_declarator,

Functions and Arrays

27. post_declarator::="["constant_expression"]" | "("parameter_list")" |"("identifier_list")"

28. direct_declarator::=identifier | "("declarator")" | direct_declarator post_declarator,

29. abstract_declarator::=pointer | pointer direct_abstract_declarator,

30. direct_abstract_declarator::= "(" abstract_declarator ")" |O( direct_abstract_declarator) O("[" O(constant_expression) "]" | "(" O(parameter_list)")" ),

. . . . . . . . . ( end of section Declarations) <<Contents | End>>Statements

1. statement::=labeled_statement | compound_statement | expression_statement |selection_statement | iteration_statement | jump_statement

Branch2. jump_statement::="goto" identifier";" | "continue" ";" | "break;" | "return"

expression ";",Structured

3. loop::=iteration_statement.4. iteration_statement::="while" "("expression")" statement | "do" statement

"while" "("expression")" ";" | for_statement.

5. for_statement::="for" "("expression ";" expression ";" expression")"statement,

6. selection_statement::=if_statement | "switch" "("expression")" statement,7. if_statement::="if ("expression")" statement | "if" "("expression")" statement

"else" statement.

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 2/18

8. expression_statement::= expression ";",

9. labeled_statement::=identifier ":" statement | "case" constant_expression ":"statement | "default" ":" statement,

Compound10. compound_statement::=block | "{" #statement "}",

11. block::="{" declaration #declaration #statement "}",

. . . . . . . . . ( end of section Statements) <<Contents | End>>Pre-Processor Commands

1. preprocess_token::=identifier | constant | string_literal | operator | punctuator |each Non-white space not one of the previous,

2. header_char::=any character except new_line | and | >,3. header_name::=#(header_char),

4. new_line::=new_line character,

5. Left_paren::=left parenthesis with no white space before it,

6. control_line::="#include" (#(preprocess_token | header_name) new_line |"#define" identifier #(preprocess_token) new_line | "#define" identifier left_parenidentifier_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,

7. endif_line::="#endif" new_line,

8. elif_group::="#elif" constant_expression new_line pp_group,

9. else_group::="#else" new_line pp_group,

10. if_group::=("#if" constant_expression | "#ifdef" identifier | "#ifndef"identifier) new_line pp_group,

11. if_part::=if_group #(elif_group) else_group endif_line,

12. pp_part::=#preprocess_token new_line | if_part | control_line,

13. pp_group::=#(pp_part),

. . . . . . . . . ( end of section Pre-Processor Commands) <<Contents | End>>

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 3/18

. . . . . . . . . ( end of section Syntax of The C Programming Language) <<Contents |End>>

Endyntax of The C Programming Language

Cross-Refferences1. ASCII::= See http://www.csci.csusb.edu/dick/samples/comp.text.ASCII.html

Used_in The definition of C++ [ c++.syntax.html ]

Used_in The definition of Java [ java.syntax.html ]NotationThis uses my XBNF Extended BNF Notation where "|" indicates "or", "(...)" indicates

priority. For more information see [ intro_ebnf.html ]

The following abbreviations are also used:1. O(_)::= 0 or 1 occurrences,2. N(_)::= 1 or more occurrence3. L(_)::= a comma separated list4. #(_)::= 0 or more occurrences.

5. S(E,Op)::=serial_operator_expression(E, Op)6. serial_operator_expression(E,Op)::= E #(Op E).

S(E,Op) = E Op E Op E Op ... E

It also uses the following shorthand

Lexemes1. identifier::=nondigit #(nondigit | digit),

2. 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",

3. digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",

4. punctuator::="[" | "]" | "(" | ")" | "{" | "}" | "*" | "," | ":" | "=" | ";" | "..." | "#",

5. operator::="[" | "]" | "(" | ")" | "." | "->" | "++" | "--" | "&" | "*" | "+" | "-" | "~" | "!"| "sizeof" | "/" | "%" | "<<" | ">>" | "<" | ">" | "<=" | ">=" | "==" | "!=" | "^" | "|" | "&&" |"||" | "?" | ":" | "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "||=" |"," | "#" | "##",

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 4/18

6. infix::= "->" | "&" | "*" | "+" | "-" | "/" | "%" | "<<" | ">>" | "<" | ">" | "<=" | ">=" |"==" | "!=" | "^" | "|" | "&&" | "||" | "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" |"&=" | "^=" | "||=" | "," ,

7. prefix::= "++" | "--" | "&" | "*" | "+" | "-" | "~" | "!" | "sizeof" ,

8. postfix::= "++" | "--",

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 5/18

Robertadhiabram

parman9. integer_suffix::=#(unsigned_suffix) | #(long_suffix),

10. unsigned_suffix::="u" | "U",

11. long_suffix::="l" | "L",

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 6/18

12. sign::="+" | "-",

13. octal_constant::="0" #(octal_digit),

14. octal_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7",

15. hex_constant::=("0x" | "0X") (hex_digit),

16. hex_digit::="0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "a" | "b" | "c" | "d"| "e" | "f" | "A" | "B" | "C" | "D" | "E" | "F",

17. decimal_constant::=non_zero_digit #(digit),

18. non_zero_digit::="1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9",

19. integer_constant::=(decimal_constant | octal_constant | hex_constant) |

integer_suffix,20. float_suffix::="f" | "l" | "F" | "L",

21. fraction::=#digit "." digit #digit,

22. exponent_part::=("e" | "E") sign #(digit),

23. float_constant::=fraction (exponent_part|) (float_suffix|)|(decimal_constant(exponent_part|) float_suffix,

24. enumeration_constant::=identifier,

25. char_constant::=char~(double_quote|eoln|backslash)| escape_sequence,

26. escape_sequence::=backslash (char | "0" #octal_digit |"0x"#hexadecimal_digit),

27. character_constant::="'" char_constant"'" ,

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 7/18

constant :=::=float_constant | integer_constant | enumeration_constant |character_constant,

28. string__char::=char~(double_quote|eoln|backslash)| escape_sequence,

29. string_literal::=double_quote #(string_char) double_quote,

. . . . . . . . . ( end of section Lexemes) <<Contents | End>>Expressions

Expressions are made up by applying operators to primary_expressions.1. primary_expression::= variable | constant | string_literal | "(" expression ")",

2. variable::= identifier & declared and in scope of declaration.3. argument_list::=List(assignment_expression),

OperatorsSymbol See"("... ")" primary_expression cast_expression function_call"." part of a structure"-" additive_expression unary_expression"->" part of a pointed at structure

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 8/18

"--" unary_expression postfix_expression

"-=" assignment_expression"&" AND_expression bitwise Boolean"&=" assignment_expression"&" address_of unary_expression

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 9/18

"&&" 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

Robertadhi

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 10/18

abram parman

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 11/18

"!" logical negation prefix

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 12/18

"!=" equality_expression

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 13/18

"sizeof" unary_expression

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 14/18

"/" multiplicative_expression divide

"/=" assignment_expression"%" multiplicative_expression mod"%=" assignment_expression"<" relational_expression

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 15/18

"<<" shift_expression left

Robertadhiabram

parman"<<=" assignment_expression"<=" relational_expression">" relational_expression">>" shift_expression right

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 16/18

">=" relational_expression">>=" assignment_expression"==" equality_expression"=" assignment_expression" "̂ XOR_expression exclusive-or bitwise

"^=" assignment_expression"|" OR_expression bitwise or "||" logical_OR_expression"||=" assignment_expression..."?"... ":"... conditional_expression"," expression (discard previous value)

Arithmetic4. post_fix::="++" | "--",

5. post_fix_expression::=(primary_expression) #(post_fix),

6. unary_operator::="&" | "*" | "+" | "-" | "!" | "-",

7. pre_fix::="++" | "--" | "sizeof",

8. unary_expression::=#(pre-fix) post_fix_expression | unary_operator cast_expression | "sizeof" "(" type_name")",

9. cast_expression::=#(type_name) unary_expression. This implies that casts aredone after doing post-fix operations..

10. multiplicative_expression::=S(cast_expression, multiplicative_operator).[ serial_operator_expression ]

The rule above means that 'casts' are done before multiplication and division, andthat multiplication and division are done from left to right.

11. multiplicative_operator::="*" | "%" | "/",

12. additive_expression::=S(multiplicative_expression, additive_operator). Thismeans that addition and subtraction occurs after multiplication and from left to right.

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 17/18

13. additive_operator::="+" | "-",

8/9/2019 A Complete C Program Has to Have a Function With Name 'Main'. This is the Function Called by the Operating Sys…

http://slidepdf.com/reader/full/a-complete-c-program-has-to-have-a-function-with-name-main-this 18/18

Shifts

top related