Programming in Chinese: Explain the running program design in Taiji language (sequence)

Source: Internet
Author: User

Programming in Chinese: Explain the running program design in Taiji language (sequence)

Quick Start:

Save the following example Program
Input
Tai chi file name
You can run it.

For example, if the file is saved as "day ",
Input
Taiji day
You can.

Of course, go to my website (http://taiji9.getbbs.com) to download the Taiji interpreter.

1.
Display ("Tai Chi"); // display "Tai Chi"

2.
Integer A; // defines the integer variable A, which is actually a memory allocation unit)
A = 9 + 2; // assign a value to;
Display (a); // display;

Integer A; // defines the integer variable.
A = 9 + 2; // assign a value to;
Display (a); // display;

3.
// From // to the end of the line is a comment, which will be skipped by the compiled program directly without input. The comments between/* and */are also
Integer A; // defines the integer variable A, which is actually a memory allocation unit)
A = 9; // assign a value to;
Integer B;
B = 10; // defines B and assigns a value of 10;
B = a + 2; // now B is 11.
A = A + B;
// The original value of A + the value of B, and the result is assigned to a; A is 21 now;
A = a + 1; // What is a now?

A = a * B-a-B; // now,
// * Is multiplication,/is division, and % is the remainder of division.

 

4.
Integer;
A = 2;
Star:; // number, any value
A = a + 1;
Display ();
Flying Stars; // The Flying Club controls the program process to jump to a specified place.

This program will go through infinite loops, and press Ctrl + C to terminate.

Change:
Integer;
A = 2;
Star:; // number, any value
A = a + 1;
Display ();
Flying (A <10) stars; // jump only when the conditions are met

----------------------------------------------------
Variable name naming rules: the first word is Chinese character, English name, or underscore _, followed by Chinese characters, English names, or underscores _ or numbers.
If the first word is a number, it is considered a number rather than a variable name.
Future function name, class name ...... This rule also applies.
-----------------------------------------------------

5.

Integer I;
I = 0;
/* Note: When (I <10), the loop is in. Until I> = 10.
Check whether the conditions are met after each loop. */
Loop (I <10)
{
Display (I );
I = I + 1;
};

Format: loop (condition)
{
....
}
Think about: how to implement the same functions with flying?

6.

// Calculate 0 + 1 + 2 + 3 + ...... + 10;
Integer I;
I = 0;
Integer J; j = 0; // define J and save the result.
Loop (I <= 10) // loop to 10;
{
J = J + I; // J is sequentially added with I increasing by 1.
Display (j );
I = I + 1;
};

Think about it:
(1) sum: 1 + 2 + 3 + ...... + 100
2 + 4 + 6 + ...... + 100
1*1 + 2*2 + 3*3 + ...... + 100*100

(2) implement this program with "fei"

7. pointer
/*
Computer memory units are arranged one by one,
The number of sequential numbers arranged by each unit is the address of this unit,
The content of a unit storage is called the value of a unit.

A unit can store any number,
Of course, you can store the addresses of other units (also a number)
This is called a pointer because its value points to another unit.
*/

The data definition method is
Type variable name;
Therefore

Integer A; A = 8;
Integer * pA; // defines the integer pointer Pa. The integer * is regarded as a type.
Pa = & A; // PA points to a, and the value of PA unit is the address of.
// For example, it may be 24000010; this is related to the system.
// Assign a certain memory unit to the variable when defining it.
* PA = 9; // obtain the memory unit pointed to by PA. The value is 9;

Integer ** PPA; // The integer ** is regarded as a type.
PPA = & PA; // PPA is a pointer to the pointer Pa.
** PPA = 7;
Display ();
Display (* pA );
Display (** PPA );

 

8. Functions
Integer accumulation (integer N) // Return Value Type Function Name (parameter)
{// Calculate 0 + 1 + ...... + N;
Integer I = 0;
Integer J = 0;
Loop (I <= N)
{
J = J + I;
I = I + 1;
}
Return to J; // return the value of J;
}
Accumulate (20); // call a function. 20. Call the function.
Integer K;
K = accumulate (100); // the return value is assigned to K;

Using Functions improves code reusability.
Format:
Return Value Type Function Name (parameter)
{
.....
}

Integer Exchange (integer * P1; integer * P2)
{// Swap the values of memory units pointed by P1 and P2.
Integer I;
I = * P1; // the value that P1 points. Save it.

* P1 = * P2; // P1 indicates that P2 is assigned
* P2 = I;
}

Integer;
A = 2;
Integer B;
B = 3;
Exchange (& A; & B );
Display ();
Display (B );

The following is a function that cannot complete the switching function.
Exchange (integer a, integer B)
{
Integer I;
I =;
A = B;
B = I;
}
Integer x; X = 2; integer y; y = 3;
Exchange (x, y );

Each variable corresponds to a memory unit, including function parameters. Variables in each independent region do not involve each other, and duplicate names are irrelevant.
For example, the value of x (x, y) above is transmitted to parameters a and Y in the mother of the switching function to B. So how to exchange A and B is not related to X and Y.
The one behind the scenes won't work even with the same name.
After the execution enters the function body, the memory unit is allocated to the variable in the function body.
After the function is returned, all its variables are released.

 

Get keyboard input characters:
Character;
A = press the key (); // click the button to return to the key value.
Display ();

9. Judgment
Character;
A = Key ();
If (A = 'y ')
{Display ("yes ");}
If (A = 'n ')
{Display ("no ");}
If (A = '? ')
{Display ("why ");}
Another
{
If (A = 'k ')
{Display ("aaaaaaaaaaa ");}
Else
{Display ("Bu zhi dao ");}
}
Display ();

Try it and you will understand it.
This is what people say. Is the meaning of words.
The character is enclosed in single quotes, and the string is enclosed in double quotes.

Character;
A = Key ();
Select ()
{
Condition ('y ')
{Display ("yes ");}
Condition ('n ')
{Display ("no ");}
Default
{Show ("??? ");}
}

If you press a key other than Y and N, the default value is used)

10. Loop Control:
Integer;
A = 2;
Loop (A <10)
{
Display ();
If (A = 8)
{Continued ;}
A = a + 1;
}
Continue to jump to the beginning of the loop.

Integer;
A = 2;
Loop (A <10)
{
Display ();
If (A = 8)
{Disconnected ;}
A = a + 1;
}
Break is a bounce Loop

11. Array
Integer [10] A; // defines array A, containing 10 Integer Variables
A [0] = 1; // The 0th variables of A are assigned a value of 1.
Integer I; I = 0;
A [I] = I * I;
Display (A [I]);
Loop (I <10)
{
I = I + 1;
A [I] = I * I; // assign a value to the I variable
Display (A [I]);
}

 

12. Recursion
Integer accumulation (integer N)
{
If (n = 1)
{To 1 ;}
Integer R;
R = accumulate (n-1) + N;

R;
}
Integer K;
K = accumulate (5 );
Display (k );

13. String
Integer String Length (character * Str)
{
Integer I;
I = 0;
Display (STR [I]);
Loop (STR [I]! = 0)
{
Display (STR [I]);
I = I + 1;
}
Return to I;
}
Character * STR;
STR = "aaaaaaaaaaa ";
Integer K;
K = String Length (STR );
Display (k );

14. Class
Students
{
Character * Name; // defines the member variable
Integer age;
Integer height;
};

Student Chen; // defines a class instance
Chen. Name = "Chen"; // assign values to member variables
Chen. Age = 25;
Student * pcw; // pointer
Pcw = & Chen;
Pcw-> Height = 170; // access member variables through pointers

Display (Chen. Name );
Show (Chen. Height)

 

Class chain
{
Integer;
Chain * P;
};
Chain C1;
Chain C2;
C1.p = & C2;
C2.p = & C1;
C1.a = 9;
C2.a = 8;
Display (c1.a );
Display (c1.p-> P-> );

 

------------------------------
Interpreter system features:

1.
Integer;
Integer B;
Integer C;
Runcode (a = 1; B = 2; C = 3); // run the code in ()
C = C +;
Display (C );

2.
Integer;
Integer B;
Integer C;
Character * STR = "A = 1; B = 2; C = 3 ";
Runstr (STR); // code pointed to by the character pointer variable in running ()
C = C +;
Display ();
Display (C );
STR [2] = STR [2] + 1; // dynamically change the code.
Runstr (STR); // code pointed to by the character pointer variable in running ()
Display ();

------------------------

In this preface, I briefly explained that it should be easy to get started. You can use the knowledge and code accumulation of C/C ++ in Taiji language.

My csdn blog:
Http://blog.csdn.net/universee
At present, the Taiji language interpreter has not been strictly tested. If you find any problem, go to my blog and reply to me.
2006.4.22 night

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.