JSONization of level-2 syntax

153 views
Skip to first unread message

gmhwxi

unread,
Dec 12, 2014, 11:12:15 PM12/12/14
to ats-lan...@googlegroups.com
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

For instance, the command-line below:

patsopt --jsonize-2 ${PATSHOME}/doc/EXAMPLE/INTRO/acker1.dats

generates the JSON text included at the end of this message. The text can be readily
parsed. An example of doing so can be found in the UTFPL0 directory:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/UTFPL0

In ATS, level-2 syntax is used after fixities (infix, prefix and postfix) and bindings are resolved.

If you ever want to design/implement a language, then you can use this tool to get going quickly.
This is especially so if you want to play with fancy types as the concrete syntax of ATS allows
the programmer to readily add type-annotations. I myself intend to use the tool for teaching PL
and compilers.

Also, this tool can be used for analyzing and documenting ATS code.

{
"s2cstmap":
[{"s2cst_sym": "g0int_t0ype", "s2cst_srt": {"S2RTfun": [[{"S2RTbas": ["tkind"]}], {"S2RTbas": ["t@ype"]}]}, "s2cst_stamp": 200, "s2cst_supcls": []}, {"s2cst_sym": "int_kind", "s2cst_srt": {"S2RTbas": ["tkind"]}, "s2cst_stamp": 226, "s2cst_supcls": []}, {"s2cst_sym": "int", "s2cst_srt": {"S2RTbas": ["t@ype"]}, "s2cst_stamp": 230, "s2cst_supcls": []}, {"s2cst_sym": "atsvoid_t0ype", "s2cst_srt": {"S2RTbas": ["t@ype"]}, "s2cst_stamp": 421, "s2cst_supcls\
"
: []}]
,
"s2varmap":
[]
,
"d2conmap":
[]
,
"d2cstmap":
[{"d2cst_sym": "main_void_0", "d2cst_type": {"s2exp_srt": {"S2RTbas": ["type"]}, "s2exp_node": {"S2Efun": [-1, [], {"s2exp_srt": {"S2RTbas": ["t@ype"]}, "s2exp_node": {"S2Ecst": [{"s2cst_stamp": 421}]}}]}}, "d2cst_stamp": 56}]
,
"d2varmap":
[{"d2var_sym": "acker", "d2var_stamp": 181}, {"d2var_sym": "m", "d2var_stamp": 182}, {"d2var_sym": "n", "d2var_stamp": 183}]
,
"d2eclist":
[{"d2ecl_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 108(line=8, offs=1) -- 143(line=8, offs=36)", "d2ecl_node": {"D2Cstaload": [[], "/home/hwxi/research/Postiats/git/prelude/DATS/integer.dats"]}}, {"d2ecl_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 166(line=12, offs=1) -- 370(line=27, offs=4)", "d2ecl_node": {"D2Cfundecs": ["FK_fun", {}, [{"f2undec_loc": "/home/hwxi/research/Postiats/git/doc/EXA\
MPLE/INTRO/acker1.dats: 170(line=12, offs=5) -- 370(line=27, offs=4)"
, "f2undec_var": {"d2var_stamp": 181}, "f2undec_def": {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 176(line=13, offs=1) -- 370(line=27, offs=4)", "d2exp_node": {"D2Elam_dyn": [0, -1, [{"p2at_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 180(line=14, offs=3) -- 186(line=14, offs=9)", "p2at_node": {"P2Tann": [{"p2at_loc": "/h\
ome/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 180(line=14, offs=3) -- 181(line=14, offs=4)"
, "p2at_node": {"P2Tvar": [{"d2var_stamp": 182}]}}, {"s2exp_srt": {"S2RTbas": ["t@ype"]}, "s2exp_node": {"S2Eapp": [{"s2exp_srt": {"S2RTfun": [[{"S2RTbas": ["tkind"]}], {"S2RTbas": ["t@ype"]}]}, "s2exp_node": {"S2Ecst": [{"s2cst_stamp": 200}]}}, [{"s2exp_srt": {"S2RTbas": ["tkind"]}, "s2exp_node": {"S2Eextkind": ["atstype_int"]}}]]}}]}}, {"p2at\
_loc"
: "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 188(line=14, offs=11) -- 194(line=14, offs=17)", "p2at_node": {"P2Tann": [{"p2at_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 188(line=14, offs=11) -- 189(line=14, offs=12)", "p2at_node": {"P2Tvar": [{"d2var_stamp": 183}]}}, {"s2exp_srt": {"S2RTbas": ["t@ype"]}, "s2exp_node": {"S2Eapp": [{"s2exp_srt": {"S2RTfun": [[{"S2RTbas": ["tkind"]}], {"S2RTbas": [\
"t@ype"]}]}, "s2exp_node": {"S2Ecst": [{"s2cst_stamp": 200}]}}, [{"s2exp_srt": {"S2RTbas": ["tkind"]}, "s2exp_node": {"S2Eextkind": ["atstype_int"]}}]]}}]}}], {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 199(line=15, offs=5) -- 370(line=27, offs=4)", "d2exp_node": {"D2Eann_seff": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 199(line=15, offs=5) -- 370(line=27, offs=4)", "d2exp_node\
"
: {"D2Eann_type": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 205(line=15, offs=11) -- 370(line=27, offs=4)", "d2exp_node": {"D2Elet": [[], {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 215(line=18, offs=1) -- 346(line=25, offs=4)", "d2exp_node": {"D2Eifhead": [{}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 218(line=18, offs=4) -- 224(line=18, o\
ffs=10)"
, "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 220(line=18, offs=6) -- 222(line=18, offs=8)", "d2exp_node": {"D2Esym": [{"d2sym_sym": "<="}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 218(line=18, offs=4) -- 224(line=18, offs=10)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 218(line=18, offs=4) --\
 219(line=18, offs=5)"
, "d2exp_node": {"D2Evar": [{"d2var_stamp": 182}]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 223(line=18, offs=9) -- 224(line=18, offs=10)", "d2exp_node": {"D2Ei0nt": ["0"]}}]]}]]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 232(line=19, offs=8) -- 235(line=19, offs=11)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/E\
XAMPLE/INTRO/acker1.dats: 233(line=19, offs=9) -- 234(line=19, offs=10)"
, "d2exp_node": {"D2Esym": [{"d2sym_sym": "+"}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 232(line=19, offs=8) -- 235(line=19, offs=11)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 232(line=19, offs=8) -- 233(line=19, offs=9)", "d2exp_node": {"D2Evar": [{"d2var_stamp": 183}]}}, {"d2exp_loc": "/h\
ome/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 234(line=19, offs=10) -- 235(line=19, offs=11)"
, "d2exp_node": {"D2Ei0nt": ["1"]}}]]}]]}}, [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 249(line=21, offs=5) -- 323(line=23, offs=39)", "d2exp_node": {"D2Eifhead": [{}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 252(line=21, offs=8) -- 258(line=21, offs=14)", "d2exp_node"\
: {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 254(line=21, offs=10) -- 256(line=21, offs=12)", "d2exp_node": {"D2Esym": [{"d2sym_sym": "<="}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 252(line=21, offs=8) -- 258(line=21, offs=14)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 252(line=21, offs=8) -- 253(line=21, offs=9\
)"
, "d2exp_node": {"D2Evar": [{"d2var_stamp": 183}]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 257(line=21, offs=13) -- 258(line=21, offs=14)", "d2exp_node": {"D2Ei0nt": ["0"]}}]]}]]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 270(line=22, offs=12) -- 284(line=22, offs=26)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker\
1.dats: 270(line=22, offs=12) -- 275(line=22, offs=17)"
, "d2exp_node": {"D2Evar": [{"d2var_stamp": 181}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 276(line=22, offs=18) -- 284(line=22, offs=26)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 277(line=22, offs=19) -- 280(line=22, offs=22)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc\
/EXAMPLE/INTRO/acker1.dats: 278(line=22, offs=20) -- 279(line=22, offs=21)"
, "d2exp_node": {"D2Esym": [{"d2sym_sym": "-"}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 277(line=22, offs=19) -- 280(line=22, offs=22)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 277(line=22, offs=19) -- 278(line=22, offs=20)", "d2exp_node": {"D2Evar": [{"d2var_stamp": 182}]}}, {"d2exp_loc\
"
: "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 279(line=22, offs=21) -- 280(line=22, offs=22)", "d2exp_node": {"D2Ei0nt": ["1"]}}]]}]]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 282(line=22, offs=24) -- 283(line=22, offs=25)", "d2exp_node": {"D2Ei0nt": ["1"]}}]]}]]}}, [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 296(line=23, offs=12) -- 323(line=23, offs=3\
9)"
, "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 296(line=23, offs=12) -- 301(line=23, offs=17)", "d2exp_node": {"D2Evar": [{"d2var_stamp": 181}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 302(line=23, offs=18) -- 323(line=23, offs=39)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 303(line=23, offs=19) --\
 306(line=23, offs=22)"
, "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 304(line=23, offs=20) -- 305(line=23, offs=21)", "d2exp_node": {"D2Esym": [{"d2sym_sym": "-"}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 303(line=23, offs=19) -- 306(line=23, offs=22)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 303(li\
ne=23, offs=19) -- 304(line=23, offs=20)"
, "d2exp_node": {"D2Evar": [{"d2var_stamp": 182}]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 305(line=23, offs=21) -- 306(line=23, offs=22)", "d2exp_node": {"D2Ei0nt": ["1"]}}]]}]]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 308(line=23, offs=24) -- 322(line=23, offs=38)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/resear\
ch/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 308(line=23, offs=24) -- 313(line=23, offs=29)"
, "d2exp_node": {"D2Evar": [{"d2var_stamp": 181}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 314(line=23, offs=30) -- 322(line=23, offs=38)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 315(line=23, offs=31) -- 316(line=23, offs=32)", "d2exp_node": {"D2Evar": [{"d2var_stamp":\
 
182}]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 318(line=23, offs=34) -- 321(line=23, offs=37)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 319(line=23, offs=35) -- 320(line=23, offs=36)", "d2exp_node": {"D2Esym": [{"d2sym_sym": "-"}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 318(line=23, offs=34) \
-- 321(line=23, offs=37)"
, [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 318(line=23, offs=34) -- 319(line=23, offs=35)", "d2exp_node": {"D2Evar": [{"d2var_stamp": 183}]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 320(line=23, offs=36) -- 321(line=23, offs=37)", "d2exp_node": {"D2Ei0nt": ["1"]}}]]}]]}}]]}]]}}]]}]]}}]]}}]]}}]}}, {"s2exp_srt": {"S2RTbas": ["t@ype"]}, "s2exp_node":\
 
{"S2Eapp": [{"s2exp_srt": {"S2RTfun": [[{"S2RTbas": ["tkind"]}], {"S2RTbas": ["t@ype"]}]}, "s2exp_node": {"S2Ecst": [{"s2cst_stamp": 200}]}}, [{"s2exp_srt": {"S2RTbas": ["tkind"]}, "s2exp_node": {"S2Eextkind": ["atstype_int"]}}]]}}]}}, {}]}}]}}, "f2undec_ann": []}]]}}, {"d2ecl_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 411(line=31, offs=1) -- 500(line=38, offs=4)", "d2ecl_node": {"D2Cimpdec": [0, {"i2mpdec_loc": "/home/h\
wxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 421(line=32, offs=1) -- 500(line=38, offs=4)"
, "i2mpdec_locid": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 421(line=32, offs=1) -- 426(line=32, offs=6)", "i2mpdec_cst": {"d2cst_stamp": 56}, "i2mpdec_imparg": {}, "i2mpdec_tmparg": {}, "i2mpdec_tmpgua": {}, "i2mpdec_def": {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 427(line=32, offs=7) -- \
500(line=38, offs=4)"
, "d2exp_node": {"D2Elam_dyn": [0, -1, [], {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 432(line=32, offs=12) -- 500(line=38, offs=4)", "d2exp_node": {"D2Eann_funclo": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 432(line=32, offs=12) -- 500(line=38, offs=4)", "d2exp_node": {"D2Eann_seff": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker\
1.dats: 432(line=32, offs=12) -- 500(line=38, offs=4)"
, "d2exp_node": {"D2Eann_type": [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 432(line=32, offs=12) -- 500(line=38, offs=4)", "d2exp_node": {"D2Elet": [[{"d2ecl_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 439(line=34, offs=1) -- 477(line=34, offs=39)", "d2ecl_node": {"D2Cvaldecs": ["VK_val", [{"v2aldec_loc": "/home/hwxi/research/Postiat\
s/git/doc/EXAMPLE/INTRO/acker1.dats: 443(line=34, offs=5) -- 477(line=34, offs=39)"
, "v2aldec_pat": {"p2at_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 443(line=34, offs=5) -- 445(line=34, offs=7)", "p2at_node": {"P2Tempty": []}}, "v2aldec_def": {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 448(line=34, offs=10) -- 476(line=34, offs=38)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home/hwx\
i/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 448(line=34, offs=10) -- 457(line=34, offs=19)"
, "d2exp_node": {"D2Eignored": []}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 459(line=34, offs=21) -- 476(line=34, offs=38)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 459(line=34, offs=21) -- 476(line=34, offs=38)", "d2exp_node": {"D2Eapplst": [{"d2exp_loc": "/home\
/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 472(line=34, offs=34) -- 473(line=34, offs=35)"
, "d2exp_node": {"D2Esym": [{"d2sym_sym": "="}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 459(line=34, offs=21) -- 476(line=34, offs=38)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 459(line=34, offs=21) -- 471(line=34, offs=33)", "d2exp_node": {"D2Eapplst": [{"\
d2exp_loc"
: "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 459(line=34, offs=21) -- 464(line=34, offs=26)", "d2exp_node": {"D2Evar": [{"d2var_stamp": 181}]}}, [{"D2EXPARGdyn": [-1, "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 465(line=34, offs=27) -- 471(line=34, offs=33)", [{"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 466(line=34, offs=28) -- 467(line=34, offs=29)", "d2exp_node\
"
: {"D2Ei0nt": ["3"]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 469(line=34, offs=31) -- 470(line=34, offs=32)", "d2exp_node": {"D2Ei0nt": ["3"]}}]]}]]}}, {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAMPLE/INTRO/acker1.dats: 474(line=34, offs=36) -- 476(line=34, offs=38)", "d2exp_node": {"D2Ei0nt": ["61"]}}]]}]]}}]]}]]}}, "v2aldec_ann": {}}]]}}], {"d2exp_loc": "/home/hwxi/research/Postiats/git/doc/EXAM\
PLE/INTRO/acker1.dats: 481(line=36, offs=1) -- 500(line=38, offs=4)"
, "d2exp_node": {"D2Eempty": []}}]}}, {"s2exp_srt": {"S2RTbas": ["t@ype"]}, "s2exp_node": {"S2Ecst": [{"s2cst_stamp": 421}]}}]}}, {}]}}, {"funclo_name": "FUNCLOfun", "funclo_arglst": []}]}}]}}}]}}]
}





Artyom Shalkhakov

unread,
Dec 12, 2014, 11:45:59 PM12/12/14
to ats-lan...@googlegroups.com
On Saturday, December 13, 2014 10:12:15 AM UTC+6, gmhwxi wrote:
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

For instance, the command-line below:

patsopt --jsonize-2 ${PATSHOME}/doc/EXAMPLE/INTRO/acker1.dats

generates the JSON text included at the end of this message. The text can be readily
parsed. An example of doing so can be found in the UTFPL0 directory:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/UTFPL0

In ATS, level-2 syntax is used after fixities (infix, prefix and postfix) and bindings are resolved.

If you ever want to design/implement a language, then you can use this tool to get going quickly.
This is especially so if you want to play with fancy types as the concrete syntax of ATS allows
the programmer to readily add type-annotations. I myself intend to use the tool for teaching PL
and compilers.


Thanks for making this possible! Last time I tried to JSONize some simple ATS2 code I was baffled by the output. I decided to wait until you make some documentation or code available for learning how to deal with JSONized ATS syntax trees.

Hongwei Xi

unread,
Dec 13, 2014, 1:25:19 AM12/13/14
to ats-lan...@googlegroups.com
You are welcome.

As I said, parsing level-2 JSONized syntax is entirely straightforward. You should have no
problem following the code in the following directory:
If someone is familiar with pretty-printing (e.g., Ocaml has good packages for doing it), it would
be really nice to build a tool for pretty-printing ATS source code based on the level-2 JSONized syntax.

Cheers!


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/62b8fc91-9171-45d2-836c-7159b30f7c3c%40googlegroups.com.

Yannick Duchêne

unread,
Dec 17, 2014, 3:37:52 PM12/17/14
to ats-lan...@googlegroups.com


Le samedi 13 décembre 2014 05:12:15 UTC+1, gmhwxi a écrit :
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

Just out of curiosity, why JSON instead of simple XML 1.0?
 

For instance, the command-line below:

patsopt --jsonize-2 ${PATSHOME}/doc/EXAMPLE/INTRO/acker1.dats

generates the JSON text included at the end of this message. The text can be readily
parsed. An example of doing so can be found in the UTFPL0 directory:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/UTFPL0

In ATS, level-2 syntax is used after fixities (infix, prefix and postfix) and bindings are resolved.

What is “binding”  in this context? Some kind of name resolution?


If you ever want to design/implement a language, then you can use this tool to get going quickly.
This is especially so if you want to play with fancy types as the concrete syntax of ATS allows
the programmer to readily add type-annotations. I myself intend to use the tool for teaching PL
and compilers.

Does it mean one can generate ATS source from a constructed JSON representation?

Brandon Barker

unread,
Dec 17, 2014, 3:41:12 PM12/17/14
to ats-lang-users
On Wed, Dec 17, 2014 at 3:37 PM, 'Yannick Duchêne' via ats-lang-users <ats-lan...@googlegroups.com> wrote:


Le samedi 13 décembre 2014 05:12:15 UTC+1, gmhwxi a écrit :
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

Just out of curiosity, why JSON instead of simple XML 1.0?

I'd also been wanting to ask this question for a while, since JSON is sort of the "untyped" version of XML, but I guess that may not matter very much (not sure).

Apparently, XML is rather unpleasant to parse; it seems nobody wants to use it these days except Java developers ;). /ducks
 
 

For instance, the command-line below:

patsopt --jsonize-2 ${PATSHOME}/doc/EXAMPLE/INTRO/acker1.dats

generates the JSON text included at the end of this message. The text can be readily
parsed. An example of doing so can be found in the UTFPL0 directory:

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/UTFPL0

In ATS, level-2 syntax is used after fixities (infix, prefix and postfix) and bindings are resolved.

What is “binding”  in this context? Some kind of name resolution?


If you ever want to design/implement a language, then you can use this tool to get going quickly.
This is especially so if you want to play with fancy types as the concrete syntax of ATS allows
the programmer to readily add type-annotations. I myself intend to use the tool for teaching PL
and compilers.

Does it mean one can generate ATS source from a constructed JSON representation?

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

gmhwxi

unread,
Dec 17, 2014, 4:39:18 PM12/17/14
to ats-lan...@googlegroups.com

>>Just out of curiosity, why JSON instead of simple XML 1.0?

JSON is more compact. Converting from JSON to XML should be straightforward.


>>What is “binding”  in this context? Some kind of name resolution?

Yes. Namespace handling is included.

Dealing with namespaces is non-trivial in language design and implementation.
Often, this issue is ignored at the start. See how languages like PHP and Perl evolve.

>>Does it mean one can generate ATS source from a constructed JSON representation?

The "raw" source is referred to as level-0 syntax, which translates into level-1 syntax after
the fixity issue is dealt with. Often it is not a good idea to handle fixity using the kind of technique
in the implementation of a simple calculator.

From level-2 syntax, one cannot not recover level-0 syntax. However, you can implement
pretty-printing on level-2 syntax so as to get "prettified" source :)



gmhwxi

unread,
Dec 20, 2014, 11:17:47 PM12/20/14
to ats-lan...@googlegroups.com

I want mention another motivation for jsonizing level-2 syntax:

ATS2 is implemented in ATS1. Jsonization of level-2 syntax makes it possible
to write various program analysis tools for ATS2 in ATS2 (instead of ATS1).

Trust me on this: If you program for a while in ATS2, then you would not want to go
back to ATS1 anymore :)
...

Yannick Duchêne

unread,
Feb 11, 2015, 10:58:07 AM2/11/15
to ats-lan...@googlegroups.com


Le samedi 13 décembre 2014 05:12:15 UTC+1, gmhwxi a écrit :
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

For instance, the command-line below:

patsopt --jsonize-2 ${PATSHOME}/doc/EXAMPLE/INTRO/acker1.dats

generates the JSON text included at the end of this message. The text can be readily
parsed. An example of doing so can be found in the UTFPL0 directory:

For me, a `-d` option has to be added before the file name, otherwise I get an error about an unrecognised option, ex:

     waring(ATS): unrecognized command line argument [test.dats] is ignored.

Also there is a bug: end of line escaped characters (`\n`) in string literals, are turned into real end of line in the output, which the JSON output, invalid. Ex:

    …  "Hello\n" …

is turned into this:

     … "Hello
     " …


Hongwei Xi

unread,
Feb 11, 2015, 12:42:41 PM2/11/15
to ats-lan...@googlegroups.com
Yes, the command-line should be:

patsopt --jsonize-2 -d ${PATSHOME}/doc/EXAMPLE/INTRO/acker1.dats


>>Also there is a bug: end of line escaped characters (`\n`) in string literals, are turned into real end of line in the output, which the JSON output, invalid.

I have fixed this one. Changes are in ATS2-0.1.9 pre-release.


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

William Blair

unread,
Feb 11, 2015, 2:34:09 PM2/11/15
to ats-lan...@googlegroups.com
I was working with the --jsonize-2 format when I ran into some unexpected behaviour. I wanted to export the following datatype to JSON with the goal of automatically generating a parser for it.

    abst@ype prop

    datatype constraint =
        | ConstraintProp of (prop)
        | ConstraintConj of (List0(constraint))
        | ConstraintDisj of (List0(constraint))

But when I run patsopt with "--jsonize-2", some of the information is missing. For instance, there are several s2vars referenced in the "d2eclist" in the constructors, but there are no entries in s2varmap. It looks like a couple of s2csts are missing in s2cstmap as well. For instance, the s2cst_stamp "45" is referenced two times in s2cstmap, but 45 does not have an entry in the map.

You can see the formatted JSON output here:

http://pastebin.com/wmNXaUiA

Is this the expected output for level-2 syntax?

Thanks,
Will
Message has been deleted

gmhwxi

unread,
Feb 11, 2015, 9:43:44 PM2/11/15
to ats-lan...@googlegroups.com
I took a look at the issue.

It seems that the cause is due to List0 being expanded.

Whether a type definition should or should not be expanded depends on what
the the application wants to do. So my fix is to simply output syntax for unexpanded
types. Changes have been uploaded.

William Blair

unread,
Feb 12, 2015, 11:17:26 AM2/12/15
to ats-lan...@googlegroups.com
Thanks for the fix! Emitting syntax for unexpanded types works fine for my purpose since List0 gives me all the info I need.

Yannick Duchêne

unread,
Feb 14, 2015, 11:20:10 PM2/14/15
to ats-lan...@googlegroups.com
Using Postiat 0.1.8, investigating the JSON data for `basics_dyn.sats`, for the declaration at line 46:
     
     sortdef t0p = t@ype and vt0p = vt@ype

I find a `d2eclist/2/d2ecl_node/D2Cnone`, which is empty. Is this on purpose or is this a issue related to the one solved for Postiat 0.1.9?

A different case, at line 190, is this declaration:

     overload ~ with lazy_vt_free

For this one I get a `d2eclist/39/d2ecl_node/D2Cignored`, which is more explicit, and looks to be as it is on purpose. Is there a way to not ignore this and get a populated node instead?

gmhwxi

unread,
Feb 15, 2015, 6:50:53 PM2/15/15
to ats-lan...@googlegroups.com


On Saturday, February 14, 2015 at 11:20:10 PM UTC-5, Yannick Duchêne wrote:
Using Postiat 0.1.8, investigating the JSON data for `basics_dyn.sats`, for the declaration at line 46:
     
     sortdef t0p = t@ype and vt0p = vt@ype

I find a `d2eclist/2/d2ecl_node/D2Cnone`, which is empty. Is this on purpose or is this a issue related to the one solved for Postiat 0.1.9?

In level-2 syntax, all static definitions have been stored in a map. It would be a bit involved to output this map in JSON format.
 

A different case, at line 190, is this declaration:

     overload ~ with lazy_vt_free

For this one I get a `d2eclist/39/d2ecl_node/D2Cignored`, which is more explicit, and looks to be as it is on purpose. Is there a way to not ignore this and get a populated node instead?

I will handle this shortly. 

gmhwxi

unread,
Feb 16, 2015, 12:03:52 AM2/16/15
to ats-lan...@googlegroups.com
Done. Should be available in the next release.
For now, please try the pre-release of ATS2-0.1.9:

http://www.ats-lang.org/Downloads.html

Yannick Duchêne

unread,
Feb 16, 2015, 12:43:26 AM2/16/15
to ats-lan...@googlegroups.com


Le lundi 16 février 2015 06:03:52 UTC+1, gmhwxi a écrit :
Done. Should be available in the next release.
For now, please try the pre-release of ATS2-0.1.9:

http://www.ats-lang.org/Downloads.html

Confirmed: I now get a `/d2eclist/39/d2ecl_node/D2Coverload/0`  whose value is `~`.

Yannick Duchêne

unread,
Feb 17, 2015, 3:41:53 PM2/17/15
to ats-lan...@googlegroups.com


Le samedi 13 décembre 2014 05:12:15 UTC+1, gmhwxi a écrit :
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

I can't tell if it's a bug or not, so I'm reporting this in case it really is one.

I can't generate JSON data for `lib/ats2-postiats-0.1.9/prelude/SATS/array.sats`. I wondered if it would terminate or not: `patsopt` was running since an hour at full CPU speed, 1.83 GHz, when I stopped it. Memory usage was 21MB (stable, the same during the whole hour), so that was not an issue with memory.

I stopped it because I had no way to know if it was trapped in an infinite recursion.

Was it?

Yannick Duchêne

unread,
Feb 17, 2015, 4:07:56 PM2/17/15
to ats-lan...@googlegroups.com
I have not waited so long for these ones, but their seems to hang `patsopt --jsonize-2` too:

     lib/ats2-postiats-0.1.9/prelude/SATS/array.sats
     lib/ats2-postiats-0.1.9/prelude/SATS/matrix.sats
     lib/ats2-postiats-0.1.9/prelude/SATS/string.sats
     lib/ats2-postiats-0.1.9/prelude/DATS/filebas.dats
     lib/ats2-postiats-0.1.9/prelude/DATS/strptr.dats
     lib/ats2-postiats-0.1.9/prelude/DATS/string.dats

As said in the prior message, I don't assert it's an infinite recursion, I just wonder if it is.

Yannick Duchêne

unread,
Feb 17, 2015, 5:09:07 PM2/17/15
to ats-lan...@googlegroups.com


Le mercredi 11 février 2015 18:42:41 UTC+1, gmhwxi a écrit :

>>Also there is a bug: end of line escaped characters (`\n`) in string literals, are turned into real end of line in the output, which the JSON output, invalid.

I have fixed this one. Changes are in ATS2-0.1.9 pre-release.


A character escape issue remains: in `doc/EXAMPLE/INTRO/hello.dats`, there are many Unicode characters. In the generated JSON, these are escaped as `\NNN`, which is not valid JSON. The proper way to escape these characters is `\uNNNN`: `\u` followed by four digits for character in the BMP (whose code point are 16 bits) and characters beyond the BMP are to be encoded as UTF‑16 16 bits word paires (yes, unfortunately less direct), according to the JSON specification, on printed page 9 (displayed page 10): http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf .

Ex. `\344` should be `\u0344`.

Fixing the case of characters from the BMP is obvious: just use `\u` and pad left with `0` up to four digits next to the `\u`. The case of characters beyond de BMP is less obvious, and fortunately, these ones are rare (however common in some use case). I will search the Unicode reference for the exact encoding to be applied.

gmhwxi

unread,
Feb 17, 2015, 6:03:33 PM2/17/15
to ats-lan...@googlegroups.com
You waited long enough :)

There are clearly non-terminating tail calls.

It is a bug. It had been there but not triggered until 'overload' was handled.

Now it is fixed. Please try pre-release of ATS2-0.1.9.

gmhwxi

unread,
Feb 17, 2015, 6:31:38 PM2/17/15
to ats-lan...@googlegroups.com

Thanks for pointing this out!

I fixed this. For now I only handle UTF-8.

I have never understood why people want UTF-16. They could use UTF-8 or UTF-32.
But why UTF-16 :)

Yannick Duchêne

unread,
Feb 17, 2015, 6:51:22 PM2/17/15
to ats-lan...@googlegroups.com


Le mercredi 18 février 2015 00:31:38 UTC+1, gmhwxi a écrit :

Thanks for pointing this out!

I fixed this. For now I only handle UTF-8.


If you mean output to JSON as‑is, the same byte sequence as in the source file (except for control characters), assuming it's UTF-8, then the JSON standard does not specify it (it's left at applications discretion), however, this should be OK, and is indeed the most simple solution, and there is no more escape needed, except for control characters (the ones in the range 0 .. 31).
 
I have never understood why people want UTF-16. They could use UTF-8 or UTF-32.
But why UTF-16 :)

Neither I am. It's related to JavaScript: JavaScript uses UTF-16 strings (either UCS-2 or UTF-16, and UTF-16 by default, and this is so, by specification, not implementations details), and JSON came from the JavaScript world.

Otherwise, one of UTF-32 or UTF-8 should be the only one Unicode encodings for everything, except internal representations and only if there is a good reason to.

Yannick Duchêne

unread,
Feb 19, 2015, 2:47:14 AM2/19/15
to ats-lan...@googlegroups.com


Le samedi 13 décembre 2014 05:12:15 UTC+1, gmhwxi a écrit :
Patsopt can be used to turn ATS source code into a serialized representation in JSON.

What means the number “2”  near to everywhere, like in “p2at_node” instead of “pat_node”? Is this to remind the syntax level?

gmhwxi

unread,
Feb 19, 2015, 8:00:49 AM2/19/15
to ats-lan...@googlegroups.com
Yes.

ATS compiler consists of the following translations:

Trans1: level-0 to level-1: resolving fixity issues
Trans2: level-1 to level-2: handling binding issues
Trans3: level-2 to level-3: typechecking
Trans4: level-3 to level-4: erasing type indices and proofs; preparing for emitting C code

Yannick Duchêne

unread,
Jun 24, 2018, 5:51:26 PM6/24/18
to ats-lang-users
In https://github.com/Hibou57/PostiATS-Utilities , I added a `doc` directory with a file to help with the interpretation of JSON output. The main file is `json-ref.txt` which requires to read `json-ref-ref.md` before, since the latter explains how to read the former.
Reply all
Reply to author
Forward
0 new messages