Ask for the syntax of representing operators in Common-Lisp



>>>>> "Nguyen" == Nguyen Huong <hiperfume at yahoo.com> writes:

    Nguyen> 1.  (*) text/plain          ( ) text/html           
    Nguyen> Hello everybody,
 
    Nguyen>  Now I need to deal with the S-expression of Maxima. I do the following steps:
 
    Nguyen>  1) Calculate the integration.
    Nguyen>  (%i1) e:integrate(x^2+x,x);save(test,e);
    Nguyen>                       3      2
    Nguyen>                      x     x
    Nguyen>  (%o1)           -- + --
    Nguyen>                      3     2
 
    Nguyen>  2)Then, it saves the result to file "test" as following:
    Nguyen>  ;;; -*- Mode: LISP; package:maxima; syntax:common-lisp; -*- 
    Nguyen>  (in-package "MAXIMA")
    Nguyen>  (DSKSETQ $E
    Nguyen>           '((MPLUS SIMP)
    Nguyen>             ((MTIMES SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) $X 2))
    Nguyen>             ((MTIMES SIMP) ((RAT SIMP) 1 3) ((MEXPT SIMP) $X 3)))) 
    Nguyen>  (ADD2LNC '$E $VALUES) 
 
    Nguyen>  3)Now I want to write a small compiler with the input is the content of the above result file, the output is a string containing the result in infix mathematics operators, i.e., the result after compling is: 1/2  * x^2  + 1/3  * x^3
 
    Nguyen>  In order to write the compiler, I need to know exactly about the abstract syntax to parse the above file, or at least the syntax to parse the part representing the expression "((MPLUS SIMP)
    Nguyen>              ((MTIMES SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) $X 2))
    Nguyen>              ((MTIMES SIMP) ((RAT SIMP) 1 3) ((MEXPT SIMP) $X 3)))) 
 
Not exactly sure what you want, but the syntax is fairly simple.  All
(most?) of maxima's internal representation is of the form:

    ((op [flags]) [[[arg1] arg2] ...])

where op is the name of the operation, flags are optional flags
telling maxima something about it, and the args are optional arguments
to the operation.  Basically, this form is roughly equivalent to the
infix form "arg1 op arg2 op arg3 ...".

Don't know if there's a comprehensive list of operators, but in this
case we have

     ((MPLUS) a b)      a+b
     ((MTIMES) a b)     a*b
     ((RAT) a b)        a/b, where a and b are integers
     ((MEXPT) a b)      a^b

And for presentation, $X is presented as "x".  That is, the case is
inverted, and the leading "$" is removed.

Ray