login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Parsing FriCAS/Axiom code

There are four possible forms of parsed output.

Click + at the top right of the window to expand the SPAD compilere output to show the parser output in the following examples:

 (+)   help  links  subscribe  changes  refresh  edit

fricas
)boot $RawParseOnly := true
(EVAL-WHEN (EVAL LOAD) (SETQ |$RawParseOnly| T)) Value = T

spad
)abbrev package PASCAL Pascal
Pascal : with ( make_pascal : Integer -> Matrix(Integer) )
  == add
    make_pascal(N : Integer) : Matrix(Integer) ==
        -- coerce here to NonNegativeInteger because this is what
        -- 'zero' requires
        nn := N::NonNegativeInteger
        tab := zero(nn, nn)$Matrix(Integer)
        n : Integer
        tab(1, 1) := 1
        for n in 2..nn repeat
            -- Fill row numer n
            k : Integer
            tab(n, 1) := 1
            tab(n, n) := 1
            for k in 2..(n - 1) repeat
                tab(n, k) := tab(n-1, k) + tab(n-1, k-1)
        tab
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1379180095272779836-25px002.spad
      using old system compiler.
   PASCAL abbreviates package Pascal 
(==
 (|:| |Pascal|
      (|with|
       (CATEGORY
        (|Signature| |make_pascal| (-> |Integer| (|Matrix| |Integer|)) NIL))))
 (|add|
  (== (|:| (|make_pascal| (|:| N |Integer|)) (|Matrix| |Integer|))
   (|;|
    (|;|
     (|;|
      (|;|
       (|;| (|:=| |nn| (|::| N |NonNegativeInteger|))
        (|:=| |tab| ((|Sel| (|Matrix| |Integer|) |zero|) (|,| |nn| |nn|))))
       (|:| |n| |Integer|))
      (|:=| (|tab| (|,| 1 1)) 1))
     (REPEAT (IN |n| (SEGMENT 2 |nn|))
             (|;|
              (|;| (|;| (|:| |k| |Integer|) (|:=| (|tab| (|,| |n| 1)) 1))
               (|:=| (|tab| (|,| |n| |n|)) 1))
              (REPEAT (IN |k| (SEGMENT 2 (- |n| 1)))
                      (|:=| (|tab| (|,| |n| |k|))
                       (+ (|tab| (|,| (- |n| 1) |k|))
                          (|tab| (|,| (- |n| 1) (- |k| 1)))))))))
    |tab|))))

fricas
)boot $RawParseOnly := true
(EVAL-WHEN (EVAL LOAD) (SETQ |$RawParseOnly| T)) Value = T

spad
)abbrev package PASCAL Pascal
Pascal : with ( make_pascal : Integer -> Matrix(Integer) )
  == add
    make_pascal(N : Integer) : Matrix(Integer) ==
        -- coerce here to NonNegativeInteger because this is what
        -- 'zero' requires
        nn := N::NonNegativeInteger
        tab := zero(nn, nn)$Matrix(Integer)
        n : Integer
        tab(1, 1) := 1
        for n in 2..nn repeat
            -- Fill row numer n
            k : Integer
            tab(n, 1) := 1
            tab(n, n) := 1
            for k in 2..(n - 1) repeat
                tab(n, k) := tab(n-1, k) + tab(n-1, k-1)
        tab
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1379180095272779836-25px004.spad
      using old system compiler.
   PASCAL abbreviates package Pascal 
(==
 (|:| |Pascal|
      (|with|
       (CATEGORY
        (|Signature| |make_pascal| (-> |Integer| (|Matrix| |Integer|)) NIL))))
 (|add|
  (== (|:| (|make_pascal| (|:| N |Integer|)) (|Matrix| |Integer|))
   (|;|
    (|;|
     (|;|
      (|;|
       (|;| (|:=| |nn| (|::| N |NonNegativeInteger|))
        (|:=| |tab| ((|Sel| (|Matrix| |Integer|) |zero|) (|,| |nn| |nn|))))
       (|:| |n| |Integer|))
      (|:=| (|tab| (|,| 1 1)) 1))
     (REPEAT (IN |n| (SEGMENT 2 |nn|))
             (|;|
              (|;| (|;| (|:| |k| |Integer|) (|:=| (|tab| (|,| |n| 1)) 1))
               (|:=| (|tab| (|,| |n| |n|)) 1))
              (REPEAT (IN |k| (SEGMENT 2 (- |n| 1)))
                      (|:=| (|tab| (|,| |n| |k|))
                       (+ (|tab| (|,| (- |n| 1) |k|))
                          (|tab| (|,| (- |n| 1) (- |k| 1)))))))))
    |tab|))))

fricas
)boot $FlatParseOnly := true
(EVAL-WHEN (EVAL LOAD) (SETQ |$FlatParseOnly| T)) Value = T

spad
)abbrev package PASCAL Pascal
Pascal : with ( make_pascal : Integer -> Matrix(Integer) )
  == add
    make_pascal(N : Integer) : Matrix(Integer) ==
        -- coerce here to NonNegativeInteger because this is what
        -- 'zero' requires
        nn := N::NonNegativeInteger
        tab := zero(nn, nn)$Matrix(Integer)
        n : Integer
        tab(1, 1) := 1
        for n in 2..nn repeat
            -- Fill row numer n
            k : Integer
            tab(n, 1) := 1
            tab(n, n) := 1
            for k in 2..(n - 1) repeat
                tab(n, k) := tab(n-1, k) + tab(n-1, k-1)
        tab
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1379180095272779836-25px006.spad
      using old system compiler.
   PASCAL abbreviates package Pascal 
(==
 (|:| |Pascal|
      (|with|
       (CATEGORY
        (|Signature| |make_pascal| (-> |Integer| (|Matrix| |Integer|)) NIL))))
 (|add|
  (== (|:| (|make_pascal| (|:| N |Integer|)) (|Matrix| |Integer|))
   (|;|
    (|;|
     (|;|
      (|;|
       (|;| (|:=| |nn| (|::| N |NonNegativeInteger|))
        (|:=| |tab| ((|Sel| (|Matrix| |Integer|) |zero|) (|,| |nn| |nn|))))
       (|:| |n| |Integer|))
      (|:=| (|tab| (|,| 1 1)) 1))
     (REPEAT (IN |n| (SEGMENT 2 |nn|))
             (|;|
              (|;| (|;| (|:| |k| |Integer|) (|:=| (|tab| (|,| |n| 1)) 1))
               (|:=| (|tab| (|,| |n| |n|)) 1))
              (REPEAT (IN |k| (SEGMENT 2 (- |n| 1)))
                      (|:=| (|tab| (|,| |n| |k|))
                       (+ (|tab| (|,| (- |n| 1) |k|))
                          (|tab| (|,| (- |n| 1) (- |k| 1)))))))))
    |tab|))))

fricas
)boot $PostTranOnly := true
(EVAL-WHEN (EVAL LOAD) (SETQ |$PostTranOnly| T)) Value = T

spad
)abbrev package PASCAL Pascal
Pascal : with ( make_pascal : Integer -> Matrix(Integer) )
  == add
    make_pascal(N : Integer) : Matrix(Integer) ==
        -- coerce here to NonNegativeInteger because this is what
        -- 'zero' requires
        nn := N::NonNegativeInteger
        tab := zero(nn, nn)$Matrix(Integer)
        n : Integer
        tab(1, 1) := 1
        for n in 2..nn repeat
            -- Fill row numer n
            k : Integer
            tab(n, 1) := 1
            tab(n, n) := 1
            for k in 2..(n - 1) repeat
                tab(n, k) := tab(n-1, k) + tab(n-1, k-1)
        tab
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1379180095272779836-25px008.spad
      using old system compiler.
   PASCAL abbreviates package Pascal 
(==
 (|:| |Pascal|
      (|with|
       (CATEGORY
        (|Signature| |make_pascal| (-> |Integer| (|Matrix| |Integer|)) NIL))))
 (|add|
  (== (|:| (|make_pascal| (|:| N |Integer|)) (|Matrix| |Integer|))
   (|;|
    (|;|
     (|;|
      (|;|
       (|;| (|:=| |nn| (|::| N |NonNegativeInteger|))
        (|:=| |tab| ((|Sel| (|Matrix| |Integer|) |zero|) (|,| |nn| |nn|))))
       (|:| |n| |Integer|))
      (|:=| (|tab| (|,| 1 1)) 1))
     (REPEAT (IN |n| (SEGMENT 2 |nn|))
             (|;|
              (|;| (|;| (|:| |k| |Integer|) (|:=| (|tab| (|,| |n| 1)) 1))
               (|:=| (|tab| (|,| |n| |n|)) 1))
              (REPEAT (IN |k| (SEGMENT 2 (- |n| 1)))
                      (|:=| (|tab| (|,| |n| |k|))
                       (+ (|tab| (|,| (- |n| 1) |k|))
                          (|tab| (|,| (- |n| 1) (- |k| 1)))))))))
    |tab|))))

fricas
)boot $PrintOnly := true
(EVAL-WHEN (EVAL LOAD) (SETQ |$PrintOnly| T)) Value = T

spad
)abbrev package PASCAL Pascal
Pascal : with ( make_pascal : Integer -> Matrix(Integer) )
  == add
    make_pascal(N : Integer) : Matrix(Integer) ==
        -- coerce here to NonNegativeInteger because this is what
        -- 'zero' requires
        nn := N::NonNegativeInteger
        tab := zero(nn, nn)$Matrix(Integer)
        n : Integer
        tab(1, 1) := 1
        for n in 2..nn repeat
            -- Fill row numer n
            k : Integer
            tab(n, 1) := 1
            tab(n, n) := 1
            for k in 2..(n - 1) repeat
                tab(n, k) := tab(n-1, k) + tab(n-1, k-1)
        tab
spad
   Compiling FriCAS source code from file 
      /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1379180095272779836-25px010.spad
      using old system compiler.
   PASCAL abbreviates package Pascal 
(==
 (|:| |Pascal|
      (|with|
       (CATEGORY
        (|Signature| |make_pascal| (-> |Integer| (|Matrix| |Integer|)) NIL))))
 (|add|
  (== (|:| (|make_pascal| (|:| N |Integer|)) (|Matrix| |Integer|))
   (|;|
    (|;|
     (|;|
      (|;|
       (|;| (|:=| |nn| (|::| N |NonNegativeInteger|))
        (|:=| |tab| ((|Sel| (|Matrix| |Integer|) |zero|) (|,| |nn| |nn|))))
       (|:| |n| |Integer|))
      (|:=| (|tab| (|,| 1 1)) 1))
     (REPEAT (IN |n| (SEGMENT 2 |nn|))
             (|;|
              (|;| (|;| (|:| |k| |Integer|) (|:=| (|tab| (|,| |n| 1)) 1))
               (|:=| (|tab| (|,| |n| |n|)) 1))
              (REPEAT (IN |k| (SEGMENT 2 (- |n| 1)))
                      (|:=| (|tab| (|,| |n| |k|))
                       (+ (|tab| (|,| (- |n| 1) |k|))
                          (|tab| (|,| (- |n| 1) (- |k| 1)))))))))
    |tab|))))

From: Waldek Hebisch
Date: 16 March 2014 01:13
Subject: Re: [fricas-devel] Parsing FriCAS/Axiom code
To: fricas-devel@googlegroups.com

Francesco Bonazzi wrote: > > I think that creating a SPAD-to-Julia compiler is a hard task, but > nonetheless I believe that adding CAS support to Julia would benefit both > Julia and the CAS itself. I believe that Julia offers a much easier > learning curve for beginners than SPAD, and the CAS developing community > could become much larger, with considerable improvement to the code. > > I was wondering whether it is possible to use aldor or the spad compiler to > generate the "parsed aldor" format of FriCAS (the -Fap parameter in > aldor), so that the source code parsing would be much easier.

There are four possible forms of parsed output. Typing on FriCAS command line:

)boot $RawParseOnly := true

cause FriCAS instead of compiling to print raw parse tree (that is directly output from the parser).

)boot $FlatParseOnly := true

prints somewhat flattened version of parse tree (bigger parse trees should be more readable, but otherwise this form is not used)

)boot $PostTranOnly := true

prints parse tree after first auxiliary transformation

)boot $PrintOnly := true

prints parse tree after second auxiliary transformation. This form is used by Spad compiler.

> Otherwise, do you have any other suggestions or do you believe that such > work is infeasible by automatic translation?

It is interesting project. Difficulty depends largely on how well Spad concepts map to Julia. IIUC core ideas of Julia are quite similar to Spad, so it looks possible.

-- Waldek Hebisch




  Subject:   Be Bold !!
  ( 14 subscribers )  
Please rate this page: