Changeset 083cf31 for src/examples
- Timestamp:
- Jan 7, 2016, 11:28:48 AM (9 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, with_gc
- Children:
- 1e9d87b
- Parents:
- 267cb3d (diff), de91427b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/examples
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/Makefile.in
r267cb3d r083cf31 191 191 esac; \ 192 192 done; \ 193 echo ' cd $(top_srcdir) && $(AUTOMAKE) -- gnusrc/examples/Makefile'; \193 echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/examples/Makefile'; \ 194 194 $(am__cd) $(top_srcdir) && \ 195 $(AUTOMAKE) -- gnusrc/examples/Makefile195 $(AUTOMAKE) --foreign src/examples/Makefile 196 196 .PRECIOUS: Makefile 197 197 Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status -
src/examples/fstream_test.c
r267cb3d r083cf31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:13:43201513 // Update Count : 212 // Last Modified On : Mon Nov 23 14:43:32 2015 13 // Update Count : 40 14 14 // 15 15 … … 20 20 ifstream *sin = ifstream_stdin(); 21 21 int nombre; 22 sout << "Appuyez un nombre, s'il vous plâit:\n"; 23 sin >> &nombre; 24 sout << "Vous avez appuyé: " << nombre << "\n"; 22 sout | "Entrez un nombre, s'il vous plaît:\n"; 23 sin | &nombre; 24 sout | "Vous avez entré " | nombre | " stocké à l'adresse " | &nombre | endl; 25 sout | "nombre " | nombre | " est " 26 | (nombre > 0 ? "plus grand que" : 27 nombre == 0 ? "égal à" : "moins de") 28 | " zéro" | endl; 29 30 sout | "Entrez trois nombres, s'il vous plaît:\n"; 31 int i, j, k; 32 sin | &i | &j | &k; 33 sout | "Vous avez entré " | "i:" | i | " j:" | j | " k:" | k | endl; 34 35 sout | 3 | ' ' | 3.5 | ' ' | 'a' | ' ' | "abc" | endl; 25 36 } 26 37 -
src/examples/hello.c
r267cb3d r083cf31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 20 16:02:50201513 // Update Count : 312 // Last Modified On : Sun Nov 22 17:40:37 2015 13 // Update Count : 5 14 14 // 15 15 … … 19 19 ofstream *sout = ofstream_stdout(); 20 20 ifstream *sin = ifstream_stdin(); 21 sout << "Bonjour au monde!\n"; 22 sout << 3 << " " << 3.5 << " " << 'a' << " " << "abc" << "\n"; 23 int i, j, k; 24 sin >> &i >> &j >> &k; 25 sout << "i:" << i << " j:" << j << " k:" << k << "\n"; 21 sout | "Bonjour au monde!\n"; 26 22 } 27 23 -
src/examples/iostream.c
r267cb3d r083cf31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Nov 20 13:19:19201513 // Update Count : 912 // Last Modified On : Mon Dec 7 23:08:02 2015 13 // Update Count : 24 14 14 // 15 15 … … 21 21 22 22 forall( dtype ostype | ostream( ostype ) ) 23 ostype * ? <<?( ostype *os, char c ) {23 ostype * ?|?( ostype *os, char c ) { 24 24 return write( os, &c, 1 ); 25 } // ? <<?25 } // ?|? 26 26 27 27 forall( dtype ostype | ostream( ostype ) ) 28 ostype * ? <<?( ostype *os, int i ) {28 ostype * ?|?( ostype *os, int i ) { 29 29 char buffer[32]; // larger than the largest integer 30 30 sprintf( buffer, "%d", i ); 31 31 return write( os, buffer, strlen( buffer ) ); 32 } // ? <<?32 } // ?|? 33 33 34 34 forall( dtype ostype | ostream( ostype ) ) 35 ostype * ? <<?( ostype *os, double d ) {35 ostype * ?|?( ostype *os, double d ) { 36 36 char buffer[32]; // larger than the largest double 37 37 sprintf( buffer, "%g", d ); 38 38 return write( os, buffer, strlen( buffer ) ); 39 } // ? <<?39 } // ?|? 40 40 41 41 forall( dtype ostype | ostream( ostype ) ) 42 ostype * ? <<?( ostype *os, const char *cp ) {42 ostype * ?|?( ostype *os, const char *cp ) { 43 43 return write( os, cp, strlen( cp ) ); 44 } // ? <<?44 } // ?|? 45 45 46 46 forall( dtype ostype | ostream( ostype ) ) 47 ostype * ? <<?( ostype *os, const void *p ) {47 ostype * ?|?( ostype *os, const void *p ) { 48 48 char buffer[32]; // larger than the largest pointer 49 49 sprintf( buffer, "%p", p ); 50 50 return write( os, buffer, strlen( buffer ) ); 51 } // ?<<? 51 } // ?|? 52 53 54 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) 55 retostype * ?|?( ostype *os, retostype * (*manip)(ostype*) ) { 56 return manip(os); 57 } 58 59 forall( dtype ostype | ostream( ostype ) ) 60 ostype * endl( ostype * os ) { 61 os | "\n"; 62 // flush 63 return os; 64 } // endl 52 65 53 66 forall( type elt_type | writeable( elt_type ), … … 56 69 void write( iterator_type begin, iterator_type end, os_type *os ) { 57 70 void print( elt_type i ) { 58 os << i <<' ';71 os | i | ' '; 59 72 } 60 73 for_each( begin, end, print ); 61 } // ? <<?74 } // ?|? 62 75 63 76 forall( type elt_type | writeable( elt_type ), … … 65 78 dtype os_type | ostream( os_type ) ) 66 79 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 67 void print( elt_type i ) { 68 os << i << ' '; 69 } 80 void print( elt_type i ) { os | i | ' '; } 70 81 for_each_reverse( begin, end, print ); 71 } // ? <<?82 } // ?|? 72 83 73 84 74 85 forall( dtype istype | istream( istype ) ) 75 istype * ? >>?( istype *is, char *cp ) {86 istype * ?|?( istype *is, char *cp ) { 76 87 return read( is, cp, 1 ); 77 } // ? >>?88 } // ?|? 78 89 79 90 forall( dtype istype | istream( istype ) ) 80 istype * ? >>?( istype *is, int *ip ) {91 istype * ?|?( istype *is, int *ip ) { 81 92 char cur; 82 93 83 94 // skip some whitespace 84 95 do { 85 is >>&cur;96 is | &cur; 86 97 if ( fail( is ) || eof( is ) ) return is; 87 98 } while ( !( cur >= '0' && cur <= '9' ) ); … … 91 102 while ( cur >= '0' && cur <= '9' ) { 92 103 *ip = *ip * 10 + ( cur - '0' ); 93 is >>&cur;104 is | &cur; 94 105 if ( fail( is ) || eof( is ) ) return is; 95 106 } … … 97 108 unread( is, cur ); 98 109 return is; 99 } // ? >>?110 } // ?|? 100 111 101 112 // Local Variables: // -
src/examples/iostream.h
r267cb3d r083cf31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 19 17:56:51201513 // Update Count : 512 // Last Modified On : Mon Nov 23 14:15:25 2015 13 // Update Count : 17 14 14 // 15 15 … … 27 27 28 28 context writeable( type T ) { 29 forall( dtype ostype | ostream( ostype ) ) ostype * ? <<?( ostype *, T );29 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 30 30 }; 31 31 32 32 // implement writable for some intrinsic types 33 33 34 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, char ); 35 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, int ); 36 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, double ); 37 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, const char * ); 38 forall( dtype ostype | ostream( ostype ) ) ostype * ?<<?( ostype *, void * ); 34 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, char ); 35 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, int ); 36 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, double ); 37 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const char * ); 38 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, const void * ); 39 40 forall( dtype ostype, dtype retostype | ostream( ostype ) | ostream( retostype ) ) retostype * ?|?( ostype *os, retostype * (* manip)(ostype*) ); 41 forall( dtype ostype | ostream( ostype ) ) ostype * endl( ostype * ); 39 42 40 43 // writes the range [begin, end) to the given stream … … 49 52 void write_reverse( iterator_type begin, iterator_type end, os_type *os ); 50 53 54 //****************************************************************************** 51 55 52 56 context istream( dtype istype ) { … … 58 62 59 63 context readable( type T ) { 60 forall( dtype istype | istream( istype ) ) istype * ? <<?( istype *, T );64 forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, T ); 61 65 }; 62 66 63 67 forall( dtype istype | istream( istype ) ) 64 istype * ? >>?( istype *, char * );68 istype * ?|?( istype *, char * ); 65 69 66 70 forall( dtype istype | istream( istype ) ) 67 istype * ? >>?( istype *, int * );71 istype * ?|?( istype *, int * ); 68 72 69 73 #endif // IOSTREAM_H -
src/examples/sum.c
r267cb3d r083cf31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 28 15:09:55201513 // Update Count : 11 812 // Last Modified On : Sat Nov 21 18:08:18 2015 13 // Update Count : 119 14 14 // 15 15 … … 53 53 } 54 54 sout << "sum from " << low << " to " << High << " is " 55 << (int)sum( size, a ) << ", check " << (int)s << "\n";55 << (int)sum( size, a ) << ", check " << (int)s << endl; 56 56 57 57 int s = 0, a[size]; … … 62 62 } 63 63 sout << "sum from " << low << " to " << High << " is " 64 << sum( size, (int *)a ) << ", check " << (int)s << "\n";64 << sum( size, (int *)a ) << ", check " << (int)s << endl; 65 65 66 66 double s = 0.0, a[size]; … … 72 72 printf( "%g\n", sum( size, (double *)a ) ); 73 73 // sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is " 74 // << sum( size, (double *)a ) << ", check " << (double)s << "\n";74 // << sum( size, (double *)a ) << ", check " << (double)s << endl; 75 75 76 76 float s = 0.0, a[size]; … … 82 82 printf( "%g\n", sum( size, (float *)a ) ); 83 83 // sout << "sum from " << low / 10.0 << " to " << High / 10.0 << " is " 84 // << sum( size, (float *)a ) << ", check " << (float)s << "\n";84 // << sum( size, (float *)a ) << ", check " << (float)s << endl; 85 85 } 86 86 -
src/examples/vector_test.c
r267cb3d r083cf31 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Nov 19 17:54:34201513 // Update Count : 912 // Last Modified On : Tue Dec 15 16:02:56 2015 13 // Update Count : 13 14 14 // 15 15 … … 27 27 int num; 28 28 29 sout << "enter N elements and C-d on a separate line:\n";29 sout | "enter N elements and C-d on a separate line:" | endl; 30 30 for ( ;; ) { 31 sin >>#31 sin | # 32 32 if ( fail( sin ) || eof( sin ) ) break; 33 33 append( &vec, num ); … … 35 35 // write out the numbers 36 36 37 sout << "Array elements:\n";37 sout | "Array elements:" | endl; 38 38 write( begin( vec ), end( vec ), sout ); 39 sout << "\n";39 sout | endl; 40 40 41 sout << "Array elements reversed:\n";41 sout | "Array elements reversed:" | endl; 42 42 write_reverse( begin( vec ), end( vec ), sout ); 43 sout << "\n";43 sout | endl; 44 44 } 45 45
Note: See TracChangeset
for help on using the changeset viewer.