Changes between Version 2 and Version 3 of LanguageSubset
- Timestamp:
- 07/17/13 20:21:52 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
LanguageSubset
v2 v3 21 21 * if-then-else statements : Same syntax as C. 22 22 * while, for loops 23 * return statement 23 24 * { <blockItem>* } : A blockItem can be a variable declaration, function definition, or statement. 24 25 * $assert <expr> : Check that <expr> holds. … … 66 67 67 68 A program must have a function called main which takes no arguments. Execution of the program begins in the body of main. 69 70 == Example == 71 72 This program calls a function that sums the numbers from 1 to n and checks that the result is equal to the closed form. 73 74 {{{ 75 #include<civlc.h> 76 77 $input int n; 78 $output int s = 0; 79 80 int add(int i) { 81 int sum = 0; 82 for (int i=0; i<n; i++) { 83 sum = sum + i; 84 } 85 return sum; 86 } 87 88 void main() { 89 $assume n>0; 90 s = add(n); 91 $assert s == (n*(n+1))/2; 92 } 93 }}}
