Ch interpreter

From Wikipedia, the free encyclopedia

Ch, (IPA pronunciation: [siː eɪtʃ]), is a commercial embeddable C/C++ interpreter. Ch is designed for using one C compatible language for all programming tasks.

Ch extends C and C++ for scripting, numerical computing and 2D/3D plotting, and embedded scripting. It can run in Windows, Linux, Mac OS X and various versions of Unix.

Contents

Ch supports the 1999 ISO C Standard (C99) and C++ classes. It is superset of C with C++ classes. C99 major features such as complex numbers, variable length arrays (VLAs), IEEE-754 floating-point arithmetic and generic mathematical functions are supported. Wide characters in Addendum 1 for C90 is also supported.

As a C/C++ interpreter, Ch can be used as a scripting engine for your applications. It extends your applications with a C compatible scripting language.

Ch is a C-compatible shell similar to C-shell (csh). It can be used as login shell. Ch has a built-in string type for automatic memory allocation and de-allocation.

Ch has built-in 2D/3D graphical plotting features and computational arrays for numerical computing. A 2D linear equation of the form b = A*x can be written verbatim in Ch.

There are two ways to run Ch code. One is:

   #!/bin/ch
   printf("Hello world!\n");

Another is:

   #!/bin/ch
   #include 
   int main() {
       printf("Hello world!\n");
   }

Note: #!/bin/ch is optional.

   #include 
   #include 
   int main() {
       array double A[2][3] = {1, 2, 3,
                           4, 5, 6};
       array double B[3][2];
       printf("A= \n%f \n", A+A);
       B = 2*transpose(A);
       printf("B= \n%f \n", B);
   }

The output is:

   A=
   2.000000 4.000000 6.000000
   8.000000 10.000000 12.000000 
   B=
   2.000000 8.000000
   4.000000 10.000000
   6.000000 12.000000 

Find and compile all .c files into .o in the current directory for which the .o file is old or absent:

   #!/bin/ch 
   #include  
   struct stat cstat, ostat; 
   string_t c, o; 
   foreach (c; `find . -name "*.c"`) 
   { 
       o=`echo $c | sed 's/.c$/.o/'`; 
       stat(o, &ostat); stat(c, &cstat); 
       if (ostat.st_mtime > cstat.st_mtime) 
       {  
           echo "compiling $c to $o"; 
           gcc -c -o "$o" "$c"; 
       } 
   } 

To plot a sine wave:

  #include 
  #include 
  int main() {
       int numpoints = 36;
       array double x[numpoints], y[numpoints];
       linspace(x, 0, 360); // assign x with values from 0 to 360 linearly
       y = sin(x*M_PI/180);
       plotxy(x, y, "Ch plot", "xlabel", "ylabel");
   }

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.