473,589 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design question (specifically, script interpreter)

I am an experienced C programmer, learning C++ by writinging a
mathematical toolkit in the framework of a script interpreter. I am
posting here to ask for advice (or references) on the object design
and implimentation.

Currently I have a portable "ScriptSess ion" class which contains the
mechanics of looping with a user prompt, parsing a sentence and
handling syntax errors, etc., and I wan this to be a class I can use
for any script interpreter.

One of the core functions is the execution of a command sentence. This
necessarily involves some mathematical commands which should not be
part of "ScriptSess ion" so I started by overloading a method called
interpret, which is virtual in the base class:

class ScriptSession
{
public:
...
virtual bool ScriptSession:: execute(void);
}

I have then written a method within the final application which
overload this, but it needs to know a lot about the internals of the
ScriptSession class so it has become rather ugly and feels like it is
voilating encpasulation and so on. Also, I have put everything in
here, even basic stuff like interpretation of the command "exit" which
is universal, so that won't do.

I bought "Design Patterns" (Gang of Four) but none of the patterns
seem to really fit this nicely. Or maybe I'm just missing some of the
important stuff. I apologise if I haven't explained the problem
clearly enough; that's part of the problem of course.

Any advice would be appreciated. Thanks,
Ian Giblin.
Jul 22 '05 #1
4 1977
Ian Giblin wrote:
I am an experienced C programmer, learning C++ by writinging a
mathematical toolkit in the framework of a script interpreter. I am
posting here to ask for advice (or references) on the object design
and implimentation.
The first thing to recommend that comes to mind is comp.object
newsgroup. OO Design has common principles that are not necessarily
language-specific. Check it out.
Currently I have a portable "ScriptSess ion" class which contains the
mechanics of looping with a user prompt, parsing a sentence and
handling syntax errors, etc., and I wan this to be a class I can use
for any script interpreter.

One of the core functions is the execution of a command sentence. This
necessarily involves some mathematical commands which should not be
part of "ScriptSess ion" so I started by overloading a method called
interpret, which is virtual in the base class:

class ScriptSession
{
public:
...
virtual bool ScriptSession:: execute(void);
I thought you said "a method called interpret"... And a small note on
C++ syntax: you don't need a fully qualified name in a class definition.
You usually write

virtual bool execute();

(oh, yes, 'void' is also superfluous).
}

I have then written a method within the final application which
overload this,
The correct term is "overrides" .
but it needs to know a lot about the internals of the
ScriptSession class so it has become rather ugly and feels like it is
voilating encpasulation and so on.
Yes, it rather sounds like a bad design.
Also, I have put everything in
here, even basic stuff like interpretation of the command "exit" which
is universal, so that won't do.
Well, without seeing more of your 'ScriptSession' class (at least its
interface, the implementation probably doesn't matter much) it is not
clear what you mean that it needs to know and what exactly are those
"internals" . Can't you provide access to those internals through some
protected functions?
I bought "Design Patterns" (Gang of Four) but none of the patterns
seem to really fit this nicely. Or maybe I'm just missing some of the
important stuff. I apologise if I haven't explained the problem
clearly enough; that's part of the problem of course.
"Design Patterns" is by no means a "recipes for all occasions" type of
book. You learn the most common ones so you can recognise patterns in
your own code and describe them and later apply them.
Any advice would be appreciated. Thanks,
Ian Giblin.


Well, take a look at comp.object and possibly ask them for an example
of an interpreter framework that you could extend. Perhaps somebody
here knows about it too (I don't), my colleagues whenever an interpreter
is needed all wrote their own, which seems like an overkill, but that's
up to them.

Shake the Web (or google for "interprete r C++ framework"), see if
something falls out. I bet other folks have written something in that
area. While it is a good idea to write one for training, it isn't so
good to get stuck on design when your actual goal is the language.

Take a look at "Advanced C++. Programming Styles and idioms" by James
Coplien. It's relatively old, but it's a good from design point of
view. Helped me to figure some C++ stuff out. It assumes you know C++
to some extend, of course.

Good luck! If you decide to continue trying to figure out your stuff
here, in comp.lang.c++, I strongly recommend making more specific
questions, a generic topic like "I want to create an interpreter and I
am stuck, help!" calls for a book rather than a newsgroup message.

V
Jul 22 '05 #2
Ian Giblin wrote:
I bought "Design Patterns" (Gang of Four) but none of the patterns
seem to really fit this nicely. Or maybe I'm just missing some of the
important stuff. I apologise if I haven't explained the problem
clearly enough; that's part of the problem of course.


Dr. Phlip Rx's /Refactoring to Patterns/ by Josh Kerievsky.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Jul 22 '05 #3
Thanks for the detailed response.

Victor Bazarov <v.********@com Acast.net> wrote in message news:<1drld.333 765$wV.15439@at tbi_s54>...

I thought you said "a method called interpret"...
Sorry. It annoys *me* when people make weird mistakes like that. So
now, I'm annoyed with myself for not spotting it when I check the
post.
And a small note on
C++ syntax: you don't need a fully qualified name in a class definition.
You usually write

virtual bool execute();

(oh, yes, 'void' is also superfluous).


<gulp> I see... I'll probably keep the 'void' because it reminds me
when I'm reading the code, but the class name prefix was a bit silly.

I'll take your other comments to heart. I will see how far I get with
this and ask on the object-oriented group if I cannot come up with a
good framework.

Regards, Ian.
Jul 22 '05 #4
Ian,

Its a bit hard to understand your problem, you've not posted
much code or information to work on.

However, you might want to look at TCL. Although this is implemented
in C ( I think), the basic model might be useful. TCL has a very regular
syntax so its easy to write an interpreter which can recognize the "command"
from the "options" and "data". Its then quite easy to add new commands
by writing a C/C++ package which implements the necessary pieces required
to register and execute the command. TCL provides the basic looping and
waiting for commands, then parses, checks for errros, and executes each
command or script you
pass in. TCL has a fairly complex API for accessing the guts of the
interpreter
and for implementing commands.

Python is also a model you could look at, as I remember, it was quite easy
to write an extension
(package of commands) to python in C/C++ ( or anything other language for
that matter ) and
load them into the python interpreter.

Hope that helps, and good luck.
dave
"Ian Giblin" <gi****@panix.c om> wrote in message
news:96******** *************** ***@posting.goo gle.com...
I am an experienced C programmer, learning C++ by writinging a
mathematical toolkit in the framework of a script interpreter. I am
posting here to ask for advice (or references) on the object design
and implimentation.

Currently I have a portable "ScriptSess ion" class which contains the
mechanics of looping with a user prompt, parsing a sentence and
handling syntax errors, etc., and I wan this to be a class I can use
for any script interpreter.

One of the core functions is the execution of a command sentence. This
necessarily involves some mathematical commands which should not be
part of "ScriptSess ion" so I started by overloading a method called
interpret, which is virtual in the base class:

class ScriptSession
{
public:
...
virtual bool ScriptSession:: execute(void);
}

I have then written a method within the final application which
overload this, but it needs to know a lot about the internals of the
ScriptSession class so it has become rather ugly and feels like it is
voilating encpasulation and so on. Also, I have put everything in
here, even basic stuff like interpretation of the command "exit" which
is universal, so that won't do.

I bought "Design Patterns" (Gang of Four) but none of the patterns
seem to really fit this nicely. Or maybe I'm just missing some of the
important stuff. I apologise if I haven't explained the problem
clearly enough; that's part of the problem of course.

Any advice would be appreciated. Thanks,
Ian Giblin.

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1792
by: #pragma once | last post by:
That's all we are expecting from programs written in the managed code; Though a MVP advised not to say that, because after JIT compilation the code runs in the native! Funny, isn't? That means scripting languages run in the Host code and never in the native? That means scripting languages are poorer than .NET in speed just because they are hosted by an interpreter? What about .Net run time libraries? Can any one tell me the differences?...
16
4736
by: fernandez.dan | last post by:
Hey I'm sorry if this is not the appropriate news group for this question. I was wondering if anyone has any recommendation for embbedding a script engine in a c++ application. I want to feed my C++ application scripts which based on the script would create C++ objects and call the appropriate methods. At the moment I created a simple interpreter within our C++ aplication that we can feed our custom scripts. The interpreter is primitive...
4
2067
by: Smriti Dev | last post by:
Hi There, I'm creating a MS ACCESS database using Ms Access 2000 to store Interpretation requests by different departments in a hospital and Interpreter availability. All internal departments will be calling in or faxing their Interpretation requests to Intake staff at the Interpretation department and the intake staff will feed the request into the database. However, their is one department, Rehab, that is going to be going to be able...
2
1411
by: HopfZ | last post by:
Is there a way to make a (cross-browser) javascript function that will open an existing webpage (for example, www.google.com) in a new window (or in some part of _self) and then load a specified user script? like this way: openWithUserScript( 'http://www.google.com', 'http://www.my_homepage.com/my_script.js' );
6
15026
by: Alan Isaac | last post by:
I'm fairly new to Python and I've lately been running a script at the interpreter while working on it. Sometimes I only want to run the first quarter or half etc. What is the "good" way to do this? Possible ugly hacks include: - stick an undefined name at the desired stop point - comment out the last half I do not like these and assume that I have overlooked the obvious.
5
10633
by: Joel | last post by:
In the course of my project, I must include some custom logic and would like to integrate a small script language in my application for that purpose. In C++, I used the LUA script language and I know that bindings exists for a LUA/c# integration, but only using the binary DLL. However, I would prefer a native c# solution and for a small language, not a huge interpreter like Python. Has anybody seen such implementation ? Thanks,
3
2334
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify the interpreter manually...look what it says: i've tried with /web/cgi-bin/php "$HOME/html/path/to/my/script.php as command and it doesn't work. if i run the script in browser it works...what should i introduce as a command..and do i have...
13
12782
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new scripting language that makes writing automated tests simpler. Really, I'm looking to kind of abstract the power of the C# language into a simpler language that's easier to learn. The script files would be interpreted by a script interpreter...
4
2822
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application. I want to be able to debug the Python script by using a debug server, like Winpdb (winpdb.org). I use ActivePython 2.5.2.2, Microsoft Visual Studio 2005, and Winpdb 1.3.8.
0
7931
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7865
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8233
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5731
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3849
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1198
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.