Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #997
| From | "luser.droog" <luser.droog@gmail.com> |
|---|---|
| Newsgroups | comp.lang.postscript |
| Subject | Re: How to do Algebraic Mode in PS like the HP does? |
| Date | 2012-10-13 01:40 -0500 |
| Organization | unorganized |
| Message-ID | <k5b2de$5m2$1@dont-email.me> (permalink) |
| References | (2 earlier) <k0b0js$nqu$1@reader1.panix.com> <ef3f384c-2a6e-4850-8286-7d75b4b63179@googlegroups.com> <k3ou4d$c8i$1@reader1.panix.com> <k45r3i$5ki$1@dont-email.me> <k48n03$98q$1@dont-email.me> |
luser.droog wrote:
> luser.droog wrote:
>
>> David Combs wrote:
>>
>>> In article <ef3f384c-2a6e-4850-8286-7d75b4b63179@googlegroups.com>,
>>> luser- -droog <mijoryx@yahoo.com> wrote:
>>>>
>>>>
>>>>I'd suggest you take them one-at-a-time and start posting "How to do XX
>>>>in PS like the HP does?" threads. I'll contribute!
>>>>
>>>>For algebraic mode, we'll need a LL(1) or LR parser. I'll go get my
>>>>Dragon book...
>>>>
>>>>-- droog
>>>
>>>
>>> Yes, if it were c, you'd need the lr stuff, I guess.
>>>
>>> But just parenthesized expressions and function calls,
>>> isn't that basically dead simple? Recursive descent
>>> or the like. And so unlike an lr scheme, with
>>> recursive descent the parsing code is readable and
>>> understandable. (Once someone does the first and
>>> follow sets -- sort of beyond me!)
>>>
>>> David
>>
>> Here's a first draft. Converts a string containing
>> an infix expression involving "*_+-" to a string
>> containing the postfix equivalent.
>>
>> To actually produce PS output, we'll need to expand the
>> payload in the /oper dict and pre-scan the string to
>> count operators so the size of the output string can
>> be calculated.
>>
>
> A little more searching led me to this:
>
http://devmaster.net/posts/2866/processing-arithmetic-expressions-with-the-shunting-yard-algorithm
>
> Looks very promising.
Another draft.
This one uses `token` to consume the string,
and evaluates instead of generating a postfix representation.
But I think this makes for a simple, extensible base. ?maybe?
%!
%infix4.ps
[ % oper prec
[ /+ {add} 1 ]
[ /- {sub} 1 ]
[ /* {mul} 2 ]
[ / {div} 2 ]
]
dup /oper exch dup length dict begin {
dup 0 get exch 1 get def
} forall currentdict end def
dup /prec exch dup length dict begin {
dup 0 get exch 2 get def
} forall currentdict end def
pop
/opstack 10 array def
/opptr -1 def
/oppush {
/opptr opptr 1 add def
opptr opstack length eq { /stackoverflow signalerror } if
opstack opptr 3 2 roll put
} def
/oppop {
opptr -1 eq { /stackunderflow signalerror } if
opstack opptr get
/opptr opptr 1 sub def
} def
/integertype { } def
/realtype { } def
/nametype {
dup oper exch known {
/op exch def
{
opptr 0 lt { exit } if
prec opstack opptr get get
prec /op load get gt { %prec(tos)>prec(op)
oper oppop get exec
}{
exit
} ifelse
} loop
/op load oppush
}{
dup where { exch get } if
} ifelse
} def
/process {
dup type exec
} def
/eval {
{
token {
exch /rem exch def
process
rem
}{
exit
} ifelse
} loop
{
opptr -1 eq { exit } if
oper oppop get exec
} loop
} def
/a 2 def (a = )print a =
/b 3 def (b = )print b =
[
(a + b)
(a * b)
(a + b * b)
(a * b + b)
(a + b / a * b)
(b * b * b / a * b * a)
] { dup print(=)= eval = } forall
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar
Is it possible to replace 1 custom character in a font?? Ramon F Herrera <ramon@conexus.net> - 2012-07-16 12:07 -0700
Re: Is it possible to replace 1 custom character in a font?? Bill <billsrrempire@gmail.com> - 2012-07-16 12:29 -0700
Re: Is it possible to replace 1 custom character in a font?? Character <Char@cters.bold.italic> - 2012-07-16 17:20 -0700
Re: Is it possible to replace 1 custom character in a font?? luser- -droog <mijoryx@yahoo.com> - 2012-07-16 20:51 -0700
Re: Is it possible to replace 1 custom character in a font?? dkcombs@panix.com (David Combs) - 2012-08-13 13:15 +0000
Re: Is it possible to replace 1 custom character in a font?? luser- -droog <mijoryx@yahoo.com> - 2012-08-13 15:54 -0700
Re: Is it possible to replace 1 custom character in a font?? dkcombs@panix.com (David Combs) - 2012-08-13 13:48 +0000
Re: Is it possible to replace 1 custom character in a font?? luser- -droog <mijoryx@yahoo.com> - 2012-08-16 03:09 -0700
Re: Is it possible to replace 1 custom character in a font?? dkcombs@panix.com (David Combs) - 2012-09-24 06:21 +0000
How to do Algebraic Mode in PS like the HP does? "luser.droog" <luser.droog@gmail.com> - 2012-09-28 22:48 -0500
Re: How to do Algebraic Mode in PS like the HP does? "luser.droog" <luser.droog@gmail.com> - 2012-09-30 00:57 -0500
Re: How to do Algebraic Mode in PS like the HP does? Herbert Voss <Herbert.Voss@alumni.tu-berlin.de> - 2012-09-30 22:40 +0200
Re: How to do Algebraic Mode in PS like the HP does? "luser.droog" <luser.droog@gmail.com> - 2012-10-02 12:32 -0500
Re: How to do Algebraic Mode in PS like the HP does? "luser.droog" <luser.droog@gmail.com> - 2012-10-13 01:40 -0500
Re: How to do Algebraic Mode in PS like the HP does? "luser.droog" <luser.droog@gmail.com> - 2012-10-14 00:51 -0500
Re: How to do Algebraic Mode in PS like the HP does? "luser.droog" <luser.droog@gmail.com> - 2012-10-14 04:43 -0500
Re: Is it possible to replace 1 custom character in a font?? SaGS <sags5495@gmail.com> - 2012-08-13 20:04 -0700
Re: Is it possible to replace 1 custom character in a font?? John Deubert <john@acumentraining.com> - 2012-08-21 06:48 -0700
Re: Is it possible to replace 1 custom character in a font?? dkcombs@panix.com (David Combs) - 2012-09-24 06:23 +0000
csiph-web