Lines Matching +full:red +full:- +full:x
16 Vincent Tscherter, tscherter@tscherter.net, Solothurn, 2009-01-18
18 2009-01-18 version 0.1 first release
19 2009-01-02 version 0.2
20 - title und comment literal added
21 - ";" als terminator-symbol added
22 2023-09-28 version 0.3 prefixed all constants
23 2025-09-05 version 0.4 PHP 8 compatibility and other fixes
43 $ebnf_lexemes[] = array( 'type' => EBNF_IDENTIFIER_TOKEN, 'expr' => "[a-zA-Z0-9_-]+" );
78 header('Content-Type: application/xml');
79 echo $dom->saveXML();
81 render_node($dom->firstChild, true);
84 header('Content-Type: text/plain');
86 $syntax = $dom->createElement("syntax");
87 $syntax->setAttribute('title', 'EBNF - Syntax Error');
88 $syntax->setAttribute('meta',
89 $e->getMessage()
90 . " - '" . substr($input, $e->getPos(), 30) . "...'"
92 $dom->appendChild($syntax);
93 render_node($dom->firstChild, true);
97 imageline($im, $x1+$r, $y1, $x2-$r, $y1, $black);
98 imageline($im, $x1+$r, $y2, $x2-$r, $y2, $black);
99 imageline($im, $x1, $y1+$r, $x1, $y2-$r, $black);
100 imageline($im, $x2, $y1+$r, $x2, $y2-$r, $black);
102 imagearc($im, $x2-$r, $y1+$r, 2*$r, 2*$r, 270, 360, $black);
103 imagearc($im, $x1+$r, $y2-$r, 2*$r, 2*$r, 90, 180, $black);
104 imagearc($im, $x2-$r, $y2-$r, 2*$r, 2*$r, 0, 90, $black);
108 global $white, $black, $blue, $red, $green, $silver;
114 $red = imagecolorallocate ($im, 255, 0, 0);
121 function arrow($image, $x, $y, $lefttoright) { argument
124 $points = array($x, $y - EBNF_U / 3, $x - EBNF_U, $y, $x, $y + EBNF_U / 3);
126 $points = array($x - EBNF_U, $y - EBNF_U / 3, $x, $y, $x - EBNF_U, $y + EBNF_U / 3);
137 global $white, $black, $blue, $red, $green, $silver;
138 if ($node->nodeName=='identifier' || $node->nodeName=='terminal') {
139 $text = html_entity_decode($node->getAttribute('value'));
144 if ($node->nodeName!='terminal') {
145 imagerectangle($im, EBNF_U, 0, $w-EBNF_U-1, $h-1, $black);
146 …gestring($im, EBNF_FONT, intval(2*EBNF_U), intval(($h-imagefontheight(EBNF_FONT))/2), $text, $re…
149 rr($im, EBNF_U, 0, $w-EBNF_U-1, $h-1, EBNF_U/2, $black);
150 imagestring($im, EBNF_FONT, intval(2*EBNF_U), intval(($h-imagefontheight(EBNF_FONT))/2),
154 imageline($im,$w-EBNF_U,EBNF_U, $w+1, EBNF_U, $black);
156 } else if ($node->nodeName=='option' || $node->nodeName=='loop') {
157 if ($node->nodeName=='loop')
159 $inner = render_node($node->firstChild, $lefttoright);
165 arrow($im, $w/2+EBNF_U/2, EBNF_U, $node->nodeName=='loop'?!$lefttoright:$lefttoright);
167 arrow($im, $w-2*EBNF_U, 3*EBNF_U, $lefttoright);
170 imageline($im,$w-EBNF_U,EBNF_U, $w-EBNF_U, 3*EBNF_U, $black);
171 imageline($im,$w-3*EBNF_U-1,3*EBNF_U, $w-EBNF_U, 3*EBNF_U, $black);
173 } else if ($node->nodeName=='sequence') {
177 $w = count($inner)*EBNF_U-EBNF_U; $h = 0;
183 $x = imagesx($inner[0])+EBNF_U;
185 imageline($im, $x-EBNF_U-1, EBNF_U, $x, EBNF_U, $black);
186 arrow($im, $x, EBNF_U, $lefttoright);
187 imagecopy($im, $inner[$i], $x, 0, 0,0, imagesx($inner[$i]), imagesy($inner[$i]));
188 $x += imagesx($inner[$i])+EBNF_U;
190 } else if ($node->nodeName=='choise') {
192 $h = (count($inner)-1)*EBNF_U; $w = 0;
198 imageline($im, $w-EBNF_U, EBNF_U, $w, EBNF_U, $black);
200 imageline($im, EBNF_U, $y+EBNF_U, $w-EBNF_U, $y+EBNF_U, $black);
203 arrow($im, $w-2*EBNF_U, $y+EBNF_U, $lefttoright);
208 imageline($im, $w-EBNF_U, EBNF_U, $w-EBNF_U, $top, $black);
210 } else if ($node->nodeName=='syntax') {
211 $title = $node->getAttribute('title');
212 $meta = $node->getAttribute('meta');
213 $node = $node->firstChild;
217 $names[] = $node->getAttribute('name');
218 $im = render_node($node->firstChild, $lefttoright);
220 $node = $node->nextSibling;
227 if ($title=='') $h -= 2*EBNF_U;
228 if ($meta=='') $h -= 2*EBNF_U;
233 imagestring($im, EBNF_FONT, EBNF_U, intval((2*EBNF_U-imagefontheight(EBNF_FONT))/2),
239 …agestring($im, EBNF_FONT, EBNF_U, intval($y-EBNF_U+(2*EBNF_U-imagefontheight(EBNF_FONT))/2), $name…
242 imageline($im, $wn+2*EBNF_U+imagesx($images[$i])-1, $y+EBNF_U, $w-EBNF_U, $y+EBNF_U, $black);
243 imageline($im, $w-EBNF_U, $y+EBNF_U/2, $w-EBNF_U ,$y+1.5*EBNF_U, $black);
246 imagestring($im, 1, EBNF_U, $h-2*EBNF_U+(2*EBNF_U-imagefontheight(1))/2,
248 rr($im, 0,0,$w-1, $h-1, EBNF_U/2, $green);
249 header('Content-Type: image/png');
257 $node = $node->firstChild;
260 $node = $node->nextSibling;
288 $syntax = $dom->createElement("syntax");
289 $syntax->setAttribute('meta', META);
290 $dom->appendChild($syntax);
293 $syntax->setAttribute('title',
294 stripcslashes(substr($token['value'], 1, strlen($token['value'])-2 )));
301 $syntax->appendChild(ebnf_parse_production($dom, $tokens, $i));
304 throw new EbnfException("Syntax must end with '}'", $tokens[count($tokens)-1]['pos']);
308 $syntax->setAttribute('meta',
309 stripcslashes(substr($token['value'], 1, strlen($token['value'])-2 )));
319 $production = $dom->createElement("rule");
320 $production->setAttribute('name', $token['value']);
324 $production->appendChild( ebnf_parse_expression($dom, $tokens, $i));
333 $choise = $dom->createElement("choise");
334 $choise->appendChild(ebnf_parse_term($dom, $tokens, $i));
338 $choise->appendChild(ebnf_parse_term($dom, $tokens, $i));
340 } return $mul ? $choise : $choise->removeChild($choise->firstChild);
344 $sequence = $dom->createElement("sequence");
346 $sequence->appendChild($factor);
350 $sequence->appendChild(ebnf_parse_factor($dom, $tokens, $i));
352 } return $mul ? $sequence: $sequence->removeChild($sequence->firstChild);
358 $identifier = $dom->createElement("identifier");
359 $identifier->setAttribute('value', $token['value']);
362 $literal = $dom->createElement("terminal");
363 …$literal->setAttribute('value', stripcslashes(substr($token['value'], 1, strlen($token['value'])-2…
372 $option = $dom->createElement("option");
373 $option->appendChild(ebnf_parse_expression($dom, $tokens, $i));
379 $loop = $dom->createElement("loop");
380 $loop->appendChild(ebnf_parse_expression($dom, $tokens, $i));
393 $this->pos = $pos;
398 return $this->pos;