Re: Parsing a mathematical expression. Looking for an describing algebra (recursive)

Sergey Solyanik <ssolyanik@icdc.com>
13 Nov 1997 23:37:19 -0500

          From comp.compilers

Related articles
Parsing a mathematical expression. Looking for an describing algebra ( hlinde@euronet.nl (1997-11-11)
Re: Parsing a mathematical expression. Looking for an describing algeb ssolyanik@icdc.com (Sergey Solyanik) (1997-11-13)
Re: Parsing a mathematical expression. Looking for an describing algeb thorssig@mmedia.is (Thorsteinn Sigurdsson) (1997-11-18)
| List of all articles for this month |

From: Sergey Solyanik <ssolyanik@icdc.com>
Newsgroups: sci.math,sci.math.symbolic,comp.compilers
Date: 13 Nov 1997 23:37:19 -0500
Organization: Bentley Systems, Inc.
References: 97-11-060
Keywords: parse

Henk Linde wrote:
>
> Hello,
>
> More than 10 years ago I wrote a program for my first year computing
> science in university called expressions. This is a simple parser for
> simple mathematical expressions.
[...]
>
> I want to expand this to include matrices,functions and user defined
> functions. Does anyone here have such an algebra lying around ? Could
> you mail it to me ? Or can you point me where I can find one ?


I hope this is correct. I wrote it for 64-bit calculator. I do not
recall doing it, but I may have fixed bugs in the calculator, but not
in comments...


/*
  * Grammar:
  *
  * single = name || number
  * factor = -factor || ~ factor || single || (expr)
  * term = factor rest_f
  * rest_f = * factor rest_f || / factor rest_f || epsilon
  * term2 = term rest_ar2
  * rest_ar2 = % term rest_term2 || epsilon
  * arith = term2 rest_ar1
  * rest_ar1 = + term rest_ar1 || - term rest_ar1 || epsilon
  * shiftup = arith rest_sh
  * rest_sh = >> arith rest_sh || << arith rest_sh || epsilon
  * compup = shiftup rest_com
  * rest_com = >= shiftup rest_com || <= shiftup rest_com ||
  * > shiftup rest_com || < shiftup rest_com || epsilon
  * equp = compup rest_eq
  * rest_eq = == compup rest_eq || != compup rest_eq || epsilon
  * andxorup = equp rest_and
  * rest_and = & equp rest_and || ^ equp rest_and || epsilon
  * expr = andxorup rest_or
  * rest_or = | andxorup rest_or || epsilon
  * stmt = expr . name
  * stmt = expr
  */


Regards --


Sergey Solyanik
Software Developer
Bentley Systems, Inc
[Unless there's a theoretical issue, I'd snarf one of the many yacc
calculator grammars and worry more about the semantics. -John]






--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.