Select Page

Interpreter

Interpreter

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

Source code

/**  * Declares an abstract Interpret operation that is common to all nodes in the  * abstract syntax tree.  *   * @role __InterpreterExpression  */ public abstract class AbstractExpression {         public abstract void interpret(Context context);}  /**  * Builds an abstract syntax tree representing a particular sentence in the  * language that the grammar defines. Invokes the Interpret operation.  */ public class Client {         public AbstractExpression getExpression() {                 // put your code to create expression here                 return null;        }          public void sampleOperation() {                 Context context = new Context();                
getExpression().interpret(context);
} } /** * Contains information that is global to interpreter. * * @role __InterpreterContext */ public class Context { } /** * One such class is required for every rule in the grammar. */ public class NonterminalExpression extends AbstractExpression { public void interpret(Context context) { // put your code here } } /** * Implements an Interpret operation associated with terminal symbols in the * grammar. */ public class TerminalExpression extends AbstractExpression { public void interpret(Context context) { // put your code here } }

About The Author

I worked with various Insurances companies across Switzerland on online applications handling billion premium volumes. I love to continuously spark my creativity in many different and challenging open-source projects fueled by my great passion for innovation and blockchain technology.In my technical role as a senior software engineer and Blockchain consultant, I help to define and implement innovative solutions in the scope of both blockchain and traditional products, solutions, and services. I can support the full spectrum of software development activities, starting from analyzing ideas and business cases and up to the production deployment of the solutions.I'm the Founder and CEO of Disruptr GmbH.

Categories