File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -30,4 +30,5 @@ include("eval.jl")
30
30
include (" display.jl" )
31
31
include (" operators.jl" )
32
32
include (" W2JuliaStruct.jl" )
33
+ include (" W2JuliaExpr.jl" )
33
34
end
Original file line number Diff line number Diff line change
1
+
2
+
3
+ export W2JuliaExpr
4
+
5
+ """
6
+ Converts MathLink `WExpr`essions to Julia `Expr`essions
7
+ """
8
+ function W2JuliaExpr (wexpr:: WExpr )
9
+ # ###Check if the operator has an alias
10
+ if haskey (funcDict, wexpr. head. name)
11
+ Operator= funcDict[wexpr. head. name]
12
+ else
13
+ Operator= Symbol (wexpr. head. name)
14
+ end
15
+ return Expr (:call ,Operator,[W2JuliaExpr (arg) for arg in wexpr. args]. .. )
16
+ end
17
+ W2JuliaExpr (wexpr:: WSymbol ) = Symbol (wexpr. name)
18
+ W2JuliaExpr (wexpr:: Number ) = wexpr
19
+
20
+
21
+ # ##Dictionary with known funcitons and their translations
22
+ funcDict= Dict (" Plus" => :+ ,
23
+ " Minus" => :- ,
24
+ " Power" => :^ ,
25
+ " Times" => :* ,
26
+ " Sin" => :sin ,
27
+ " Cos" => :cos ,
28
+ )
Original file line number Diff line number Diff line change @@ -4,6 +4,25 @@ using Test
4
4
import MathLink: WExpr, WSymbol
5
5
6
6
7
+ @testset " W2JuliaExpr" begin
8
+ # ##Test of a simple MathLink to Julia converter. It converts MathLink expressions to the correcsponding Julia constructions
9
+ @testset " Variables" begin
10
+ @test W2JuliaExpr (W " a" ) == :a
11
+ @test W2JuliaExpr (W ` a` ) == :a
12
+ @test W2JuliaExpr (W " a" + W " b" ) == :(a+ b)
13
+ @test W2JuliaExpr (W ` sin` ) == :sin
14
+ @test W2JuliaExpr (W ` a+b` ) == :(a+ b)
15
+ @test W2JuliaExpr (W ` a*b` ) == :(a* b)
16
+ @test W2JuliaExpr (W ` Sin[a]` ) == :(sin (a))
17
+ @test W2JuliaExpr (W ` Sin[a+b]` ) == :(sin (a+ b))
18
+ @test W2JuliaExpr (W ` Cos[a^b]` ) == :(cos (a^ b))
19
+ @test W2JuliaExpr (W ` a/b` ) == :(a* (b^- 1 ))
20
+ @test W2JuliaExpr (W ` a^b` ) == :(a^ b)
21
+ end
22
+ end
23
+
24
+
25
+
7
26
@testset " W2JuliaStruct" begin
8
27
# ##Test of a simple MathLink to Julia converter. It converts MathLink expressions to the correcsponding Julia constructions
9
28
@testset " Lists to Lists" begin
You can’t perform that action at this time.
0 commit comments