Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits
Interpreter Print E-mail
User Rating: / 0
PoorBest 
Thursday, 20 January 2005 21:36
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 } }

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

designpattern  java 
Powered By Joomla Tags

Comments
Add New Search RSS
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:):grin;)8):p:roll:eek:upset:zzz:sigh:?:cry
:(:x
Please input the anti-spam code that you can read in the image.

3.20 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Friday, 17 June 2005 23:43 )
 


Another articles:


Content View Hits : 2891835

Enter Amount: