自己抽了一下lisp的简单BNF定义(不全,后边再续)
list -> "[" atom ("," atom)* "]" atom -> digit | id | list digit -> [0-9]+ id -> [a-zA-Z_][a-zA-Z]*
如果用javacc写一个分析器,则可以实现一个简单的嵌入式脚本,呵呵。
在网上找了一个比较全的,在这里贴出来:
letter ::= "A" | "B" | ... | "Z", number ::= "1" | "2" | ... | "9", atomic_symbol ::= letter atom_part, atom_part ::= empty | letter atom_part | number atom_part, empty ::= "", S_expression ::= atomic_symbol | "(" S_expression "."S_expression ")" | list, list ::= "(" S_expression # S_expression ")".
有了形式定义,再就是找时间实现了。