How to convert Infix notation to postfix notation

S

Seebs

According to amazon.com, the 4th addition covers C99 and was published
in 2000. That's hardly what I would consider "long-obsolete".

Hmm, you have a point.

On the other hand, I'd feel really bad giving them money. I wonder if
McGraw Hill would send me a review copy... :p
I suppose you could claim that C is obsolete and therefore any books on
C are also obsolete, but the 4th edition appears new enough to warrant
a review. It doesn't appear to be out of print yet.

True. I guess I'm marginally surprised to find that it was updated. Now
I'm curious as to whether he addressed the stuff that people kept pointing
out he got wrong... Interestingly, if he did, it simultaneously addresses
the argued problem (since the reviews are then obsolete), *and* proves
that Spinny was completely wrong to begin with.

-s
 
J

Julienne Walker

I have a copy I've - err - outgrown.  If it wouldn't cost me an arm and
a leg, I'd post it to you.

It's not so much the cost as having yet another book that I won't get
anything out of. I already have too many books, and a beginner's text
is unlikely to provide me with many new insights into C or computer
science. ;-p
 
S

Seebs

I have a copy I've - err - outgrown. If it wouldn't cost me an arm and
a leg, I'd post it to you.

Oooooh.

Well, then. I see a way we can make everyone happy.

You mail me that, I reimburse you for shipping, and I update the document
to describe the current edition. Everyone wins!

-s
 
S

Seebs

It's not so much the cost as having yet another book that I won't get
anything out of. I already have too many books, and a beginner's text
is unlikely to provide me with many new insights into C or computer
science. ;-p

I think you might be surprised. Long after you've pretty much reached the
limits of what you can learn from competently-written books that are at
a general enough level that there's a financially rewarding market for them,
you can learn a ton more by reading abject crap and trying to figure out
what on earth the author was thinking about.

-s
 
J

Julienne Walker

True.  I guess I'm marginally surprised to find that it was updated.  Now
I'm curious as to whether he addressed the stuff that people kept pointing
out he got wrong...

I've thumbed through Schildt's books occasionally over the years, and
I did notice that at one point he stopped using void main and started
using int main for C/C++, so some evidence suggests that he's getting
better about portability. That's only one issue, of course. A more
thorough review will show whether or not the overall quality of his
books has gone up from listening to people whine. ;-)
 
S

Seebs

I've thumbed through Schildt's books occasionally over the years, and
I did notice that at one point he stopped using void main and started
using int main for C/C++, so some evidence suggests that he's getting
better about portability. That's only one issue, of course. A more
thorough review will show whether or not the overall quality of his
books has gone up from listening to people whine. ;-)

Thus my interest in studying one of them more closely, which I think I'll
do if I can figure out a way to do so. (Buying a book I reasonably expect
to be bad does not meet my standards in this regard.)

-s
 
S

Sjouke Burry

Seebs said:
I think you might be surprised. Long after you've pretty much reached the
limits of what you can learn from competently-written books that are at
a general enough level that there's a financially rewarding market for them,
you can learn a ton more by reading abject crap and trying to figure out
what on earth the author was thinking about.

-s
You need a headshrinker for that!!! :)
 
N

Nick

Seebs said:
Oooooh.

Well, then. I see a way we can make everyone happy.

You mail me that, I reimburse you for shipping, and I update the document
to describe the current edition. Everyone wins!

I'm afraid it's the second edition. I outgrew it a long time ago.
 
M

Moi

Mijn hemel, nee, liever niet zeg. Dat soort aarsfladder, en dan ook nog
in steenkolen-Nederlands? Dan liever in Lojban. Hij lijkt me een
typische spreker van Lojban.

Bespaar me de gedachte. Ik vreesch dat die reetkever eerder een soort
van bruinkolen-Nederlands zal bezigen. Achtelijke gladioool...

:)
AvK
 
S

spinoza1111

Julienne, you come in primarily in my experience to enable the
continuation of, not "squabbling", but of deliberate campaigns of
personal destruction as a feminus ex machina who knows her gender will
give her a perverse authority, and who finds the isolated victim, and
joins the Lynch mob like some redneck dame of the 1920s, howling for
blood. I have seen too many women in business do this: advance
themselves by starting or enabling conflict between technical males
and when the blood is in the water, retreat in horror...at what they
are in some measure responsible for. If you're here to do this, please
just leave.

The topic under discussion is converting infix to polish notation as a
C program. It isn't my defects or those of Schildt. Instead, I am
relearning C in order to demonstrate that the thought leaders of this
group (esp. Heathfield) are the problem, because rather than
contribute substantive thoughts to what could be a collective effort,
they lie, backstab and obfuscate. And, show that a grammar driven
algorithm is the best way to solve the problem.

For example, Heathfield pretended that to not use const was a bug. I'd
not used it circa 1990 but the discussion revealed that it's not very
useful in fact in contrast to Visual Basic's ByVal and ByRef or C
Sharp's value and ref parameters, in preventing bugs. Unable to use a
compiler properly, Heathfield, like any incompetent manager, is
nonetheless able to use "negative capability" to make his defective
character the normalized deviant and to make anyone he chooses look
like what everyone here is afraid he or she is, and in most cases, is:
the Incompetent Programmer.

This homunculus is what Adorno was talking about in a passage from
Minima Moralia that I have quoted more than once: the scientific or
technical worker who under at-will employment in a "free market" is
always a bridesmaid and never a bride, a "candidate" for his job no
matter how long he's been there, desparately afraid of the revelation
of "the secret contour of his weakness".

Well, the hard truth is that here most people are incompetent, but can
get competent fast in a group environment in which your behavior is
simply declared unacceptable, in which the defects of another are
never a fit subject for discussion, but it is also axiomatic that
people have the right to verbal self-defense, the alternative to
verbal self-defense, in America, being these mass murders as seen on
TeeVee so very, very often. That is, the only alternative to horror is
the ability to conduct civil discourse, and this ability is destroyed
by Heathfield's back-stabbing, lies, and obfuscation, and your oh so
very genteel enabling behavior.
Gee, Julienne, your reading has been rather superficial, hasn't it? My
claims are based, not only on facts (such as the experience of
switching compilers for Nash) but also on bibliographical references
to a variety of texts, and they are met by rants against my person and
a primitive sort of repetition, a chanting, of the same claims about
me, over and over again.

In high school, did you ever bother finishing Brave New World, sugar?
Did you ever get to the part where the Alphas on holiday revert to
barbarism because they're driven mad by the Savage, eg., by the image
of the humanity they've lost? Or did Spark Notes suffice?

References here (including a reference that I wrote, my own book) are
pearls before swine when thrown before a Gadarene mob, but did you dig
up, honey, on how I referred to Michael L. Scott's use of the language
"the stack" in defense of Herb's similar language? Or that of Peter
Wegner?

These facts and references are met as in a dream by people like
Seebach, whose "references" are mostly "I showed yer stoopid posts to
da guys at da office and dey is laughing at you" and "I have a
learning disorder".

Anyway, enough of this banter. I need to work on the fifth version of
my solution to the original poster's problem, a version in which I
shall lexically analyse the input infix expression so as to be able to
malloc only the bytes needed for the output Polish expression. I have
little time to do this, mostly only my commute time.
 
S

spinoza1111

I wouldn't: it's obviously because he started out on a variety of MS
Basic, rather than on C, a saner version of BASIC, or some other
language altogether.

Actually, my first program was in IBM 1401 machine language. I use -1
because my prof in (graduate school) Computer Architecture pointed out
that most computers use twos-complement binary arithmetic and that -1
is all ones. Thus in terms of debugging it is as far as you can get
from falseness as possible.

I should probably define -1 using the preprocessor as true, or
TRUTHINESS, or warheit, just to annoy you.

There's a concept in Adorno's theory of music: "resentment listening".
It's listening for mistakes in performance or with a global genre-
hatred based on ignorance. It seems that most posters here are
learning disordered and read code like bad music students read scores
or listen to performance: with a sour hatred of that which they've
willy-nilly made their profession, a self-hatred turned outward.
 
S

Seebs

Actually, my first program was in IBM 1401 machine language. I use -1
because my prof in (graduate school) Computer Architecture pointed out
that most computers use twos-complement binary arithmetic and that -1
is all ones. Thus in terms of debugging it is as far as you can get
from falseness as possible.

In the asence of any established conventions in a given language, that
would be a persuasive argument.
There's a concept in Adorno's theory of music: "resentment listening".
It's listening for mistakes in performance or with a global genre-
hatred based on ignorance.

See, there's that key word: "ignorance".

That's not the same thing as pointing out specific flaws based on
exhaustive and detailed knowledge of a particular class of thing.
It seems that most posters here are
learning disordered and read code like bad music students read scores
or listen to performance: with a sour hatred of that which they've
willy-nilly made their profession, a self-hatred turned outward.

It seems... To whom? To you? Okay. But you seem awfully quick to
condemn other people based on fragmentary information... and to condemn
them, not just in terms of what you do know, but in terms of whatever
random things you invent.

-s
 
S

Seebs

The topic under discussion is converting infix to polish notation as a
C program. It isn't my defects or those of Schildt.

The only reason anyone cares about your attempts to solve a 1st year
CS homework problem is that you've made a number of grandiose claims
about how stupid you think other people are, and reading your code
has helped people form a clear opinion of the quality of your opinions.
For example, Heathfield pretended that to not use const was a bug.

He didn't "pretend" anything. He pointed out an arguable flaw. He didn't
promise that everything he complained about would meet your incoherent
standards for a "bug".
I'd
not used it circa 1990 but the discussion revealed that it's not very
useful in fact in contrast to Visual Basic's ByVal and ByRef or C
Sharp's value and ref parameters, in preventing bugs.

No, the discussion revealed, as it always does, that you haven't got
the reading comprehension skills one expects from a domestic house pet.
Gee, Julienne, your reading has been rather superficial, hasn't it? My
claims are based, not only on facts (such as the experience of
switching compilers for Nash)

And I must say, I am duly impressed; if anyone ever asks me whether
Edward G. Nilges can drop a name, I will testify that the name is not
merely dropped, but thrown with great force.
but also on bibliographical references
to a variety of texts,

Such as the abstract of a paper you didn't read, which paper did not say
anything like what you claimed it did based on skimming the abstract.
These facts and references are met as in a dream by people like
Seebach, whose "references" are mostly "I showed yer stoopid posts to
da guys at da office and dey is laughing at you" and "I have a
learning disorder".

As well as detailed technical explanations of the irrelevance of your
name-dropping and incoherent rants.

Meanwhile...

Not a shred of evidence for your claims about the nature and purpose of
the standardization process. Why's that? Probably because you haven't
got any, you just made it up. Hmmm. Beginning to see a pattern...

-s
 
N

Nick Keighley

The only reason anyone cares about your attempts to solve a 1st year
CS homework problem is that you've made a number of grandiose claims
about how stupid you think other people are, and reading your code
has helped people form a clear opinion of the quality of your opinions.

to be fair he's never claimed to be a C expert. So he's implementing a
solution in a language he's unfamiliar with. On the other hand you'd
think he'd grateful for any help...
He didn't "pretend" anything.  He pointed out an arguable flaw.  He didn't
promise that everything he complained about would meet your incoherent
standards for a "bug".

spinoza keeps on going on about "Structured Walkthroughs" and
egolessness and yet displays an ego the size of a planet. In his
universe all criticism of his program is the critic's problem not the
program's.


<snip>
 
N

Nick Keighley

Which translates rather wonderfully to "English" as "My sky, no,
rather do not say. That type aarsfladder, and thus still in
steenkolen-Nederlands? Then rather in Lojban. He seems a typical
participant of Lojban me."

Gotta love Babblefish.

google does slightly better

Heavens, no, do not tell. That kind aarsfladder, and then also
in coal-Dutch? Rather than in Lojban. He seems a
typical speaker of Lojban.
 
B

Ben Bacarisse

io_x said:
"spinoza1111" <[email protected]> ha scritto nel messaggio

testCase("((10+(113-(2+((((((2/(4+3)))))))+2+2))))*a", "10 113 2 2
4 3 + / + 2 + 2 + - + a *", intMallocMax);

why this above not result to me?

My code gives the same result as shown above. The does not mean that
yours is wrong, but it is
yesterday and today i had some free time for spend in this
because in the algo book i have it use push/pop for infixtopolish
(nor that i have understod well what this polish syntax is)
i choose the assembly implementation
(don't know how many bug there are)

C:>infixto
((10+(113-(2+((((((2/(4+3)))))))+2+2))))*a
start [((10+(113-(2+((((((2/(4+3)))))))+2+2))))*a
]; result [10 113 2 2 4 3 + / + - + 2 2 + + a *]

is there some error below?
C:>infixto
(a+b)*c
start [(a+b)*c
]; result [a b + c *]

C:>infixto
a+(b*c)
start [a+(b*c)
]; result [a b c * +]

C:>infixto
a+b+c
start [a+b+c
]; result [a b c + +]

it seems this is build to result
for "right to left" evalutation
when there are no "()"

-------------------------------
; reference in Robert Sedgewick
; nasmw -fobj thisfile.asm
; bcc32 thisfile.obj
%define P _printf

section _DATA use32 public class=DATA
global _main
extern _printf
extern _fgets
extern __streams
; _streams+ 0 = stdin
; _streams+24 = stdout


%define Space 6
%define Digit 0
%define Operator 3

ptr: dd v1, v2, v3, v4, v5, v6

; 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Table:
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 6 ; 0
db 6, 16, 16, 6, 16, 16, 16, 16, 16, 16 ; 1 10 e' fine input non spazio
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 2
db 16, 16, 6, 16, 16, 16, 16, 3, 3, 16 ; 3
db 1, 2, 3, 3, 16, 3, 16, 3, 0, 0 ; 4 "." e' lettera
db 0, 0, 0, 0, 0, 0, 0, 0, 16, 16 ; 5
db 16, 16, 16, 16, 16, 0, 0, 0, 0, 0 ; 6
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 7
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 8
db 0, 16, 16, 16, 3, 0, 16, 0, 0, 0 ; 9
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 10
db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ; 11
db 0, 0, 0, 16, 3, 16, 16, 16, 16, 16 ; 12
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 13
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 14
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 15
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 16
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 17
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 18
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 19
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 20
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 21
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 22
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 23
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 24
db 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 ; 25

IstartIIIsIIIresultIIIsIIIn
db "start [%s]; result [%s] " , 13, 10, 0

IErrorIinIcharIIdIIErrstrIIsIn
db "Error in char %d str=%s" , 13, 10, 0

v1:
IErroreIdiIargomenti
db "Errore di argomenti" , 0

v2:
IErroreItroppiIoperatoriIII4028I
db "Errore troppi operatori (>4028)" , 0

v3:
IErroreIoverflowIresult
db "Errore overflow result" , 0

v4:
IErroreIIIIIIIIInonIbilanciate
db "Errore '(' ')' non bilanciate" , 0

v5:
IErroreIalternanzaInonIrispettata
db "Errore alternanza non rispettata" , 0

v6:
IErroreIcarattereInonIpermesso
db "Errore carattere non permesso" , 0

section _BSS use32 public class=BSS

section _TEXT use32 public class=CODE


;Errore se ritorna !=0
; Caso 1: Errore di argomenti
; Caso 2: Errore troppi operatori (>4028)
; Caso 3: Errore overflow result
; Caso 4: Errore '(' ')' non bilanciate
; Caso 5: Errore alternanza non rispettata
; Caso 6: Errore carattere non permesso
;0k,4j,8i,12b,16ra,20Pres,24PresSz,28P_PLen,32P_i+16
; 36 40 44 48
align 4
infixToPolishAsm:
push ebx
push esi
push edi
push ebp
sub esp, 16
mov edi, dword[esp+ 36]
mov ebp, dword[esp+ 40]
mov esi, dword[esp+ 48]
mov ecx, esp
mov dword[esp], 0
mov dword[esp+4], 0
mov dword[esp+8], 0
xor eax, eax
xor ebx, ebx
mov edx, 1
cmp dword[esp+ 44], 0
je .e0
cmp edi, 0
je .e
cmp ebp, 0
jle .e
cmp esi, 0
je .e
jmp .3
.e: sub esi, dword[esp+ 48]
mov edi, dword[esp+ 44]
mov [edi], esi
.e0: mov eax, edx
stc
jmp .z
.e1: mov esp, ecx
mov byte[edi], 0
mov edx, 2
jmp short .e ; errore: overflow stack
.e2: mov esp, ecx
mov byte[edi], 0
mov edx, 3
jmp short .e ; errore: overflow res
.e3: mov esp, ecx
mov byte[edi], 0
mov edx, 4
jmp short .e ; errore: ( non bilanciate
.e4: mov esp, ecx
mov byte[edi], 0
mov edx, 5
jmp short .e ; errore: alternanza non rispettata
.e5: mov esp, ecx
mov byte[edi], 0
mov edx, 6
jmp short .e ; errore: carattere non permesso
.0: mov byte[edi], 0
cmp dword[ecx], 0
jne .e3
cmp dword[ecx+4], 1
jne .e4
.0x: cmp ecx, esp
je .0a
pop edx
mov byte[edi], ' '
inc edi
dec ebp
jle .e2
mov byte[edi], dl
dec ebp
jle .e2
inc edi
mov byte[edi], 0
jmp short .0x
.0a: sub edi, dword[esp+ 36]
mov edx, dword[esp+ 44]
mov [edx], edi
xor eax, eax
jmp .z
.2: inc esi
.3: mov al, [esi]
.0b: cmp eax, 0
je .0
mov bl, [Table+eax]
cmp ebx, Space
je .2
cmp ebx, Digit
jne .2a
add dword[ecx+4], 1
cmp dword[ecx+4], 1
jg .e4
.1a: mov [edi], al
inc esi
mov al, [esi]
inc edi
dec ebp
jle .e2
cmp byte[Table+eax], 0
je .1a
jmp short .0b
.2a: cmp ebx, Operator
jne .4
sub dword[ecx+4], 1
cmp dword[ecx+4], 0
jl .e4
mov edx, ecx
sub edx, esp
shr edx, 2
cmp edx, 4028
jae .e1
push eax
.3a: mov byte[edi], ' '
inc edi
dec ebp
jle .e2
jmp .2
.4: cmp eax, ')'
jne .5
cmp dword[ecx], 0
je .e3
inc dword[ecx]
cmp esp, ecx
ja .e
jz .2
pop edx
sub ebp, 2
jle .e2
mov byte[edi], ' '
inc edi
mov byte[edi], dl
inc edi
jmp .2
.5: cmp eax, '('
jne .e5
dec dword[ecx]
jmp .2
.z:
lea esp, [esp+16]
pop ebp
pop edi
pop esi
pop ebx
ret 16

align 4
_main:
pushad
sub esp, 4048
mov edi, esp
lea esi, [edi+2000]
lea ebp, [edi-4]
push __streams
push 1024
push esi
call _fgets
add esp, 12
cmp eax, 0
je .x
jmp short .1
.e: dec eax
cmp eax, 5
ja .x
mov edx, [ptr+4*eax]
mov eax, [ebp]
push edx
push eax
push IErrorIinIcharIIdIIErrstrIIsIn
call P
add esp, 12
jmp short .x
.1: push esi
push ebp
push 1024
push edi
call infixToPolishAsm
cmp eax, 0
jne .e
push edi
push esi
push IstartIIIsIIIresultIIIsIIIn
call P
add esp, 12
.x:
add esp, 4048
popad
xor eax, eax
ret
 
B

Ben Bacarisse

Ben Bacarisse said:
My code gives the same result as shown above. The does not mean that
yours is wrong, but it is

.... a data point.

[I sent in error. I had decided not to post since there is nothing C
related here at all, but hit the wrong key. Sorry.]

<snip>
 
J

Julienne Walker

Gee, Julienne, your reading has been rather superficial, hasn't it?

Speaking of superficial reading, are you aware that the text you've
quoted and apparently attributed to me was actually written by Seebs?
I know I promised not to reply to you again, but being misquoted is
something I feel the need to correct.
 

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
474,076
Messages
2,570,565
Members
47,200
Latest member
Vanessa98N

Latest Threads

Top