35{
39
40 const std::string mandelbrot_program =
41 " width := 118; "
42 " height := 41; "
43 " imag_max := +1; "
44 " imag_min := -1; "
45 " real_max := +1; "
46 " real_min := -2.5; "
47 " x_step := (real_max - real_min) / width; "
48 " y_step := (imag_max - imag_min) / height; "
49 " "
50 " for (var y := 0; y < height; y += 1) "
51 " { "
52 " imag := imag_min + (y_step * y); "
53 " "
54 " for (var x := 0; x < width; x += 1) "
55 " { "
56 " real := real_min + x_step * x; "
57 " z_real := real; "
58 " z_imag := imag; "
59 " "
60 " for (var n := 0; n < 30; n += 1) "
61 " { "
62 " a := z_real^2; "
63 " b := z_imag^2; "
64 " plot_value := n; "
65 " "
66 " if ((a + b) < 4) "
67 " { "
68 " z_imag := 2 * z_real * z_imag + imag; "
69 " z_real := a - b + real; "
70 " } "
71 " else "
72 " break; "
73 " }; "
74 " "
75 " putch(61 - plot_value); "
76 " }; "
77 " "
78 " println() "
79 " } ";
80
82
83 symbol_table_t symbol_table;
84 symbol_table.add_function(
"putch" ,
putch );
85 symbol_table.add_function("println", println);
86
87 expression_t expression;
88 expression.register_symbol_table(symbol_table);
89
90 parser_t parser;
91 parser.enable_unknown_symbol_resolver();
92 parser.compile(mandelbrot_program,expression);
93
94 expression.value();
95}