Click here to Skip to main content
15,886,018 members
Articles / Programming Languages / C++

Building a simple C++ script compiler from Scintilla and CINT

Rate me:
Please Sign up or sign in to vote.
4.73/5 (25 votes)
8 Jul 2006CPOL7 min read 153.9K   7.6K   85  
How to build a simple C++ script compiler from Scintilla and CINT.
lib/wintcldl/README

 This directory includes WildCard interpreter, a marriage of C/C++ and Tcl/Tk
interpreters.  Now it works on HP-UX, Linux and Windows-NT/9x. UNIX version
is in lib/WildCard directory. This directory is dedicated to Windows-NT/9x
environment using Visual C++ 4.0. Compilation environment for Symantec C++
7.2 is obsoleted (just because IMPORTS statement in WILDC.DEF file is 
incomplete now).

 For Tcl/Tk8.3 version, go to /lib/wintcldl83.

What you need:=============================================================

 What you need to run WildCard are

    + Windows-NT or Windows-9x operating systems
    + Tcl7.5/Tk4.1 
    + cint revision 5.11.32 or later
    + Visual C++ 4.0/5.0/6.0

Compile: ==================================================================

 1) Install CINT
   Please refer to ../../README and ../../platform/README to install CINT.

 2) Install Tcl7.5/Tk4.1.
   You need to get Tcl7.5/Tk4.1 or later. It can be get from Sun-Microsystem's
  ftp site. This package is a self-extracting archive. Use file manager to 
  run the package, then setup program will start. Please install it to C:\TCL
  directory (this is the default).

          ftp://ftp.smli.com/pub/tcl/win41p1.exe

 3) Run C:\CINT\LIB\WINTCLDL\setup.bat
   Run SETUP.BAT from DOS prompt.

 4) Adding path
   Edit C:\AUTOEXEC.BAT using notepad or other text editor. Please add 
  following lines at the end.

   SET PATH=%PATH%;C:\CINT\LIB\WINTCLDL;C:\TCL\BIN

 5) Re-boot or re-login. 


What WildCard can do ======================================================
 WildCard has full functionality of CINT and Tcl/Tk interpreters. You can
enjoy 100% compatibility from cint and wish in one environment. Take a look
at wildc.wc and calc.wc examples. To start wildc interpreter, use following
command.

  $ wildc wildc.wc

To monitor what is going on

   $ wildc -T wildc.wc

Be careful that wildc is a batch command.


WildCard Commands ========================================================

How to start WildCard:
	WildCard interpreter can be started by 'wildc' command. You can give
	mixed C/C++ and Tcl/Tk script. WildCard interpreter usually accepts
        source code with .wc extension.

    Example:
	$ wildc grcalc.wc            # starts C/C++ interpreter


How to debug WildC script:
        You can give -S, -s, -t, -T and -b debug option to the wildc. 
        Debugger works in the same way as CINT. You can set break point, 
        step through and trace your source code.

    Example:
        $ wildc -S grcalc.wc

        You MUST USE 'p WildCard_Exit()' to terminate process in the debug
        mode. Otherwise, behavior is not guaranteed.

    Example:
        wildc> p WildCard_Exit()


In Tcl:

  ceval {C/C++ expression}
	ceval can be used in Tcl/Tk script to evaluate C/C++ expression. 
	Result is returned as form of string.

    Example:
	ceval 1+2
	ceval printf("abc\n");
	button .b -text "button"
	bind .b <Button-1> {ceval CallBack()}

In C/C++:

  #pragma tcl <interp> <link variable list>
  #pragma endtcl
	#pragma tcl statement starts Tcl/Tk interpreter. 
	If it appears within a function, Tcl/Tk script will be evaluated 
	when the function is executed.
	If it appears in a global scope, Tcl/Tk script will be immediately 
	evaluated. #pragma endtcl can be omitted in global scope. In this
	case, WildCard_MainLoop() is implicitly called to start X11 event
	loop.

    Example:
	f() {
	  #pragma tcl interp
	    # tcl/tk commands evaluated when f() is called
	  #pragma endtcl
	}
	#pragma tcl interp
	  # tcl/tk commands evaluated when source code loading
	#pragma endtcl
	#pragma tcl interp
	  # tcl/tk commands evaluated when source code loading 
	  # and implicitly calls WildCard_MainLoop() because #pragma
	  # endtcl is omitted.


	A parameter <interp> must be a valid Tcl_Interp* object. A global
	object 'interp' is preregistered in the WildCard environment for
	user's convenience.
	After the <interp> you can list up arbitrary number of C/C++ variables
	to link to Tcl/Tk interpreters. Variables must be type of int, double
	or char* and must be a simple object name. Variables are unlinked at
	#pragma endtcl.

    Example:
        f(char *color) {
	  static int i=0;
	  #pragma tcl interp color i
	    button -.b$i -text "Button Test" -bg $color
	  #pragma endtcl
	  ++i;
	}


  WildCard_MainLoop();
  WildCard_Exit();
	WildCard_MainLoop() and WildCard_Exit() are API function for the
	WildCard interpreter. WildCard_MainLoop() starts X11 event loop
	to get mouse and keyboard events. The events are handled by Tcl/Tk
	interpreter.
	WildCard_Exit() must be used to quit WildCard interpreter. exit()
	will not work.

    Example:
        void DrawGraphics() {
	  #pragma tcl interp
	    button .b -text "Exit"
	    bind .b <Button-1> {ceval Exit_CallBack()}
	    pack .b
	  #pragma endtcl
	}
        void Exit_CallBack() { WildCard_Exit(); }
	main() {
	  DrawGraphics();
          WildCard_MainLoop();
	}

  Tcl_xxx()
  Tk_xxx()
	The WildCard interpreter embeds all of the Tcl/Tk methods as 
	precompiled library. You can access Tcl/Tk intrinsics from
	C/C++ interpreter. You don't need to use them in most of the cases.

    Example:
        int i; 
	Tcl_LinkVar(interp,"i",(char*)(&i),TCL_LINK_INT);
	    // parenthesis around (&i) is needed in WildCard.


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions