http://www.eteks.com

com.eteks.parser
Class JavaSyntax

java.lang.Object
  |
  +--com.eteks.parser.AbstractSyntax
        |
        +--com.eteks.parser.JavaSyntax
All Implemented Interfaces:
Syntax

public class JavaSyntax
extends AbstractSyntax

Syntax used by parsers for functions and expressions written in Java. This syntax supports the Java unary and binary operators and the static methods of the java.lang.Math class. The multi parameters methods of java.lang.Math are implemented as Java functions implementing the Function interface and added to the syntax.
All the following operators, constants and functions are supported :

The operators priorities are the same as in Java.
The operator for assignment is =, brackets ( ) and the separator of parameters ,.
All the following operators are not supported : The literals may be any Java literal number. If extendedSyntax is equal to true, quoted characters and strings are also supported as literals.
The parsed identifiers (function name and its parameters) may be any Java identifier containing letters, digits, the characters $, _ or . (dots). The first character of an identifier must be a letter, the characters $ or _ (not a dot). No type checking is done during the parsing of functions and expressions but using a WrapperInterpreter interpreter enables to fill this lack at runtime.

Since:
Jeks 1.0
Version:
1.0.2
Author:
Emmanuel Puybaret
See Also:
FunctionParser, WrapperInterpreter

Fields inherited from interface com.eteks.parser.Syntax
CONDITION_ELSE, CONDITION_IF, CONDITION_THEN, CONSTANT_E, CONSTANT_FALSE, CONSTANT_PI, CONSTANT_TRUE, FUNCTION_ABS, FUNCTION_ACOS, FUNCTION_ASIN, FUNCTION_ATAN, FUNCTION_CEIL, FUNCTION_COS, FUNCTION_COSH, FUNCTION_EXP, FUNCTION_FLOOR, FUNCTION_INTEGER, FUNCTION_LN, FUNCTION_LOG, FUNCTION_NOT, FUNCTION_OPPOSITE, FUNCTION_ROUND, FUNCTION_SIN, FUNCTION_SINH, FUNCTION_SQR, FUNCTION_SQRT, FUNCTION_TAN, FUNCTION_TANH, OPERATOR_ADD, OPERATOR_BITWISE_AND, OPERATOR_BITWISE_NOT, OPERATOR_BITWISE_OR, OPERATOR_BITWISE_XOR, OPERATOR_DIFFERENT, OPERATOR_DIVIDE, OPERATOR_EQUAL, OPERATOR_GREATER, OPERATOR_GREATER_OR_EQUAL, OPERATOR_LESS, OPERATOR_LESS_OR_EQUAL, OPERATOR_LOGICAL_AND, OPERATOR_LOGICAL_NOT, OPERATOR_LOGICAL_OR, OPERATOR_LOGICAL_XOR, OPERATOR_MODULO, OPERATOR_MULTIPLY, OPERATOR_OPPOSITE, OPERATOR_POSITIVE, OPERATOR_POWER, OPERATOR_REMAINDER, OPERATOR_SHIFT_LEFT, OPERATOR_SHIFT_RIGHT, OPERATOR_SHIFT_RIGHT_0, OPERATOR_SUBSTRACT, USER_STARTING_KEY
 
Constructor Summary
JavaSyntax()
          Creates a Java syntax, that doesn't use an extended syntax (no boolean constants and strings).
JavaSyntax(boolean extendedSyntax)
          Creates a Java syntax.
 
Method Summary
 java.lang.Object getLiteral(java.lang.String expression, java.lang.StringBuffer extractedLiteral)
          Returns the value of the literal parsed from the string expression or null if expression doesn't start with a literal.
 boolean isJavaIdentifier(java.lang.String identifier)
          Returns true if the string identifier is a Java identifier.
 boolean isValidIdentifier(java.lang.String identifier)
          Returns true if the string identifier is a correctly written identifier usable as the name of a function or a paramater.
 
Methods inherited from class com.eteks.parser.AbstractSyntax
addFunction, getAssignmentOperator, getBinaryOperatorKey, getBinaryOperatorPriority, getClosingBracket, getCommonFunctionKey, getConditionPartCount, getConditionPartKey, getConstantKey, getDelimiters, getFunction, getOpeningBracket, getParameterSeparator, getUnaryOperatorKey, getWhiteSpaceCharacters, isCaseSensitive, isShortSyntax, removeFunction, setAssignmentOperator, setBinaryOperatorKey, setBinaryOperatorPriority, setClosingBracket, setCommonFunctionKey, setConditionPartKey, setConstantKey, setOpeningBracket, setParameterSeparator, setShortSyntax, setUnaryOperatorKey, setWhiteSpaceCharacters
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaSyntax

public JavaSyntax()
Creates a Java syntax, that doesn't use an extended syntax (no boolean constants and strings).

JavaSyntax

public JavaSyntax(boolean extendedSyntax)
Creates a Java syntax.
Parameters:
extendedSyntax - if equal to true, this syntax supports the boolean constants true and false and quoted strings and characters.
Method Detail

getLiteral

public java.lang.Object getLiteral(java.lang.String expression,
                                   java.lang.StringBuffer extractedLiteral)
Returns the value of the literal parsed from the string expression or null if expression doesn't start with a literal. If a literal is found at the beginning of expression, this method extracts the parsed literal in the string buffer extractedLiteral. The extracted literal is a number or if this instance supports an extended syntax, a string or a character.
Parameters:
expression - the string to parse.
extractedLiteral - the literal extracted from expression identified as a valid literal with the syntax of the parser.
Returns:
the value of the extracted literal or null if expression doesn't start with a valid literal. If the literal is a number, an instance of Number is returned, if the literal is a string an instance of String is returned and if the literal is a character an instance of Character is returned.
See Also:
com.eteks.parser.AbstractSyntax#getLiteralNumber

isValidIdentifier

public boolean isValidIdentifier(java.lang.String identifier)
Returns true if the string identifier is a correctly written identifier usable as the name of a function or a paramater.
Parameters:
identifier - the string to test.
Returns:
the result of isJavaIdentifier ().
See Also:
isJavaIdentifier(java.lang.String)

isJavaIdentifier

public boolean isJavaIdentifier(java.lang.String identifier)
Returns true if the string identifier is a Java identifier. An identifier of the syntax JavaSyntax may contain letters, digits, the characters $, _ or . (dots). The first character of identifier must be a letter, the characters $ or _ (not a dot). The dot allows to emulate static fields and methods of Java.
Parameters:
identifier - the string to test.
Returns:
true if identifier is a Java identifier.

&cp; 1998-2003 eTeks - All rights reserved