Compilation Backus-Naur形式语法验证器

Compilation Backus-Naur形式语法验证器,compilation,binary-tree,conditional-compilation,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

我想知道如何编写一个程序来读取一个文件,其中有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
是否有效