home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!sgiblab!adagio.panasonic.com!nntp-server.caltech.edu!willow!roy
- From: Roy_Williams
- Newsgroups: comp.lang.c++
- Subject: parsing
- Date: 8 Jan 1993 00:34:23 GMT
- Organization: CCSF Caltech, Pasadena, CA
- Lines: 43
- Distribution: world
- Message-ID: <1iii6fINNfur@gap.caltech.edu>
- Reply-To: roy@willow.ccsf.caltech.edu
- NNTP-Posting-Host: willow.ccsf.caltech.edu
-
- Suppose I have some class, for example vectors, with lots of
- operators defined so I can do things like
-
- a += b + 3*c + a*b;
-
- meaning in normal language
-
- for(int i=0; i<vector_length; i++)
- a[i] += b[i] + 3*c[i] + a[i]*b[i];
-
- If the vectors are small and 'new' is cheap, we can define
- each operator by creating a new one to hold the result,
- evaluating, then returning the whole vector. They get destroyed
- by the system.
-
- When the vectors get a bit larger, we want to return a pointer
- to the new vector, using the magic of reference counting
- to do the garbage collection.
-
- Now suppose we get stingy about either the time taken for
- memory allocation, or we are working at the limits of the
- machine's available memory: if I were computing the above
- operation with a hand-held calculator and pencil, I wouldn't
- write down any temporaries, so I want my implementation of
- vectors to do as well.
-
- I'd like a vector to be either a set of numbers, as before,
- or an operator type and pointer(s) to vector(s). Nothing would
- actually get computed until we get to the assignment (or even
- until the thing is written out!).
-
- Is there any code or book or reference or ftpable class library
- so I don't have to do this myself? How about optimizing the
- parse tree before evaluation so a*b + a*c becomes a*(b + c)?
-
- Roy Williams
- Caltech Concurrent Supercomputing Facilities
- Pasadena, CA
-
-
-
-
-
-