Backus-Naur Form语法验证器

时间:2016-12-15 17:10:05

标签: compilation binary-tree conditional-compilation

我想知道如何编写一个程序来读取存在BNF形式规则的文件,并验证它是否属于该语言的短语。 例如:

rule = ident "=" exp ";" ;
exp = art_expr | call_fn_exp;
art_expr = art_expr |"("art_expr")" | art_expr art_oper art_expr | numeric;
numeric = integer | decimal;
integer = signe  digit [exponentiel digit];
decimal = signe digit float_part;
float_part = "." exponentiel digit;
signe= ["+"|"-"] {signe};
exponentiel = ("e"|"E") ["+"|"-"];
digit =  "0".."9" {digit};
art_oper = "+"|"-"|"/"|"-"|"%";
call_fn_exp = ident"("optargs")";
optargs =  exp {"," exp};
ident = (letter|"_") {digit|letter|"_"};
letter =  "a".."z" | "A".."Z";

如何检查(12) + add(12,15) + 12是否有效?

0 个答案:

没有答案