General purpose Expression Parser

I

Ioannis Vranos

Dexter said:
This Java based utility may be invoked from Java code to parse
mathematical expressions. It is useful for programmers developing
calculators, graphing utilities or other math related programs.

Download for free at http://www.thinkanddone.com/prog/java/parser.html

If the above link does not work try http://www.britishcomputercolleges.com/prog/java/parser2.html


An interview of the inventor of C++ templates, Alexander Stepanov, where
it mentions Java:

http://www.stlport.org/resources/StepanovUSA.html



An interesting link I came across the web:

http://icl.pku.edu.cn/bswen/_old_stuff/cpp/java-to-cpp.html
 
I

Ian Collins

Ioannis said:
An interview of the inventor of C++ templates, Alexander Stepanov, where
it mentions Java:
<EvenMoreOT>He didn't invent templates, he was the authour of the
Standard Template Library</EvenMoreOT>

What has this to do with C anyway?
 
I

Ioannis Vranos

Ian said:
<EvenMoreOT>He didn't invent templates, he was the authour of the
Standard Template Library</EvenMoreOT>


AFAIK he invented templates.
What has this to do with C anyway?


Nothing right now. However I think template functions and structs could
be introduced in C.
 
I

Ioannis Vranos

Ben said:
You can already use them in C++. There is no need for them in C.


So, whatever we can use in C++ needs not be provided in C. In other
words you are saying that C is obsolete.

Templates can replace elegantly C's generic programming which is now
done by using void pointers and indentifiers.
 
I

Ian Collins

Ioannis said:
So, whatever we can use in C++ needs not be provided in C. In other
words you are saying that C is obsolete.

Templates can replace elegantly C's generic programming which is now
done by using void pointers and indentifiers.

King 'ell not again!

You could say that any C++ feature would enhance C, when all you would
end up with is an early C++ compiler and you know where they ended up.
Templates lead to function over loading which leads to....

We all have our pet C enhancements, which can be suggested on comp.std.c.
 
R

Richard Tobin

You can already use them in C++. There is no need for them in C.
[/QUOTE]
So, whatever we can use in C++ needs not be provided in C. In other
words you are saying that C is obsolete.

Not at all. He's saying there's no point making C be the same
as C++. If you want C++, you know where to find it.

Of course, both positions are too extreme.

-- Richard
 
I

Ioannis Vranos

Ian said:
King 'ell not again!

You could say that any C++ feature would enhance C, when all you would
end up with is an early C++ compiler and you know where they ended up.
Templates lead to function over loading which leads to....

We all have our pet C enhancements, which can be suggested on comp.std.c.


Actually making "versions" inside a generic C function which uses void
pointers, for every type it can accept, I think is usually more bloated
code than providing a simple template function. Also the template one is
faster since it has not those conditional-specialisations.

A C programmer, as a C++ programmer does now, could control his code and
not let it become bloated.


In general, templates are more elegant (simpler) and more efficient than
bloated generic functions using void pointers and conditional statements
to determine the type(s) of object(s) passed.

Also they can replace macros in 99% of the times leading to more robust
code.


I think C can borrow these things from C++, as it has borrowed things
from C++ in the past (function prototypes etc).
 
C

CBFalconer

Ioannis said:
So, whatever we can use in C++ needs not be provided in C. In
other words you are saying that C is obsolete.

Don't be silly. You select a language to suit the job. If you
really need template functions use C++ or better languages (Ada,
for example). You probably don't need them.
 
C

CBFalconer

Ioannis said:
Ian Collins wrote:
.... snip ...

Actually making "versions" inside a generic C function which uses
void pointers, for every type it can accept, I think is usually
more bloated code than providing a simple template function. Also
the template one is faster since it has not those conditional-
specialisations.

You should take this to comp.compilers.lcc and join with Jacob
Navia. There it can be on-topic, and Jacob will agree with you.
Here it is off-topic, and virtually noone will agree with you.
 
S

santosh

CBFalconer said:
You should take this to comp.compilers.lcc and join with Jacob
Navia. There it can be on-topic, and Jacob will agree with you.
Here it is off-topic, and virtually noone will agree with you.

He *was* talking about standard C code, essentially saying that
functions accepting void * arguments and including separate code to
deal with all supported argument types is actually more bloated and
slow than code derived through some form of generics.

In pure C the closest one can come to type generic source code is
through the macro processor.
 
R

Richard Heathfield

Ioannis Vranos said:
So, whatever we can use in C++ needs not be provided in C. In other
words you are saying that C is obsolete.

CUSTOMER: "I'd like a knife and fork, please."
WAITER: "Here you are, sir."
CUSTOMER: "Wait a moment - this fork has no sharp edge."
WAITER: "That's right."
CUSTOMER: "But this knife has a lovely edge on it. Why can't the fork be
like that?"
WAITER: "Because it's a fork."
CUSTOMER: "This knife has serrations along the blade to improve its grip
during the cut. Why can't the fork have serrations?"
WAITER: "Because it's a fork. If you want to cut, use the knife."
CUSTOMER: "So what you're saying is that the fork is useless? I don't need
it?"
WAITER: "No, what I'm saying is that I don't get paid enough to deal with
people like you."
 
I

Ian Collins

CBFalconer said:
Don't be silly. You select a language to suit the job. If you
really need template functions use C++ or better languages (Ada,
for example). You probably don't need them.
How do you know what others need? If nobody needed function templates,
C++ wouldn't have a standard library built around them.
 
R

Richard Heathfield

Ian Collins said:
How do you know what others need? If nobody needed function templates,
C++ wouldn't have a standard library built around them.

Nobody needs function templates. All you need is a big old array, ++p, --p,
++*p, --*p, putchar(*p), *p = getchar(), jump from HERE to THERE if *p is
0, and jump back from THERE to HERE. And you probably don't *need* all of
those.
 
I

Ian Collins

Richard said:
Ian Collins said:


Nobody needs function templates. All you need is a big old array, ++p, --p,
++*p, --*p, putchar(*p), *p = getchar(), jump from HERE to THERE if *p is
0, and jump back from THERE to HERE. And you probably don't *need* all of
those.
I walked into that one with my eyes open, didn't I?
 
J

Jean-Marc Bourguet

Ioannis Vranos said:
....
AFAIK he invented templates.

Whatever you mean by template, I don't think he invented them.
- If you mean "parametric polymorphism", Strachey introduced his
classification in 1967, when A.Stepanov was 17, and I think Strachey
classified notions which where already existing.

- If you mean the specific of C++ way, I suggest reading the section 4.1.2
of http://www.research.att.com/~bs/hopl-almost-final.pdf where you'll find
that while he was working at Bell Labs at the time when C++ template where
designed, he failed in convincing Bjarne Stroustrup to make that mecanism
more similar to Ada generics. BTW, it is that difference which make the STL
so more friendly than his earlier work in Ada.

Yours,
 
C

Chris Thomasson

Richard Heathfield said:
Ioannis Vranos said:

CUSTOMER: "I'd like a knife and fork, please."
WAITER: "Here you are, sir."
CUSTOMER: "Wait a moment - this fork has no sharp edge."
WAITER: "That's right."
CUSTOMER: "But this knife has a lovely edge on it. Why can't the fork be
like that?"
WAITER: "Because it's a fork."
CUSTOMER: "This knife has serrations along the blade to improve its grip
during the cut. Why can't the fork have serrations?"
WAITER: "Because it's a fork. If you want to cut, use the knife."
CUSTOMER: "So what you're saying is that the fork is useless? I don't need
it?"
WAITER: "No, what I'm saying is that I don't get paid enough to deal with
people like you."

LOL. :^D
 
C

CBFalconer

Ian said:
How do you know what others need? If nobody needed function
templates, C++ wouldn't have a standard library built around them.

Read it again. I didn't claim to know what others need. I said
"If you need them then ...". I said "probably don't". It is also
a fact that they don't exist in C, and are thus off topic here.
 
I

Ioannis Vranos

CBFalconer said:
You should take this to comp.compilers.lcc and join with Jacob
Navia. There it can be on-topic, and Jacob will agree with you.
Here it is off-topic, and virtually noone will agree with you.


I suppose you know what templates are. If you do, I suppose you consider
having complex numbers and rest of area-specific stuff built in better
than having useful general purpose facilities built in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top