|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--fri.patterns.interpreter.parsergenerator.semantics.ReflectSemantic
Semantic base class that tries to call methods with the same name as nonterminal on left side of rule. The number of parameters of the method must be the same as the number of symbols on the right side of the rule, all parameters must be of type Object, and the return type must be Object. The method might process the parse results and return an arbitrary Object to be processed by another callback method. The ranges of the currently dispatched rule is available by protected getRanges() method.
Example: Both rulesexpression ::= expression "+" term ; expression ::= expression "-" term ;would be dispatched by
public Object expression(Object expression, Object operator, Object term) { int e = ((Integer) expression).intValue(); int t = ((Integer) term).intValue(); if (operator.equals("+")) return new Integer(e + t); else if (operator.equals("-")) return new Integer(e - t); else throw new IllegalArgumentException("Unknown operator: "+operator); }
Calculator
Constructor Summary | |
ReflectSemantic()
|
Method Summary | |
java.lang.Object |
doSemantic(Rule rule,
java.util.List inputTokens,
java.util.List ranges)
Tries to find a method with same name as left side of rule and number of arguments as much as elements in inputTokens list. |
protected java.lang.Object |
fallback(Rule rule,
java.util.List inputTokens,
java.util.List ranges)
Fallback semantic handler that is called when no method was found by reflection. |
protected java.util.List |
getRanges()
Returns the current Token.Range list of all input tokens. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ReflectSemantic()
Method Detail |
public java.lang.Object doSemantic(Rule rule, java.util.List inputTokens, java.util.List ranges)
doSemantic
in interface Semantic
rule
- the rule that was recognized by the parser.inputTokens
- all semantic call returns from underlying rules, collected according to current rule.ranges
- all line ranges for parseResults elements. Cast elements to Token.Range
to get the start and end position of every Object in parseResult List.
protected java.lang.Object fallback(Rule rule, java.util.List inputTokens, java.util.List ranges)
protected java.util.List getRanges()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |