Java Code Examples for org.antlr.runtime.tree.Tree#getCharPositionInLine()
The following examples show how to use
org.antlr.runtime.tree.Tree#getCharPositionInLine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionBlock.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
/** * Parse a tree for piece-wice linear membership function * @param tree : Tree to parse * @return A new membership function */ private MembershipFunction fclTreeFuzzifyTermPieceWiseLinear(Tree tree) { if (debug) Gpr.debug("Tree: " + tree.toStringTree()); int numberOfPoints = tree.getChildCount() - 1; if (debug) Gpr.debug("\tNumber of points: " + numberOfPoints); Value x[] = new Value[numberOfPoints]; Value y[] = new Value[numberOfPoints]; for (int childNum = 1; childNum < tree.getChildCount(); childNum++) { Tree child = tree.getChild(childNum); if (debug) Gpr.debug("\t\tChild: " + child.toStringTree()); String leaveName = child.getText(); // It's a set of points? => Defines a piece-wise linear membership function if (leaveName.equalsIgnoreCase("POINT")) { x[childNum - 1] = new Value(child.getChild(0), this); // Parse and add each point y[childNum - 1] = new Value(child.getChild(1), this); if (debug) Gpr.debug("\t\tParsed point " + childNum + " x=" + x[childNum - 1] + ", y=" + y[childNum - 1]); if ((y[childNum - 1].getValue() < 0) || (y[childNum - 1].getValue() > 1)) throw new RuntimeException("\n\tError parsing line " + child.getLine() + " character " + child.getCharPositionInLine() + ": Membership function out of range (should be between 0 and 1). Value: '" + y[childNum - 1] + "'\n\tTree: " + child.toStringTree()); } else throw new RuntimeException("Unknown (or unimplemented) option : " + leaveName); } return new MembershipFunctionPieceWiseLinear(x, y); }
Example 2
Source File: FunctionBlock.java From jFuzzyLogic with GNU Lesser General Public License v3.0 | 6 votes |
/** * Parse a tree for singletons membership function series of points * @param tree : Tree to parse * @param numberOfPoints : Number of points in this function * @return A new membership function */ private MembershipFunction fclTreeFuzzifyTermSingletonsPoints(Tree tree, int numberOfPoints) { if (debug) Gpr.debug("Tree: " + tree.toStringTree()); Value x[] = new Value[numberOfPoints]; Value y[] = new Value[numberOfPoints]; for (int childNum = 0; childNum < tree.getChildCount(); childNum++) { Tree child = tree.getChild(childNum); String leaveName = child.getText(); if (debug) Gpr.debug("Sub-Parsing: " + leaveName); // It's a set of points? => Defines a piece-wise linear membership function if (leaveName.equalsIgnoreCase("(")) { x[childNum] = new Value(child.getChild(0), this); // Parse and add each point y[childNum] = new Value(child.getChild(1), this); if ((y[childNum].getValue() < 0) || (y[childNum].getValue() > 1)) throw new RuntimeException("\n\tError parsing line " + child.getLine() + " character " + child.getCharPositionInLine() + ": Membership function out of range (should be between 0 and 1). Value: '" + y[childNum] + "'\n\tTree: " + child.toStringTree()); if (debug) Gpr.debug("Parsed point " + childNum + " x=" + x[childNum] + ", y=" + y[childNum]); } else throw new RuntimeException("Unknown (or unimplemented) option : " + leaveName); } return new MembershipFunctionGenericSingleton(x, y); }