Monday, September 18, 2017

Interpret This

Apparently I love writing interpreters. I guess it's kind of par for the course when you're creating console Java applications.
 
The user inputs commands and you parse them and route to the correct class and method and finally give some output back.
 
I usually build an Input class that will give me the command and whatever parameters or other text the user put in, so I have handy String[]s as well as various Strings and a Match boolean so I can flag it true if I find the command the user is trying to fire.
 
I use the Input object with Parse methods that always have a return of List<String> and whatever ends up in there gets outputted.
 
If I want to extend the capabilities of my project, I create a new class, give it a Parse method, and in my Parser class, add a call to that method and grab the returning List<String> ... and of course unless it's a special case, if I get a list of .size() > 0 then I flag my Input as Match(true). Anytime Match is true, I don't call any more parser methods. - Again there may be exceptions.
 
I'm sure there are better ways of doing this but so far the structure above seems to work really well for me.
Have fun interpreterizing!

No comments:

Post a Comment

From Shotcut to Kdenlive

So I've been using Shotcut for a while now, for my YouTube videos... and music videos. I love the application. Slicing clips, doing fade...