1 / 9

This presentation includes custom animations.

This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode.

melody
Download Presentation

This presentation includes custom animations.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode. If you have opened this lesson in a browser and see a bar similar to that below, click on the Slide Show icon A notice similar to the one below may appear warning that ActiveX or other scripts are disabled. Enable the controls for this website in order to see the animations.

  2. Syntax Diagrams This lesson discusses how to read syntax diagrams. Vocabulary: argument C99 syntax diagram Christine S. Wolfe Ohio University Lancaster 2008-Aug-01

  3. C, like most programming languages, has a strict format for writing code. The rules for writing a correctly formatted instruction is call the syntax. Syntax rules include: Correct spelling of key words Correct order of arguments Correct punctuation The official syntax rules are defined in the ANSI (American National Standards Institute) C standard, specifically the C99 standard adopted as ISO/IEC 9899:1999

  4. Textbooks and reference books attempt to make the syntax easier to understand by providing a syntax diagram to illustrate the rules for a given instruction. Although the syntax is always the same - as defined in the C99 standard, each publisher seems to use a different format for the diagrams. Most references will include a guide to let you know how to read the diagrams. Read the guide to understand how the reference indicates required items vs option items and other syntax details. In our textbook, Appendix B includes the syntax diagrams for the language items used in the textbook. Unfortunately, the book does not include a guide to the diagrams. Or if it does, I don't see it - let me know if you find it. I will provide a guide here.

  5. Guide to reading the syntax diagrams in Appendix B. • DataTypeItemName (argument [, argument, …]); stdio.h semicolon at end ellipse indicates the previous item (argument in this case) can be repeated square braces [ ] enclose optional items list of parameters inside parentheses correct spelling, including capitalization, of the item name data type returned by the function header file that defines the statement

  6. Example: syntax diagram from our textbook • printf syntax diagram from Page794 of the text • int printf (const char *format [, argument, …]); stdio.h semicolon at end ellipse indicates the previous item (argument in this case) can be repeated The square braces [ ] indicates that additional optional arguments may be included There is only 1 required argument and that is a string (identifed as "const char *format) note the spelling and capitalization printf returns an int #include <stdio.h> must be included in the preprocessor commands before printf can be used in a program.

  7. Example: syntax diagram from our textbook Note: colors are not part of the syntax. They are used here to show where they match in the examples. • int printf (const char *format [, argument, …]); NumChars = printf("Hello World"); NumChars = printf("Total = %f", GrandTotal); printf("%d + %d = %d" , Num1 , Num2 , Num3); Notice that the last example does not assign the returned value to a variable. That is acceptable. The value is returned but not assigned.

  8. It is important to be able to read syntax diagrams from several sources. • printf • syntax from Programmer’s Reference by Herbert Schildt • #include <stdio.h> • int printf (const char *format, …); shows the required header file ellipse indicates that optional parameters may be included required arguments are specified by datatype name of the function data type returned by the function

  9. It is important to be able to read syntax diagrams from several sources. • printf • syntax from C Pocket Referenceby Ulla Kirch-Prinz, Peter Prinzavailable on Safari • int printf ( const char *format , ... /*arg1 , ... , argn */ ); /* */ indicates that the enclosed arguments are OPTIONAL this ellipse indicates that optional parameters may be included this ellipse indicates you can have any number of arguments between arg1 and argn where n is any integer required arguments are specified by datatype name of the function data type returned by the function

More Related