Andy
Andy

Reputation: 8949

Write a simple interpreter, or find one I can use?

I need a very simple interpreter that is written in Java. The language is going to be simple.

I just need string operators, like "contains and equals". I need logically AND, OR. Along with parenthesis.

"some string" CONTAINS "ring" AND ("some string" EQUALS "input" OR "some other string" CONTAINS "other")

This simply needs to evaluate to true or false.

Are there any open source intrepetors that would evaluate a language similar this? Would I be better off just writing my own?

Upvotes: 0

Views: 968

Answers (2)

lhballoti
lhballoti

Reputation: 806

May be overkill, but you could use JavaCC to generate a parser for your language, then traverse the generated syntax tree for your input in order to evaluate the expression.

Upvotes: 3

Bob Black
Bob Black

Reputation: 2405

Beanshell might be appropriate for what you're trying to accomplish. It offers dynamic execution of Java code that you can invoke from your app.

It's also open-source, so if you wanted to just see how it works you could do that too.

Upvotes: 1

Related Questions