sensagent's content
Dictionary and translator for handheld
New : sensagent is now available on your handheld
Advertising ▼
Webmaster Solution
Alexandria
A windows (pop-into) of information (full-content of Sensagent) triggered by double-clicking any word on your webpage. Give contextual explanation and translation from your sites !
SensagentBox
With a SensagentBox, visitors to your site can access reliable information on over 5 million pages provided by Sensagent.com. Choose the design that fits your site.
Business solution
Improve your site content
Add new content to your site from Sensagent by XML.
Crawl products or adds
Get XML access to reach the best products.
Index images and define metadata
Get XML access to fix the meaning of your metadata.
Please, email us to describe your idea.
Lettris
Lettris is a curious tetris-clone game where all the bricks have the same square shape but different content. Each square carries a letter. To make squares disappear and save space for other squares you have to assemble English words (left, right, up, down) from the falling squares.
boggle
Boggle gives you 3 minutes to find as many words (3 letters or more) as you can in a grid of 16 letters. You can also try the grid of 16 letters. Letters must be adjacent and longer words score better. See if you can get into the grid Hall of Fame !
English dictionary
Main references
Most English definitions are provided by WordNet .
English thesaurus is mainly derived from The Integral Dictionary (TID).
English Encyclopedia is licensed by Wikipedia (GNU).
Copyrights
The wordgames anagrams, crossword, Lettris and Boggle are provided by Memodata.
The web service Alexandria is granted from Memodata for the Ebay search.
The SensagentBox are offered by sensAgent.
Translation
Change the target language to find translations.
Tips: browse the semantic fields (see From ideas to words) in two languages to learn more.
last searches on the dictionary :
computed in 0.047s
|
|
This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (November 2008) |
In computer programming, the interpreter pattern is a design pattern that specifies how to evaluate sentences in a language. The basic idea is to have a class for each symbol (terminal or nonterminal) in a specialized computer language. The syntax tree of a sentence in the language is an instance of the composite pattern and is used to evaluate (interpret) the sentence.[1]
Contents |
The following Reverse Polish notation example illustrates the interpreter pattern. The grammar
expression ::= plus | minus | variable | number defines a language which contains reverse Polish expressions like:
plus ::= expression expression '+'
minus ::= expression expression '-'
variable ::= 'a' | 'b' | 'c' | ... | 'z'
digit = '0' | '1' | ... '9'
number ::= digit | digit number
a b + Following the interpreter pattern there is a class for each grammar rule.
a b c + -
a b + c a - -
import java.util.Map; interface Expression { public int interpret(Map<String,Expression> variables); } class Number implements Expression { private int number; public Number(int number) { this.number = number; } public int interpret(Map<String,Expression> variables) { return number; } } class Plus implements Expression { Expression leftOperand; Expression rightOperand; public Plus(Expression left, Expression right) { leftOperand = left; rightOperand = right; } public int interpret(Map<String,Expression> variables) { return leftOperand.interpret(variables) + rightOperand.interpret(variables); } } class Minus implements Expression { Expression leftOperand; Expression rightOperand; public Minus(Expression left, Expression right) { leftOperand = left; rightOperand = right; } public int interpret(Map<String,Expression> variables) { return leftOperand.interpret(variables) - rightOperand.interpret(variables); } } class Variable implements Expression { private String name; public Variable(String name) { this.name = name; } public int interpret(Map<String,Expression> variables) { if(null==variables.get(name)) return 0; //Either return new Number(0). return variables.get(name).interpret(variables); } }
While the interpreter pattern does not address parsing[2] a parser is provided for completeness.
import java.util.Map; import java.util.Stack; class Evaluator implements Expression { private Expression syntaxTree; public Evaluator(String expression) { Stack<Expression> expressionStack = new Stack<Expression>(); for (String token : expression.split(" ")) { if (token.equals("+")) { Expression subExpression = new Plus(expressionStack.pop(), expressionStack.pop()); expressionStack.push( subExpression ); } else if (token.equals("-")) { // it's necessary remove first the right operand from the stack Expression right = expressionStack.pop(); // ..and after the left one Expression left = expressionStack.pop(); Expression subExpression = new Minus(left, right); expressionStack.push( subExpression ); } else expressionStack.push( new Variable(token) ); } syntaxTree = expressionStack.pop(); } public int interpret(Map<String,Expression> context) { return syntaxTree.interpret(context); } }
Finally evaluating the expression "w x z - +" with w = 5, x = 10, and z = 42.
import java.util.Map; import java.util.HashMap; public class InterpreterExample { public static void main(String[] args) { String expression = "w x z - +"; Evaluator sentence = new Evaluator(expression); Map<String,Expression> variables = new HashMap<String,Expression>(); variables.put("w", new Number(5)); variables.put("x", new Number(10)); variables.put("z", new Number(42)); int result = sentence.interpret(variables); System.out.println(result); } }
| The Wikibook Computer Science Design Patterns has a page on the topic of |
|
|||||||||||