| java.lang.Object fri.patterns.interpreter.parsergenerator.semantics.ReflectSemantic
All known Subclasses: fri.patterns.interpreter.parsergenerator.examples.Calculator,
ReflectSemantic | abstract public class ReflectSemantic implements Semantic(Code) | | 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 rules
expression ::= 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);
}
See Also: fri.patterns.interpreter.parsergenerator.examples.Calculator author: (c) 2000, Fritz Ritzberger |
Method Summary | |
public Object | doSemantic(Rule rule, List inputTokens, 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 Object | fallback(Rule rule, List inputTokens, List ranges) Fallback semantic handler that is called when no method was found by reflection. | protected List | getRanges() Returns the current Token.Range list of all input tokens. |
doSemantic | public Object doSemantic(Rule rule, List inputTokens, List ranges)(Code) | | Tries to find a method with same name as left side of rule and number of arguments
as much as elements in inputTokens list. All argument types are Object.
Parameters: rule - the rule that was recognized by the parser. Parameters: inputTokens - all semantic call returns from underlying rules, collected according to current rule. object to push on parser value-stack. |
fallback | protected Object fallback(Rule rule, List inputTokens, List ranges)(Code) | | Fallback semantic handler that is called when no method was found by reflection.
This method provides a default List aggregation for left recursive rules.
first list element if input list has only one element,a List if the passed rule is left recursive,else the unmodified inputTokens list. |
getRanges | protected List getRanges()(Code) | | Returns the current Token.Range list of all input tokens.
|
|
|