last but not the least

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class MyGrammar
def initialize
end
end
exampleaxiom = '$AXIOM E\n';
axiomregexp = Regexp.new(/\$AXIOM ([A-Z]\'{0,1})\\n/)
axiom = axiomregexp.match(exampleaxiom)[1]
print axiom, "\n"
#RubyVM::InstructionSequence.compile("print \"привет\"").eval
\$AXIOM ([A-Z]\'{0,1})\\n\$NTERM(( [A-Z]\'{0,1})+)\\n\$TERM(( "[a-z\*\+\(\)]")+)\\n((\$RULE (([A-Z]\'{0,1}) =(([( [A-Z]\'{0,1})( \"[a-z]\"| \"\*\"| \"\+\"| \"\(\"| \"\)\")]+\\n| \$EPS\\n)+)))+)
# каждую рулю парсим отдельно
# $AXIOM E\n$NTERM E' T T' F\n$TERM "+" "*" "(" ")" "n"\n$RULE E = T T' "n" "*"\n T "+"\n F "("\n$RULE Y = Q\n W\n $EPS\n