Rev 70 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
92 | daniel-mar | 1 | <?php |
43 | daniel-mar | 2 | |
3 | define('SIGNAL_END_OF_TRANSMISSION', chr(1).chr(2).chr(3).chr(4).chr(5).chr(6).chr(7).chr(8)); |
||
4 | define('SIGNAL_TERMINATE', chr(8).chr(7).chr(6).chr(5).chr(4).chr(3).chr(2).chr(1)); |
||
5 | |||
6 | class FastPHPExitSignalReceivedException extends Exception { |
||
7 | |||
8 | } |
||
9 | |||
10 | abstract class FastPHPIcon { |
||
11 | private $type; // arbitary identifier |
||
12 | private $visibility; // 1=private, 2=protected, 3=public(default) |
||
13 | private $abstractFinal; // 'A', 'F', ''(default) |
||
14 | private $static; // true, false(default) |
||
15 | |||
16 | public function setType($type) { |
||
17 | $this->type = $type; |
||
18 | } |
||
19 | public function getType() { |
||
20 | return $this->type; |
||
21 | } |
||
22 | |||
23 | public function setAbstract() { |
||
24 | $this->abstractFinal = 'A'; |
||
25 | } |
||
26 | public function isAbstract() { |
||
27 | return $this->abstractFinal == 'A'; |
||
28 | } |
||
29 | |||
30 | public function setFinal() { |
||
31 | $this->abstractFinal = 'F'; |
||
32 | } |
||
33 | public function isFinal() { |
||
34 | return $this->abstractFinal == 'F'; |
||
35 | } |
||
36 | |||
37 | public function setStatic() { |
||
38 | $this->static = true; |
||
39 | } |
||
40 | public function isStatic() { |
||
41 | return $this->static; |
||
42 | } |
||
43 | |||
44 | public function setPrivate() { |
||
45 | $this->visibility = 1; |
||
46 | } |
||
47 | public function isPrivate() { |
||
48 | return $this->visibility == 1; |
||
49 | } |
||
50 | |||
51 | public function setProtected() { |
||
52 | $this->visibility = 2; |
||
53 | } |
||
54 | public function isProtected() { |
||
55 | return $this->visibility == 2; |
||
56 | } |
||
57 | |||
58 | public function setPublic() { |
||
59 | $this->visibility = 3; |
||
60 | } |
||
61 | public function isPublic() { |
||
62 | return $this->visibility == 3; |
||
63 | } |
||
64 | |||
65 | public function reset() { |
||
66 | $this->type = null; |
||
67 | $this->visibility = 3; |
||
68 | $this->abstractFinal = ''; |
||
69 | $this->static = false; |
||
70 | } |
||
71 | |||
72 | public function __construct() { |
||
73 | $this->reset(); |
||
74 | } |
||
75 | |||
76 | public abstract function imageIndex(); |
||
77 | } |
||
78 | |||
79 | class FastPHPReader { |
||
80 | public static function readCodeFromEditor() { |
||
81 | $lines = array(); |
||
82 | while ($f = fgets(STDIN)){ |
||
83 | if (trim($f) == SIGNAL_END_OF_TRANSMISSION) break; |
||
84 | |||
85 | // Signal to terminate the code explorer |
||
86 | if (trim($f) == SIGNAL_TERMINATE) { |
||
87 | throw new FastPHPExitSignalReceivedException(); |
||
88 | } |
||
89 | |||
90 | $lines[] = $f; |
||
91 | } |
||
92 | return implode("", $lines); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | class FastPHPWriter { |
||
97 | |||
98 | public static function outputLeafNode(/*FastPHPIcon*/ $icon, /*int*/ $lineNo, /*string*/ $description) { |
||
70 | daniel-mar | 99 | $iconImageIndex = is_null($icon) ? -1 : $icon->imageIndex(); |
43 | daniel-mar | 100 | echo 'N'.($iconImageIndex == -1 ? '____' : sprintf('%04s', $iconImageIndex)). |
101 | sprintf('%08s', $lineNo). |
||
102 | sprintf('%04s', strlen(trim($description))). |
||
103 | trim($description). |
||
104 | "\n"; |
||
105 | } |
||
106 | |||
107 | public static function outputIncreaseLevel() { |
||
108 | echo "I\n"; |
||
109 | } |
||
110 | |||
111 | public static function outputDecreaseLevel() { |
||
112 | echo "D\n"; |
||
113 | } |
||
114 | |||
115 | public static function outputExit() { |
||
116 | echo "X\n"; |
||
117 | } |
||
118 | |||
119 | public static function signalOutputEnd() { |
||
120 | echo "\n".SIGNAL_END_OF_TRANSMISSION."\n"; |
||
121 | } |
||
122 | |||
123 | public static function outputHeader() { |
||
124 | echo "FAST100!"; |
||
125 | } |
||
126 | |||
127 | } |