Skip to content

Commit 6b4ad39

Browse files
committed
Added FB
1 parent 3237767 commit 6b4ad39

File tree

5 files changed

+86
-25
lines changed

5 files changed

+86
-25
lines changed

src/Dolang.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__precompile__(true)
1+
# __precompile__(true)
22
module Dolang
33

44
using DataStructures

src/grammar.jl

+24-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,38 @@ using Lerche
22

33
grammar_path = joinpath(dirname(pathof(@__MODULE__)), "grammar.lark")
44

5+
6+
println(grammar_path)
57
txt = read(open(grammar_path), String)
6-
const parser = Lark(txt,
8+
# const parser = Lark(txt,
9+
# parser="lalr", start="formula");
10+
11+
# const parser_equation = Lark(txt,
12+
# parser="lalr", start="equation");
13+
14+
# const parser_assignment = Lark(txt,
15+
# parser="lalr", start="assignment");
16+
17+
# const parser_equation_block = Lark(txt,
18+
# parser="lalr", start="equation_block");
19+
20+
# const parser_assignment_block = Lark(txt,
21+
# parser="lalr", start="assignment_block");
22+
23+
24+
parser = Lark(txt,
725
parser="lalr", start="formula");
826

9-
const parser_equation = Lark(txt,
27+
parser_equation = Lark(txt,
1028
parser="lalr", start="equation");
1129

12-
const parser_assignment = Lark(txt,
30+
parser_assignment = Lark(txt,
1331
parser="lalr", start="assignment");
1432

15-
const parser_equation_block = Lark(txt,
33+
parser_equation_block = Lark(txt,
1634
parser="lalr", start="equation_block");
1735

18-
const parser_assignment_block = Lark(txt,
36+
parser_assignment_block = Lark(txt,
1937
parser="lalr", start="assignment_block");
2038

2139

@@ -121,6 +139,7 @@ end
121139
end
122140

123141
@rule call(t::Converter, children) = Expr(:call, Symbol(children[1].value), children[2:end]...)
142+
@rule calltwo(t::Converter, children) = Expr(:call, Symbol(children[1].value), children[2:end]...)
124143
@rule add(t::Converter, children) = Expr(:call, :+, children...)
125144
@rule mul(t::Converter, children) = Expr(:call, :*, children...)
126145
@rule div(t::Converter, children) = Expr(:call, :/, children...)

src/grammar.lark

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ _POW: "^"|"**"
3636
?atom: NUMBER -> number
3737
| "-" atom -> neg
3838
| pow
39+
| calltwo
3940
| call
4041
| "(" formula ")"
4142
| symbol
@@ -52,10 +53,13 @@ subperiod: INT | NAME
5253
!cname: NAME -> name
5354
?date_index: "t" SIGNED_INT2 -> date
5455
| SIGNED_INT -> date
55-
?call: FUNCTION "(" sum ")" -> call
5656

57+
?call: FUNCTION "(" sum ")" -> call
5758
// this is to help the lark version
58-
FUNCTION.2: "sin"|"cos"|"exp"|"log"
59+
FUNCTION.2: "sin"|"cos"|"exp"|"log"|"nep"
60+
61+
?calltwo: FUNCTIONTWO "(" sum "," sum ")" -> calltwo
62+
FUNCTIONTWO.2: "FB"|"min"|"max"
5963

6064
SIGNED_INT2: ("+"|"-") INT
6165

test/compiler_new.jl

+24-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,30 @@ ff = Dolang.FunctionFactory(eqs, args, params, targets=targets, defs=defs,
2020

2121
ff2 = Dolang.FunctionFactory(eqs, grouped_args, params, targets=targets, defs=defs,
2222
funname=funname)
23-
23+
using Dolo
24+
using DoloYAML
25+
import DoloYAML: orphan
26+
using TimerOutputs
27+
28+
import Dolo: initial_guess
29+
30+
const NT = Threads.nthreads()
31+
32+
if NT > 1
33+
# use multithreading library KernelAbstractions
34+
engine = :cpu
35+
else
36+
# only one CPU
37+
engine = nothing
38+
end
39+
40+
println("Running simulations with $NT threads.")
41+
42+
include("implementations.jl")
43+
44+
model = DoloYAML.yaml_import("models/consumption_savings_new.yaml")
45+
dmodel = Dolo.discretize(model)
46+
2447

2548
# we're all static arrays
2649
x = @SVector [1.0]

tests/test_parsing.jl

+31-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
import YAML
2-
3-
doc = YAML.load_file("tests/tests.yaml")
4-
5-
summary = []
6-
7-
for ex in doc["expressions"]
8-
result = try
9-
Meta.parse(ex)
10-
"OK"
11-
catch
12-
"Failed"
13-
end
14-
push!(summary, (ex, result))
15-
println(ex, " : ", result)
16-
end
1+
a = 9
2+
3+
using Dolang
4+
5+
eq = Dolang.parse_equation("fb(a[t];b[t])")
6+
7+
8+
# eq = Dolang.parse_equation("a[t]-b[t]")
9+
10+
Dolang.convert(Expr,eq)
11+
12+
13+
# Dolang.parse_equation("∀t, t>9");
14+
15+
16+
# import YAML
17+
18+
# doc = YAML.load_file("tests/tests.yaml")
19+
20+
# summary = []
21+
22+
# for ex in doc["expressions"]
23+
# result = try
24+
# Meta.parse(ex)
25+
# "OK"
26+
# catch
27+
# "Failed"
28+
# end
29+
# push!(summary, (ex, result))
30+
# println(ex, " : ", result)
31+
# end
1732

1833
# for ex in doc["symbols"]
1934
# result = try

0 commit comments

Comments
 (0)