mfc >> Adding very simple scripting to my app

by Vince » Sat, 22 Jan 2005 02:48:22 GMT

Hi,

I 'd like to know how could I add very simple scripting to my MFC
application(dialog based) that reads smart card info.
I just need to handle the following logic :


IF var1 == 10
{
IF (var2 & mask3)
{
DISPLAY "HELLO"
}
ELSE
{
DISPLAY "GOODBYE"
}
}

I just need a very simple logic (IF, ELSE, equal comparison operator).




mfc >> Adding very simple scripting to my app

by Jiangsheng[Microsoft MVP of VC++] » Sat, 22 Jan 2005 05:06:45 GMT


you can visit support.microsoft.com, and look for following KB articles:

Q223139 HOWTO: Add Support for Hosting VBScript to an ATL Application
Q183698 SAMPLE: AXSH.exe Demonstrates Implementing ActiveX Script Hosts
Q168214 SAMPLE: MFCAxs.exe Implements an ActiveX Script Host Using MFC
Q223389 FILE: Scriptng.exe Contains the Files Necessary for Implementing
ActiveX Script Hosts and Engines
Q232394 HOWTO: Catch Run-time Errors in an ActiveX Script Host

Knownage Base Keyword: kbAXScript


"Vince" < XXXX@XXXXX.COM > :41f14dcc$0$15524$ XXXX@XXXXX.COM ...





mfc >> Adding very simple scripting to my app

by Joseph M. Newcomer » Sat, 22 Jan 2005 08:13:26 GMT

You could probably write this code in an afternoon, if you are a slow coder. A simple
language with nested if-then-else isn't hard (include an endif, fi, or some other
terminator and your job is much easier). I once wrote a scripting language not dissimilar
to this in five hours. A simple recursive-descent parser and a tirival tokenizer can give
you a tree you interpret, then you just do an LRN treewalk. If I weren't leaving on Sunday
for a couple weeks, I'd have time to find an old piece of code I wrote, but it is backed
up to 5 1/4" floppies and I don't have a machine that can read them any longer.

Here's the sketch:

write a simple FSM parser that recognizes words like IF, identifiers, constants, and
operators. It should return something like this

class lexeme{
public:
CString token;
};
class op : public lexeme{
public:
op(const CString & name) { token = name; }
};

and from this

class plus : public op {
public:
virtual void Execute() {
int a = stack.pop();
int b = stack.pop();
stack.push(a + b);
};

and so on.

class keyword : public lexeme{
public:
keyword(const CString & name) { token = name; }
};

class identifier : public lexeme{
public:
identifier(const CString & name) { token = name; }
void Execute() { stack.push(lookup(token)); }
};

Now this sketch obviously skips over error handling and other niceities; that's why it
takes an afternoon instead of an hour. Use throw to handle errors; if there is a script
error, do something like

class CScriptExeception : public CException { }

and have subclasses for undefined variables, divide-by-zero, and all the usual cases you
might care about.

class constant : public lexeme{
public:
identifier(const CString & name) { token = name; }
};

class Tree {}
class BinaryOp : public Tree {
public:
Tree * left;
Tree * right;
op * operator;
};

class UnaryOp : public Tree {
public:
Tree * left;
};

class Leaf : public Tree {
public:
lexeme * leaf;
}

Now you can add to those tree nodes a virtual method execute(); for a binary node, it
turns out to be
virtual void Execute() {
left->Execute();
right->Execute();
operator ->Execute();
};

I hope this helps. Otherwise you have a fairly long task to integrate VBScript,
JavaScript, etc. into your app, which in your case doesn't sound justified.
joe





Joseph M. Newcomer [MVP]
email: XXXX@XXXXX.COM
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


Adding very simple scripting to my app

by Bill Thompson » Sat, 22 Jan 2005 10:27:49 GMT

Once you've used yacc, you never go back



Adding very simple scripting to my app

by Vince » Sun, 23 Jan 2005 03:47:18 GMT

hanks Joseph.
I wish you still had the code.
But now I know what to look for and I agree with you about MS script.



This is exactly what I was
"Joseph M. Newcomer" < XXXX@XXXXX.COM > a rit dans le message de
news: XXXX@XXXXX.COM ...




Similar Threads

1. Scripting (ECMA script) solution for .NET app? - CSharp/C#

2. Simple Query 4.33 - add user-friendly query builder in your app

3. add class - add simple atl object - name and location grayed out

4. is there a very simple script interpreter?

Hi,

I would like to make my application's configuration very customizable. So I
thought it would be suitable to make a configuration file where I could
specify command execution steps.

for example, when user clicks on the command "Get Amount", the program looks
up the configuration file to find that this command maps to a custom script
that could look like:

    \\ Direct execution to check if
    \\ the function "UserExists()" is true.
    IF [UserExists]
        \\ direct the execution to the function "GetAmountDialog()" in the
current assembly
        [GetAmountDialog]
     ELSE
        \\ call "AnotherFunction()"
        [AnotherFunction]

The script is very simple and only directs executions using if-else
identifiers.
If anyone has ideas on how to implement such functionality, I would
appreciate so much.


5. Csharp simple script interpreter - CSharp/C#

6. How to expose a simple class to scripting?

Hi. I have a simple generic class in C++ (i.e. not derived from ATL or
MFC), and I want it to support IDispatch so it will be available to
scripting engines. But I do not want it to be a coclass, neither to be
createable with CoCreateInstance or have a CLSID. I want it only to be
returned by some other methods of mine.

I derive from IDispatchImpl, but there is no IUnknown implementation.
I do not want to replace in my code CClass *x with CComObject<CClass>
*x, neither to create new objects with
CComObject<CClass>::CreateInstance(), I want to create new objects
simply, with "new". And when needed, I would like to cast them to
(IDispatch*), and expose them outside.

Any ideas how could I do it?

Well, in fact, if I write implementations in the class for IUnknown's
3 methods, it works. But I have to write it in every class that I want
to be exposed to automation. Could you show me how to write a
template, something like IUnknownImpl<IInterface, &IID_IInterface>,
from which to derive (besides deriving from IDispatchImpl) ? I'm going
crazi trying to write this template class.

Thanks.

7. Calling a Script Function from C# WebBrowser App? - CSharp/C#

8. calling php script from winform app

Hi,

Can someone please tell me how to call a php script 
residing on our server from a Windows Form application 
without launching a browser?

At present I am using Process.Start(link), however I was 
wanting to do this 'silently'.

Thanks,
George.