Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Expression builder
Hi all,

I am trying to create an expression builder dialog, which can handle
logical, mathematical as well as relational operator queries.

There is an entry widget where the user can enter the query/expression.
Does anyone know of any easy way to do this, instead of parsing the
string and doing push and pop stack procedure to calculate.

The expression builder needs to handle +, -, *, /, <, >, <>, !, &&, ||,
like, (, ).

Any help is papreciated.

Thanks in advance.


Report this thread to moderator Post Follow-up to this message
Old Post
Mona
04-01-05 01:58 AM


Re: Expression builder
Mona wrote:
> Hi all,
>
> I am trying to create an expression builder dialog, which can handle
> logical, mathematical as well as relational operator queries.
>
> There is an entry widget where the user can enter the query/expression.
>  Does anyone know of any easy way to do this, instead of parsing the
> string and doing push and pop stack procedure to calculate.
>
> The expression builder needs to handle +, -, *, /, <, >, <>, !, &&, ||,
> like, (, ).

How about :
set result [expr $enteredExpression]

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester               | "The man who fights for his ideals is |
| Gerald.Lester@cox.net          |  the man who is alive." -- Cervantes  |
+--------------------------------+---------------------------------------+

Report this thread to moderator Post Follow-up to this message
Old Post
Gerald W. Lester
04-01-05 09:00 AM


Re: Expression builder
"Gerald W. Lester" <Gerald.Lester@cox.net> wrote in message
news:th13e.49364$Az.38522@lakeread02...
> Mona wrote: 
>
> How about :
>      set result [expr $enteredExpression]
Seems Mona is looking for a parse tree rather than the
answer.
Looks like there's a good start in Tcl code
on the wiki.
http://mini.net/tcl/3498

>
> --
> +--------------------------------+---------------------------------------+
> | Gerald W. Lester               | "The man who fights for his ideals is |
> | Gerald.Lester@cox.net          |  the man who is alive." -- Cervantes  |
> +--------------------------------+---------------------------------------+



Report this thread to moderator Post Follow-up to this message
Old Post
Roy Terry
04-01-05 09:00 AM


Re: Expression builder
Hi all,

Thanks for the reply.

I would like to compare a variable with the expression builder string
and perform some operations.  My problem is how do I insert the
variable in the expression string?
So, the expresion need to be something like
[("my_variable" > "somevalue") && ("my_variable" < "othervalue")].

Something like a database query.

Mona.




Arjen Markus wrote:
> Roy Terry wrote: 
handle 
query/expression. 
parsing the 
&&, ||, 
>
> Yet another one, which builds on the parsing technique used by [expr]
> itself
> is here: http://wiki.tcl.tk/13399
>
> Regards,
>
> Arjen


Report this thread to moderator Post Follow-up to this message
Old Post
Mona
04-01-05 09:01 PM


Re: Expression builder
"Mona" <impm01@yahoo.com> writes:

> I would like to compare a variable with the expression builder string
> and perform some operations.  My problem is how do I insert the
> variable in the expression string?
> [("my_variable" > "somevalue") && ("my_variable" < "othervalue")].

If I read you right, $my_variable is an expression...

Instead of:

if { ($my_variable > $somevalue) && ($my_variable < $othervalue) } {...

use:

if " ($my_variable > $somevalue) && ($my_variable < $othervalue) " {...

That will pre-expand the variables before expr looks at them.

Or were you talking about string comparisons?

--
Donald Arseneau                          asnd@triumf.ca

Report this thread to moderator Post Follow-up to this message
Old Post
Donald Arseneau
04-02-05 01:58 AM


Re: Expression builder
Mona wrote:
>
> Hi all,
>
> Thanks for the reply.
>
> I would like to compare a variable with the expression builder string
> and perform some operations.  My problem is how do I insert the
> variable in the expression string?
> So, the expresion need to be something like
> [("my_variable" > "somevalue") && ("my_variable" < "othervalue")].
>
> Something like a database query.
>

If I understand you correctly, then you want to add a $ to every
variable name?

Well, the simplest way would be:
1. Maintain a list of variable names (or assume anything text that is
not quoted is a variable name)
2. Exploit [regexp] or [string map] to convert the raw but
non-Tcl-programmer-
friendly string into a proper Tcl [expr] expression.

If you want an example that may be beyond your needs, then have a look
at:
http://wiki.tcl.tk/11379 or http://wiki.tcl.tk/2822.

Otherwise:

set raw_expr {v > "a" && v < "m"}
regsub -all {([^"]|^)([a-zA-Z]+)} $raw_expr {$\2} converted_expr
set v "b"
expr $converted_expr

(Note: the regular expression is too simple - it fails with " m " for
instance :()

Regards,

Arjen

Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
04-06-05 05:26 PM


Re: Expression builder
Thank you all for your replies.
The wiki tcl pages were a great help.
Thanks again.
Mona.


Report this thread to moderator Post Follow-up to this message
Old Post
Mona
04-28-05 01:59 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:59 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.