org.apache.sysds.parser

## Class Expression

- java.lang.Object
- - org.apache.sysds.parser.Expression

- All Implemented Interfaces:
    ParseInfo
  Direct Known Subclasses:
    BinaryExpression, BooleanExpression, ExpressionList, Identifier, IterablePredicate, RelationalExpression

      public abstract class Expression
      extends Object
      implements ParseInfo

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Expression.BinaryOp` Binary operators.
    `static class` | `Expression.BooleanOp` Boolean operators.
    `static class` | `Expression.DataOp` Data operators.
    `static class` | `Expression.FunctCallOp` Function call operators.
    `static class` | `Expression.RelationalOp` Relational operators.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Expression()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Types.DataType` | `computeDataType(Expression expression1, Expression expression2, boolean cast)` Compute data type based on expressions.
    `static Types.DataType` | `computeDataType(Identifier identifier1, Identifier identifier2, boolean cast)` Compute data type based on identifiers.
    `static Types.ValueType` | `computeValueType(Expression expression1, Expression expression2, boolean cast)` Compute value type based on expressions.
    `static Types.ValueType` | `computeValueType(Expression expr1, Types.ValueType v1, Types.ValueType v2, boolean cast)`
    `static Types.ValueType` | `computeValueType(Identifier identifier1, Identifier identifier2, boolean cast)` Compute value type based on identifiers.
    `static Types.FileFormat` | `convertFormatType(String format)` Convert string format type to `Hop.FileFormatTypes`.
    `boolean` | `equals(Object that)`
    `int` | `getBeginColumn()`
    `int` | `getBeginLine()`
    `static MatrixCharacteristics` | `getBinaryMatrixCharacteristics(Expression expression1, Expression expression2)` Returns the matrix characteristics for scalar-scalar, scalar-matrix, matrix-scalar, matrix-matrix operations.
    `static Expression.BinaryOp` | `getBinaryOp(String val)` Convert string value to binary operator.
    `static Expression.BooleanOp` | `getBooleanOp(String val)` Convert string value to boolean operator.
    `int` | `getEndColumn()`
    `int` | `getEndLine()`
    `String` | `getFilename()`
    `Identifier` | `getOutput()` Obtain identifier.
    `Identifier[]` | `getOutputs()` Obtain identifiers.
    `ArrayList<String>` | `getParseExceptionList()`
    `static Expression.RelationalOp` | `getRelationalOp(String val)` Convert string value to relational operator.
    `static String` | `getTempName()` Obtain temporary name ("parsertemp" + _tempId) for expression.
    `String` | `getText()`
    `int` | `hashCode()`
    `String` | `printErrorLocation()`
    `String` | `printInfoLocation()` Return info message containing the filename, the beginning line position, and the beginning column position.
    `String` | `printWarningLocation()`
    `void` | `raiseValidateError(String message)` Throw a LanguageException with the message.
    `void` | `raiseValidateError(String message, boolean conditional)` Throw a LanguageException with the message if conditional is `false`; otherwise log the message as a warning.
    `void` | `raiseValidateError(String msg, boolean conditional, String errorCode)` Throw a LanguageException with the message (and optional error code) if conditional is `false`; otherwise log the message as a warning.
    `abstract Expression` | `rewriteExpression(String prefix)`
    `void` | `setBeginColumn(int passed)`
    `void` | `setBeginLine(int passed)`
    `void` | `setCtxValues(org.antlr.v4.runtime.ParserRuleContext ctx)` Set ParserRuleContext values (begin line, begin column, end line, end column, and text).
    `void` | `setCtxValuesAndFilename(org.antlr.v4.runtime.ParserRuleContext ctx, String filename)` Set ParserRuleContext values (begin line, begin column, end line, end column, and text) and file name.
    `void` | `setEndColumn(int passed)`
    `void` | `setEndLine(int passed)`
    `void` | `setFilename(String passed)`
    `void` | `setOutput(Identifier output)`
    `void` | `setParseExceptionList(ArrayList<String> passed)`
    `void` | `setParseInfo(ParseInfo parseInfo)` Set parse information.
    `void` | `setText(String text)`
    `void` | `validateExpression(HashMap<String,DataIdentifier> ids, HashMap<String,ConstIdentifier> currConstVars, boolean conditional)`
    `void` | `validateExpression(MultiAssignmentStatement mas, HashMap<String,DataIdentifier> ids, HashMap<String,ConstIdentifier> currConstVars, boolean conditional)`
    `abstract VariableSet` | `variablesRead()`
    `abstract VariableSet` | `variablesUpdated()`

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.sysds.parser.ParseInfo

      `ctxAndFilenameToParseInfo`

- - ### Constructor Detail

    - #### Expression

          public Expression()

  - ### Method Detail

    - #### rewriteExpression

          public abstract Expression rewriteExpression(String prefix)

    - #### setOutput

          public void setOutput(Identifier output)

    - #### getOutput

          public Identifier getOutput()

      Obtain identifier.
      Returns:
        Identifier

    - #### getOutputs

          public Identifier[] getOutputs()

      Obtain identifiers.
      Returns:
        Identifiers

    - #### validateExpression

          public void validateExpression(HashMap<String,DataIdentifier> ids,
                                         HashMap<String,ConstIdentifier> currConstVars,
                                         boolean conditional)

    - #### validateExpression

          public void validateExpression(MultiAssignmentStatement mas,
                                         HashMap<String,DataIdentifier> ids,
                                         HashMap<String,ConstIdentifier> currConstVars,
                                         boolean conditional)

    - #### getBinaryOp

          public static Expression.BinaryOp getBinaryOp(String val)

      Convert string value to binary operator.
      Parameters:
        `val` - String value ('+', '-', '*', '/', '%%', '%/%', '^', %*%')
      Returns:
        Binary operator (`BinaryOp.PLUS`, `BinaryOp.MINUS`, `BinaryOp.MULT`, `BinaryOp.DIV`, `BinaryOp.MODULUS`, `BinaryOp.INTDIV`, `BinaryOp.POW`, `BinaryOp.MATMULT`). Returns `BinaryOp.INVALID` if string value not recognized.

    - #### getRelationalOp

          public static Expression.RelationalOp getRelationalOp(String val)

      Convert string value to relational operator.
      Parameters:
        `val` - String value ('<', '<=', '>', '>=', '==', '!=')
      Returns:
        Relational operator (`RelationalOp.LESS`, `RelationalOp.LESSEQUAL`, `RelationalOp.GREATER`, `RelationalOp.GREATEREQUAL`, `RelationalOp.EQUAL`, `RelationalOp.NOTEQUAL`). Returns `RelationalOp.INVALID` if string value not recognized.

    - #### getBooleanOp

          public static Expression.BooleanOp getBooleanOp(String val)

      Convert string value to boolean operator.
      Parameters:
        `val` - String value ('&&', '&', '||', '|', '!')
      Returns:
        Boolean operator (`BooleanOp.CONDITIONALAND`, `BooleanOp.LOGICALAND`, `BooleanOp.CONDITIONALOR`, `BooleanOp.LOGICALOR`, `BooleanOp.NOT`). Returns `BooleanOp.INVALID` if string value not recognized.

    - #### convertFormatType

          public static Types.FileFormat convertFormatType(String format)

      Convert string format type to `Hop.FileFormatTypes`.
      Parameters:
        `format` - String format type ("text", "binary", "mm", "csv")
      Returns:
        Format as `Hop.FileFormatTypes`. Can be `FileFormatTypes.TEXT`, `FileFormatTypes.BINARY`, `FileFormatTypes.MM`, or `FileFormatTypes.CSV`. Unrecognized type is set to `FileFormatTypes.TEXT`.

    - #### getTempName

          public static String getTempName()

      Obtain temporary name ("parsertemp" + _tempId) for expression. Used to construct Hops from parse tree.
      Returns:
        Temporary name of expression.

    - #### variablesRead

          public abstract VariableSet variablesRead()

    - #### variablesUpdated

          public abstract VariableSet variablesUpdated()

    - #### computeDataType

          public static Types.DataType computeDataType(Expression expression1,
                                                       Expression expression2,
                                                       boolean cast)

      Compute data type based on expressions. The identifier for each expression is obtained and passed to `computeDataType(Identifier, Identifier, boolean)`. If the identifiers have the same data type, the shared data type is returned. Otherwise, if `cast` is `true` and one of the identifiers is a matrix and the other identifier is a scalar, return `DataType.MATRIX`. Otherwise, throw a LanguageException.
      Parameters:
        `expression1` - First expression
        `expression2` - Second expression
        `cast` - Whether a cast should potentially be performed
      Returns:
        The data type (`Types.DataType`)

    - #### computeDataType

          public static Types.DataType computeDataType(Identifier identifier1,
                                                       Identifier identifier2,
                                                       boolean cast)

      Compute data type based on identifiers. If the identifiers have the same data type, the shared data type is returned. Otherwise, if `cast` is `true` and one of the identifiers is a matrix and the other identifier is a scalar, return `DataType.MATRIX`. Otherwise, throw a LanguageException.
      Parameters:
        `identifier1` - First identifier
        `identifier2` - Second identifier
        `cast` - Whether a cast should potentially be performed
      Returns:
        The data type (`Types.DataType`)

    - #### computeValueType

          public static Types.ValueType computeValueType(Expression expression1,
                                                         Expression expression2,
                                                         boolean cast)

      Compute value type based on expressions. The identifier for each expression is obtained and passed to `computeValueType(Identifier, Identifier, boolean)`. If the identifiers have the same value type, the shared value type is returned. Otherwise, if `cast` is `true` and one value type is a double and the other is an int, return `ValueType.DOUBLE`. If `cast` is `true` and one value type is a string or the other value type is a string, return `ValueType.STRING`. Otherwise, throw a LanguageException.
      Parameters:
        `expression1` - First expression
        `expression2` - Second expression
        `cast` - Whether a cast should potentially be performed
      Returns:
        The value type (`Types.ValueType`)

    - #### computeValueType

          public static Types.ValueType computeValueType(Identifier identifier1,
                                                         Identifier identifier2,
                                                         boolean cast)

      Compute value type based on identifiers. If the identifiers have the same value type, the shared value type is returned. Otherwise, if `cast` is `true` and one value type is a double and the other is an int, return `ValueType.DOUBLE`. If `cast` is `true` and one value type is a string or the other value type is a string, return `ValueType.STRING`. Otherwise, throw a LanguageException.
      Parameters:
        `identifier1` - First identifier
        `identifier2` - Second identifier
        `cast` - Whether a cast should potentially be performed
      Returns:
        The value type (`Types.ValueType`)

    - #### computeValueType

          public static Types.ValueType computeValueType(Expression expr1,
                                                         Types.ValueType v1,
                                                         Types.ValueType v2,
                                                         boolean cast)

    - #### equals

          public boolean equals(Object that)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### raiseValidateError

          public void raiseValidateError(String message)

      Throw a LanguageException with the message.
      Parameters:
        `message` - the error message

    - #### raiseValidateError

          public void raiseValidateError(String message,
                                         boolean conditional)

      Throw a LanguageException with the message if conditional is `false`; otherwise log the message as a warning.
      Parameters:
        `message` - the error (or warning) message
        `conditional` - if `true`, display log warning message. Otherwise, the message will be thrown as a LanguageException

    - #### raiseValidateError

          public void raiseValidateError(String msg,
                                         boolean conditional,
                                         String errorCode)

      Throw a LanguageException with the message (and optional error code) if conditional is `false`; otherwise log the message as a warning.
      Parameters:
        `msg` - the error (or warning) message
        `conditional` - if `true`, display log warning message. Otherwise, the message (and optional error code) will be thrown as a LanguageException
        `errorCode` - optional error code

    - #### getBinaryMatrixCharacteristics

          public static MatrixCharacteristics getBinaryMatrixCharacteristics(Expression expression1,
                                                                             Expression expression2)

      Returns the matrix characteristics for scalar-scalar, scalar-matrix, matrix-scalar, matrix-matrix operations. This method is aware of potentially unknowns and matrix-vector (col/row) operations.
      Parameters:
        `expression1` - The first expression
        `expression2` - The second expression
      Returns:
        matrix characteristics [1] is the number of columns (clen), [2] is the number of rows in a block (blen), and [3] is the number of columns in a block (blen). Default (unknown) values are -1. Scalar values are all 0.

    - #### setFilename

          public void setFilename(String passed)

      Specified by:
        `setFilename` in interface `ParseInfo`

    - #### setBeginLine

          public void setBeginLine(int passed)

      Specified by:
        `setBeginLine` in interface `ParseInfo`

    - #### setBeginColumn

          public void setBeginColumn(int passed)

      Specified by:
        `setBeginColumn` in interface `ParseInfo`

    - #### setEndLine

          public void setEndLine(int passed)

      Specified by:
        `setEndLine` in interface `ParseInfo`

    - #### setEndColumn

          public void setEndColumn(int passed)

      Specified by:
        `setEndColumn` in interface `ParseInfo`

    - #### setText

          public void setText(String text)

      Specified by:
        `setText` in interface `ParseInfo`

    - #### setParseExceptionList

          public void setParseExceptionList(ArrayList<String> passed)

    - #### setParseInfo

          public void setParseInfo(ParseInfo parseInfo)

      Set parse information.
      Parameters:
        `parseInfo` - parse information, such as beginning line position, beginning column position, ending line position, ending column position, text, and filename

    - #### setCtxValues

          public void setCtxValues(org.antlr.v4.runtime.ParserRuleContext ctx)

      Set ParserRuleContext values (begin line, begin column, end line, end column, and text).
      Parameters:
        `ctx` - the antlr ParserRuleContext

    - #### setCtxValuesAndFilename

          public void setCtxValuesAndFilename(org.antlr.v4.runtime.ParserRuleContext ctx,
                                              String filename)

      Set ParserRuleContext values (begin line, begin column, end line, end column, and text) and file name.
      Parameters:
        `ctx` - the antlr ParserRuleContext
        `filename` - the filename (if it exists)

    - #### getFilename

          public String getFilename()

      Specified by:
        `getFilename` in interface `ParseInfo`

    - #### getBeginLine

          public int getBeginLine()

      Specified by:
        `getBeginLine` in interface `ParseInfo`

    - #### getBeginColumn

          public int getBeginColumn()

      Specified by:
        `getBeginColumn` in interface `ParseInfo`

    - #### getEndLine

          public int getEndLine()

      Specified by:
        `getEndLine` in interface `ParseInfo`

    - #### getEndColumn

          public int getEndColumn()

      Specified by:
        `getEndColumn` in interface `ParseInfo`

    - #### getText

          public String getText()

      Specified by:
        `getText` in interface `ParseInfo`

    - #### getParseExceptionList

          public ArrayList<String> getParseExceptionList()

    - #### printErrorLocation

          public String printErrorLocation()

    - #### printWarningLocation

          public String printWarningLocation()

    - #### printInfoLocation

          public String printInfoLocation()

      Return info message containing the filename, the beginning line position, and the beginning column position.
      Returns:
        the info message

Copyright © 2021 The Apache Software Foundation. All rights reserved.