ฉันกำลังพยายามรวบรวมสตริงซอร์สโค้ดและพิมพ์แผนผังการแยกวิเคราะห์โดยใช้ Poly/ML รหัสต่อไปนี้คอมไพล์ แต่ต้นไม้แยกว่างเปล่า:
fun main () =
let
val stream = TextIO.openString "let val a = \"abc\"; val b = \"def\"; val c = a ^ b in print c end";
val _ = PolyML.compiler (fn () => TextIO.input1 stream, []);
val (_, parseTree) = !PolyML.IDEInterface.parseTree
in
PolyML.print (parseTree);
PolyML.print (List.length parseTree);
List.map PolyML.print (parseTree);
()
end
กำลังดำเนินการสิ่งนี้:
$ ./a.out
[...]
0
$
ฉันต้องทำอย่างไรจึงจะได้ parse tree จากคอมไพเลอร์? ฉันยังลองใช้รูปแบบโดยใช้พารามิเตอร์คอมไพเลอร์ CPCompilerResultFun
แต่สิ่งนี้ก็ไม่ได้ผลเช่นกัน:
fun main () =
let
fun useTree (NONE, _) () =
(PolyML.print "not parsed"; ())
| useTree (SOME parseTree, _) () =
(PolyML.print "parsed"; PolyML.print parseTree; ());
val stream = TextIO.openString "let val a = \"abc\"; val b = \"def\"; val c = a ^ b in print c end";
val _ = PolyML.compiler (fn () => TextIO.input1 stream, [PolyML.Compiler.CPCompilerResultFun useTree]);
in
()
end
การรันสิ่งนี้ไม่ได้สร้างเอาต์พุตใดๆ