Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a parser for BUGS #52

Merged
merged 33 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f211466
some prototypes, not working yet
sunxd3 Jul 14, 2023
73c10f0
more functions
sunxd3 Jul 15, 2023
dbe0210
old and new progress
sunxd3 Jul 17, 2023
985a3ed
cleanup
sunxd3 Jul 17, 2023
b03ea66
add `parse` function
sunxd3 Jul 17, 2023
cccf2e3
add some comments
sunxd3 Jul 18, 2023
f46e0a8
move tests to test file, add doc
sunxd3 Jul 23, 2023
8fd97af
Merge remote-tracking branch 'origin/master' into parser
sunxd3 Jul 25, 2023
30c6b11
move `parser.jl` to `src`
sunxd3 Jul 25, 2023
b21a29d
Add type restriction to `_eval`
sunxd3 Jul 25, 2023
d62594f
Multiple fix
sunxd3 Jul 25, 2023
416cc1d
formatting
sunxd3 Jul 25, 2023
14e132e
light format tests, need more and better ones
sunxd3 Jul 25, 2023
eff7b22
formatting related to `_eval`
sunxd3 Jul 25, 2023
9b8a606
Move functions
sunxd3 Jul 26, 2023
e213daa
Add Methadone example, improve to parser
sunxd3 Jul 31, 2023
6ff3e95
add some error cases
sunxd3 Jul 31, 2023
0b7be92
Volume 1-4 from MultiBUGS work with parser
sunxd3 Jul 31, 2023
acab8b6
check Julia keywords
sunxd3 Aug 1, 2023
6cba0a1
improve code doc
sunxd3 Aug 1, 2023
fe2ad9e
Some code improvement and notes on error recovery
sunxd3 Aug 1, 2023
6520dbb
Formatting
sunxd3 Aug 1, 2023
e539d50
fix formatting
yebai Aug 2, 2023
aecbb76
add parser to includes
yebai Aug 2, 2023
83c003b
add comments on errors reporting
sunxd3 Aug 5, 2023
c601039
Merge branch 'parser' of https://github.com/TuringLang/SymbolicPPL.jl…
sunxd3 Aug 5, 2023
58c9ec1
notes on panic mode, rename `@bugsast`
sunxd3 Aug 7, 2023
580906d
Apply suggestions from code review
yebai Aug 7, 2023
ea84593
Fix parser related tests.
sunxd3 Aug 7, 2023
04a4ae6
Merge branch 'parser' of https://github.com/TuringLang/SymbolicPPL.jl…
sunxd3 Aug 7, 2023
095fbfa
Remove unwanted file
sunxd3 Aug 7, 2023
53acef4
formatting
sunxd3 Aug 7, 2023
5315921
Finish renaming `@bugsast` to `@bugs`
sunxd3 Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/src/parser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Strictly speaking, the program is not "parsing", because the program doesn't output a syntax tree.
What is program does is take a token stream, with recursive descent structure, check the correctness of the program.
In the process of the recursive descent, BUGS syntax tokens will be translated into Julia syntax tokens.
The tokens that are already compatible with Julia will be remained, others will be either transformed or removed, also additional tokens may also be added.

The parser will error given a program not in strict BUGS syntax.

the general idea is:
1. use `tokenize` to get the token vector
2. inspect tokens and build the Julia version of the program in the form of a vector of tokens
3. when it is appropriate to do so, just push the token to the Julia version of the program vector
4. at the same time, some errors are detected and diagnostics are pushed to the diagnostics vector; also some tokens may be deleted, combined, or replaced
5. error recovery is very primitive: the heuristic is user forget something instead of put something wrong, a slightly more sophisticated approach is doing two versions: both "discard" and skip
7 changes: 6 additions & 1 deletion src/graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ end
# `_eval` mimic `eval` function, but use precompiled functions. This is possible because BUGS essentially only has
# two kinds of expressions: function calls and indexing.
# `env` is a dictionary mapping symbols in `expr` to values, values can be arrays or scalars
function _eval(expr::Number, env)
return expr
end
function _eval(expr::Symbol, env)
if expr == :nothing
return nothing
elseif expr == :(:)
return Colon()
else # intentional strict, all corner cases should be handled above
return env[expr]
end
Expand All @@ -137,7 +142,7 @@ function _eval(expr::Expr, env)
end
end
function _eval(expr, env)
return expr
return error("Unknown expression type: $expr of type $(typeof(expr))")
end

"""
Expand Down
Loading