looking for a tutorial and ideally source code, for a simple interpreter that reads a grammar file containing Token definitions [using regular expressions]and the allowed syntax for the Tokens. I.e. BNF or similar with a set of rules. The interpreter will read input from a source file and interpret this based on the specified grammar. The solution must be able to react dynamically to changing the BNF. For example, if the BNF is modified and the interpreter run again then a different behaviour may be expected as a result of modifying the grammar.
for example:-
file: grammar.txt contains:-
TOKENS
split = "\t " // tab or hard space to sp0lit tokens
INT = "(0-9)+" // integer: single digit followed by any number of digits
ADD = "add" // literal
MINUS = "minus" // literal
RULES
Expr ::= Term (ADD Term | MINUS Term)*
Term ::= (INT | Expr )
probably got the grammar wrong but you get the idea ?!
Looking for solution in JAVA please
What I have tried:
just search google
found many a project on compilers, not many interpreters. the compiler projects create source code from the BNF. That's not what I want
the interpreters are hard coded so cannot respond to changes in the BNF. That's not what I want either
found this but it requires CUP Jlex ?? whatrever they are, which muddies the water and the BNF is not something I recognise or want to work wit; it also creates code which isn't what I want - that's more like a compiler.
BNF Converter Tutorial[
^]
thanks in advance