Changeset bdd516a for translator/examples
- Timestamp:
- Apr 28, 2015, 4:21:36 PM (11 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 42e2ad7
- Parents:
- ad17ba6a
- Location:
- translator/examples
- Files:
-
- 2 added
- 4 edited
-
constants.c (added)
-
control_structures.c (added)
-
includes.c (modified) (1 diff)
-
min.c (modified) (1 diff)
-
square.c (modified) (1 diff)
-
sum.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
translator/examples/includes.c
rad17ba6a rbdd516a 34 34 #include <curses.h> 35 35 #else 36 #include <time.h> // FAILS -- includes locale.h 36 37 #endif // 0 37 38 -
translator/examples/min.c
rad17ba6a rbdd516a 10 10 int main() { 11 11 char c; 12 c = min( ' a', 'z' );12 c = min( 'z', 'a' ); 13 13 printf( "minimum %d\n", c ); 14 14 int i; -
translator/examples/square.c
rad17ba6a rbdd516a 12 12 int main() { 13 13 printf( "result of square of 5 is %d\n", square( 5 ) ); 14 printf( "result of square of 5 is %f\n", square( 5.0 ) ); 14 15 } -
translator/examples/sum.c
rad17ba6a rbdd516a 7 7 T ?+?( T, T ); 8 8 T ?++( T * ); 9 [T]?+=?( T *, T );9 T ?+=?( T *, T ); 10 10 }; 11 11 12 12 forall( type T | sumable( T ) ) 13 13 T sum( int n, T a[] ) { 14 T total = 0; // instantiate T, select 0 14 T total; // instantiate T, select 0 15 total = 0; 15 16 for ( int i = 0; i < n; i += 1 ) 16 17 total = total + a[i]; // select + … … 18 19 } 19 20 21 // Required to satisfy sumable as char does not have addition. 22 const char 0; 23 char ?+?( char op1, char op2 ) { return op1 + op2; } 24 char ?++( char *op ) { return *op + 1; } 25 26 const double 0; // TEMPORARY, incorrect use of int 0 27 20 28 int main() { 21 29 const int size = 10, low = 0, High = 10; 22 int si , ai[10]; // size30 int si = 0, ai[10]; // size 23 31 int i; 24 32 for ( i = low; i < High; i += 1 ) { … … 28 36 printf( "sum from %d to %d is %d, check %d\n", 29 37 low, High, sum( size, ai ), si ); 30 double sd, ad[10]; // size 38 39 // char ci[10]; 40 // char c = sum( size, ci ); 41 // float fi[10]; 42 // float f = sum( size, fi ); 43 44 double sd = 0.0, ad[10]; // size 31 45 for ( i = low; i < High; i += 1 ) { 32 46 double d = i / (double)size;
Note:
See TracChangeset
for help on using the changeset viewer.