Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. Syntax of Subset of C Processed by Compiler
  2.  
  3. A program consists of a single function definition.
  4.  
  5. A function definition looks like this:
  6.  
  7. int functionName (int varName, int varName, ...) {
  8. functionBody
  9. }
  10. or
  11.  
  12. void functionName (int varName, int varName, ...) {
  13. functionBody
  14. }
  15. It has a return type (which must be either int or void), a name (any name of your choosing), and a list of zero or more parameters, separated by commas and enclosed in parentheses. Each parameter has a type (which must be int) followed by a parameter name (of your choosing). The function body is enclosed with braces.
  16.  
  17. A function body is a list of zero or more local variable declarations followed by a list of zero or more statements.
  18.  
  19. A local variable declaration looks like this:
  20.  
  21. int varName = constant;
  22. It has a type (which must be int), a variable name (of your choosing), an equals sign, an integer constant, and a semicolon.
  23.  
  24. There are five kinds of statements:
  25.  
  26. An assignment statement looks like this:
  27.  
  28. varName = exp;
  29. It has a variable name (which must have been previously declared as a parameter or local variable), an equals sign, an integer-valued expression, and a semicolon.
  30.  
  31. A return statement looks like this:
  32.  
  33. return exp;
  34. It has the keyword ``return'', an integer-valued expression, and a semicolon. A return statement may appear in a function only if the function's return type is int.
  35.  
  36. A conditional statement looks like this:
  37.  
  38. if (exp) {
  39. statements
  40. }
  41. else {
  42. statements
  43. }
  44. It consists of the keyword ``if'', a boolean-valued expression enclosed in parentheses, a list of zero or more statements enclosed in braces, the keyword ``else'', and a list of zero or more statements enclosed in braces. The else part is optional, however.
  45.  
  46. A while statement looks like this:
  47.  
  48. while (exp) {
  49. statements
  50. }
  51. It consists of the keyword ``while'', a boolean-valued expression enclosed in parentheses, and a list of zero or more statements enclosed in braces.
  52.  
  53.  
  54. There are many kinds of exps:
  55.  
  56. A previously-declared variable is an integer-valued expression.
  57.  
  58. An integer constant is an integer-valued expression.
  59.  
  60. Compound expressions of the form
  61.  
  62. exp + exp
  63. exp - exp
  64. -exp
  65. are integer-valued expressions.
  66.  
  67. Compound expressions of the form
  68.  
  69. exp > exp
  70. exp < exp
  71. exp >= exp
  72. exp <= exp
  73. exp == exp
  74. exp != exp
  75. are boolean-valued expressions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement