-
Notifications
You must be signed in to change notification settings - Fork 0
/
bnf.php
26 lines (24 loc) · 866 Bytes
/
bnf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
use LexicalAnalyzer\Parser;
use SyntaxAnalyzer\Analyzer;
require_once __DIR__ . '/testhelpers.php';
//<rule> ::= <identifier> "::=" <expression>
//<expression> ::= <factor> {term}
//<term> ::= "|" <factor>
//<factor> ::= <identifier> | <quoted_symbol> | <expression_c> | <expression_d> | <expression_e>
//<expression_c>::="(" <expression> ")"
//<expression_d>::="[" <expression> "]"
//<expression_e>::="{" <expression> "}"
//<identifier> ::= letter { letter | digit }
//<quoted_symbol> ::= ""
$s = '<rule>::=<identifier>"::="<expression>"::="<hello>
<hello>::=<identifier>"::="<expression><bb>
';
$lexParser = new Parser(\Parser\BnfParser::getLexRule());
$words = $lexParser->run($s);
//print_r($words);
$analyzer = new Analyzer(\Parser\BnfParser::getAnalyzerRules());
$rs = $analyzer->run($words);
print_r($rs);
var_dump(count($rs));
//$analyzer->showLog();