Changes between Version 2 and Version 3 of LanguageSubset


Ignore:
Timestamp:
07/17/13 20:21:52 (13 years ago)
Author:
zirkel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LanguageSubset

    v2 v3  
    2121* if-then-else statements : Same syntax as C.
    2222* while, for loops
     23* return statement
    2324* { <blockItem>* } : A blockItem can be a variable declaration, function definition, or statement.
    2425* $assert <expr> : Check that <expr> holds.
     
    6667
    6768A 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
     72This 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
     80int 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
     88void main() {
     89  $assume n>0;
     90  s = add(n);
     91  $assert s == (n*(n+1))/2;
     92}
     93}}}