home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!destroyer!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.programming
- Subject: Re: Parsing mathematical functions.
- Message-ID: <1992Nov15.174725.13958@organpipe.uug.arizona.edu>
- Date: 15 Nov 92 17:47:25 GMT
- References: <1e25e1INN8sr@matt.ksu.ksu.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 55
- In-Reply-To: strat@matt.ksu.ksu.edu (Steve Davis)
-
- In article <1e25e1INN8sr@matt.ksu.ksu.edu>, strat@matt (Steve Davis) writes:
- >I've been thinking about a problem for a high-school level computer
- >programming contest. The problem I was considering was one that would
- >input a function and two numbers, and output an approximation of the
- >function integral. Of course the hard part for the computer isn't
- >getting the integral, it's parsing the mathematical function!
- >
- >Since this would be a high-school level contest, with solution
- >elegance being the next highest priority to having a working solution,
- >I would want to define the parsing problem in a simple and language
- >inspecific way.
-
- IMHO, the first thing you should do is give up on standard expression format,
- unless knowledge of parsing techniques (like recursive descent) is common
- among your students.
-
- A reasonable alternative you might consider is the so-called "reverse Polish
- notation", where all operators are in the postfix position:
-
- sqrt(x*x+y*y) becomes x x * y y * sqrt
-
- The advantages of this notation is that it can be parsed (and thus,
- interpreted) in a simple left-to-right scan. You'd probably still have
- to explain how to use a stack to evaluate the expression, though.
-
- If you want to stick with standard expression format, it seems to me that
- you'd pretty much have to have a mini-compiler-writing course, to explain
- how operator precedence and evaluation order is captured by a grammar
- (which means parse trees, derivations, and probably at least an aside
- on ambiguity...)
-
- >Where can I find discussion (on the Internet if
- >possible!) of this specific parsing problem.
-
- Well, one of the canonical texts on parsing is
-
- _Compilers: Principles, Techniques and Tools_, by Aho, Sethi
- and Ullman (ISBN 0-201-10088-1)
-
- Perhaps more to the point of your query is
-
- _The UNIX Programming Environment_, by Kernighan and Pike
- (ISBN 0-13-937681-X)
-
- Chapter 8 of this book concerns itself with program development, and
- the program they develop starts as a 4-function calculator and is
- developed into an interpreter for a C-like language.
-
- On the whole, I'd say your best course of action is to choose another
- problem for your contest, since judging by my experience, the knowledge
- required for the given program is way beyond anything the average
- high-schooler knows.
-
- --
- Caught an internal error--.brainrc restored
-