Publish the Taiji language interpreter

Source: Internet
Author: User
Tags filetime
Publish the Taiji language interpreter
 
 

Publish the Taiji language interpreter
(Released on July 15, March 29, the first year of Taiji)

I first published an interpreter for some of the Taiji language to explain how to run some Taiji language programs.
I focus on the Compilation part, but it hasn't been completed yet, but the interpreter is easy to do. Now I want to release part of it first.

Save the following example program as tj1.u, tj2.u ...... File,
Input
Taiji tj1.u
Taiji tj2.u
......
You can run it.

Example 1.
Int leijiahe (int n)
{
Int I; I = 0;
Int J; j = 0;
While (I <= N)
{
J = J + I;
I = I + 1;
}
Return J;
}
Show (leijiahe (20); // display
Show (leijiahe (21 ));

Int K;
K = leijiahe (10 );
Show (k );

Example 2.
Void swap (int * P1; int * P2)
{
Int I;
I = * P1;
* P1 = * P2;
* P2 = I;
}

Int A; A = 2;
Int B; B = 3;
Swap (& A; & B );
Show ();
Show (B );

Example 3.

Type student
{
Char * Name;
Int age;
Int high;
};

Student Chen;
Chen. Name = "wei ";
Chen. Age = 26;
Student * pcw;
Pcw = & Chen;
Pcw-> high = 170;
Show (chenwei. Name );

......

I will write an article to fully teach the Taiji language from scratch.

Why am I releasing this interpreter so early?

See the following C/C ++ code:

Int id = tj_compile (STR );
Tj_setmemberint (ID, "X", X );
Tj_setmemberint (ID, "Y", X );
Tj_run (ID );
Int z = tj_getmemberint (ID, "Z ");
Tj_compile and other functions are all export functions. I have implemented these functions in the dynamic link library.

Can you guess what this is?

For example, STR is
"Int X ;/
Int y ;/
Int Z ;/
Z = x * x + y * Y ;"

I will comment out the above Code:
Int id = tj_compile (STR );
// Compile this string
Tj_setmemberint (ID, "X", X );
Tj_setmemberint (ID, "Y", X );
// Set X and Y
Tj_run (ID );
// Run,
Int z = tj_getmemberint (ID, "Z ");
// Get the Z value!

In this way, the interpreter can interact with the application!

Let's look at another one:

Char * STR;
Int color;
Int bkcolor;

Int RGB (INT red; int green; int blue)
{
Int C;
C = red + green * 256 + blue * 256*256;
Return C;
}

Color = RGB (0; 0; 0 );

Bkcolor = RGB (255; 255; 255 );

If (dllcall ("kernel32.dll"; "lstrcmp"; STR; "while") = 0)
{
Color = RGB (0; 0; 255 );
Bkcolor = RGB (208; 12; 243 );
}
Elseif (STR [0] = 'I ')
{
Color = RGB (255; 255; 255 );
Bkcolor = RGB (208; 12; 243 );
}
Elseif ('0' <= STR [0] & STR [0] <= '9 ')
{
Color = RGB (255; 0; 0 );
Bkcolor = RGB (255; 255; 255 );
}

"Tai Chi Bao Jian" is the development environment of Tai Chi Language in the future. This is the Alipay authentication configuration file (conf.txt). You can set the display color by modifying this file! Here, the while character is set to the blue character at the bottom of the purple, all words starting with I are white words at the bottom of the purple, and numbers are white-colored characters at the bottom of the red. Now you can open Tai kaizaojian and try it. You can try to modify this file by yourself. I have done a program that can set colors freely before, but the setting of this program has reached this level!

You can think about the running situation in the Taiji baojian program --
This is a piece of C ++ code:
......
Int id = tj_compile (strfile );
Tj_setmemberstr (ID, "str", str1); // str1 is to be displayed
Tj_run (ID );
Color = tj_getmemberint (ID, "color ");
Bkcolor = tj_getmemberint (ID, "bkcolor ");
Show (HDC, X, Y, STR, Len, color, bkcolor );
......

Why is the STR in the configuration file program of Taiji baojian used before preliminary testing? Does tj_setmemberstr exist before tj_run? This is to assign the initial value to str. tj_compile is to compile and initialize the global namespace. The Taiji language interpreter fully communicates with applications. Tai chi baojian can be configured freely through the Tai Chi Language Interpreter. This is widely used. For example, you can use an Offline Browser or batch download software to provide users with a method to determine the format of a URL to be downloaded.

Int id = tj_compile (userconfigfile );
Tj_setmemberstr (ID, "str", currenturl );
Tj_run (ID );
Match = tj_getmemberint (ID, "match ");
If (MATCH)
Download (currenturl );

Userconfigfile is the content of your own configuration file. You can use the Taiji language to determine whether to download the file. You can use the class C/C ++ to determine the URL.

Here is an example:
Type filetime
{
Int A1;
Int A2;
};
Type win32_find_data
{
Int dwfileattributes;
Filetime ftcreationtime;
Filetime ftlastaccesstime;
Filetime ftlastwritetime;
Int nfilesizehigh;
Int nfilesizelow;
Int dwreserved0;
Int dwreserved1;
Char [260] cfilename;
Char [14] calternatefilename;
};
Win32_find_data WFD;
Int HL;
Hl = dllcall ("kernel32.dll"; "findfirstfilea"; "*. *"; & WFD );
Show (WFD. cfilename );
While (dllcall ("kernel32.dll"; "findnextfilea"; HL; & WFD )! = 0)
{
Show (WFD. cfilename );
Show ("/N ");
}
After running, all files in the current directory are displayed.

Tai chi baojian supports macro operations. Now you Press F1, press a few more keyboards, and then press F2. What happened?
F1 is the start recording macro, F2 is the playing macro, and then press F1 to stop recording.
Now you can think about how it works.

The only macro is stored in the "input.txt" file in the directory where the Taobao website authentication .exe "is located. open the file and see:
Int ID;
Dllcall (". dll"; "input"; ID; 97 );
Dllcall (". dll"; "input"; ID; 97 );
Dllcall (". dll"; "input"; ID; 113 );
......

Change this file
Int ID;
Int I; I = 97;
While (I <97 + 26)
{
Dllcall (". dll"; "input"; ID; I );
I = I + 1;
}
Press F2 again. What do you see? 26 letters from A to Z.

Dllcall is a function in the DLL.
There is a code just now:
If (dllcall ("kernel32.dll"; "lstrcmp"; STR; "while") = 0 )......
This is the lstrcmp function that calls kernel32.dll.

See dllcall (". dll"; "input"; ID; 113 ):
Input is a function in Taiji baojian. dll.
Taijidllr. dll ---> taijbao jian. dll ---> ta Bao Jian. .exe
Data is transmitted among these modules, and taijidllr. dll explains the Taiji language code.

In this way, any software can quickly establish a macro mechanism! All you need to consider is to generate macro code.
Then call the Taiji language to explain the operation, and use the DLL call in the macro to control the program itself.

See the following code.
# Include
Extern "C"
{
Int _ declspec (dllimport) _ stdcall tj_compile (char * Str );
Int _ declspec (dllimport) _ stdcall tj_run (int id );
Int _ declspec (dllimport) _ stdcall tj_setmemberint (int id, char * Name, int N );
Int _ declspec (dllimport) _ stdcall tj_setmemberstr (int id, char * Name, char * Str );
Int _ declspec (dllimport) _ stdcall tj_getmemberint (int id, char * Name );
Char * _ declspec (dllimport) _ stdcall tj_getmemberstr (int id, char * Name );
Int _ declspec (dllimport) _ stdcall tj_runstr (int id, char * Str );
}
# Pragma comment (Lib, "taijidllr. lib ")
Main ()
{
Char * STR =
"Int X ;"
"Int y ;"
"Y = x * X ;";

Int id = tj_compile (STR );
Tj_setmemberint (ID, "X", 3 );
Tj_run (ID );
Int y = tj_getmemberint (ID, "Y ");
Printf ("Y = % d", y );
}

How can I implement the macro mechanism? Also, can you think of how to use the last function in the declaration?

The following code is used in Taiji baojian.
When record keys:
If (remember)
{
Char * STR = new char [200];
Sprintf (STR, "dllcall (/". dll/";/" Input/"; ID; % d);/R/N", key );
File_addline ("input.txt", STR );
};
(Generate macro program)

Playback buttons:
Int id = tj_compile (STR );
Tj_setmemberint (ID, "ID", (INT) This );
Tj_run (ID );
(Compile and run the macro program. This points to the current window class instance)

Run will encounter such code:
Dllcall (". dll"; "input"; ID; 97 );
Call the Input Function in Taiji baojian. dll.
The C ++ source code of the Input Function in Taiji baojian. dll is as follows:
Extern "C" int _ declspec (dllexport) _ stdcall input (int id, char key)
{
Wintj * ptj = (wintj *) ID; // current window class instance
Ptj-> input (key );
Return 1;
}

In this way, any software can quickly establish a macro mechanism! Moreover, macros are used in the Taiji language! It is basically compatible with C/C ++. The syntax is the same as that of C/C ++, and the description is very free. Your C/C ++ library can be used as a macro function library! I think this is much better than Microsoft's VBA, right? In the future, Microsoft's Visual Studio, MS office, and so on will use Taiji language for macro mechanisms ...... Ha, that's great!

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

 

: Http://taiji9.getbbs.com/
Http://free3.getbbs.com/Post/Topic.aspx? Bid = 16994 & tid = 30240

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.