Venice 0.751beta

nz.org.venice.parser
Class Parser

java.lang.Object
  extended bynz.org.venice.parser.Parser

public class Parser
extends java.lang.Object

Parse a string into an executable expression. This class acts as a gatekeeper to the Gondala language which is used to perform manipulations on stock market quotes.

Langauge EBNF


 ROOT_EXPR         = [SUB_EXPR]+
 EXPR              = SUB_EXPR | "{" [SUB_EXPR]+ "}"
 SUB_EXPR          = BOOLEAN_EXPR [ LOGIC BOOLEAN_EXPR ]
 LOGIC             = "and" | "or"
 BOOLEAN_EXPR      = ADD_EXPR [ RELATION ADD_EXPR ]
 RELATION          = "==" | "<=" | ">=" | "<" | ">" | "!="
 ADD_EXPR          = MULTIPLY_EXPR [ ADD_OPERATOR MULTIPLY_EXPR ]
 ADD_OPERATOR      = "-" | "+"
 MULTIPLY_EXPR     = FACTOR [ MULTIPLY_OPERATOR FACTOR ]
 MULTIPLY_OPERATOR = "*" | "/"
 FACTOR            = STRING | VARIABLE | NUMBER | FUNCTION | FLOW_CONTROL | QUOTE | "(" SUB_EXPR ")"
 STRING            = "{a-zA-Z0-9}*"
 NUMBER            = ["-"]{0-9}+ ["." {0-9}+] | "true" | "false"
 VARIABLE_NAME     = {a-zA-Z}{a-zA-Z0-9_}*
 TYPE              = "boolean" | "float" | "int"
 VARIABLE          = [["const"] [TYPE]] VARIABLE_NAME ["=" SUB_EXPR]
 QUOTE             = "open" [ "(" SYMBOL ")" ] | "close" [ "(" SYMBOL ")" ] |
                        "low" [ "(" SYMBOL ")" ] | "high" [ "(" SYMBOL ")" | 
                        "volume" [ "(" SYMBOL ")" ] 
 SYMBOL            = {A-Za-z}*
 FUNCTION          = "lag" "(" QUOTE ["," SUB_EXPR] ")" |
                     "min" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "max" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "avg" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "sd" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "sum" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "rsi" "(" [SUB_EXPR ["," SUB_EXPR]] ")" |
                     "not" "(" SUB_EXPR ")" |
                     "percent" "(" SUB_EXPR "," SUB_EXPR ")" |
                     "dayofweek" "(" ")" |
                     "dayofyear" "(" ")" |
                     "day" "(" ")"       |
                     "month" "(" ")"     |
                     "year" "(" ")"      |
                     "sqrt" "(" SUB_EXPR ")" |
                     "abs" "(" SUB_EXPR ")" |
                     "corr" "(" STRING "," QUOTE "," SUB_EXPR ["," SUB_EXPR] ")"
                     "ema" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ["," SUB_EXPR] ")"
                     "bol_lower" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "bol_upper" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "macd" "(" QUOTE ["," SUB_EXPR] ")" |
                     "momentum" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "obv" "(" SUB_EXPR ["," SUB_EXPR] ["," SUB_EXPR] ")" |
                     "sd" "(" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")" |
                     "sin" "(" SUB_EXPR ")" |
                     "cos" "(" SUB_EXPR ")" |
                     "log" "(" SUB_EXPR ")" |
                     "exp" "(" SUB_EXPR ")" |
                     "dayfromstart" "(" ")" |
                     "capital" "(" ")" |
                     "stockcapital" "(" ")" |
                     "random" "(" SUB_EXPR ")"       |
                     "trend" (" QUOTE "," SUB_EXPR ["," SUB_EXPR] ")"
 FLOW_CONTROL      = "if"  "(" SUB_EXPR ")" EXPR "else" EXPR |
                     "for" "(" SUB_EXPR ";" SUB_EXPR ";" SUB_EXPR ")" EXPR |
                     "while" "(" SUB_EXPR ")" EXPR
 

Author:
Andrew Leppard

Method Summary
static Expression parse(java.lang.String string)
          Parse the given string into an executable expression.
static Expression parse(Variables variables, java.lang.String string)
          Parse the given string into an executable expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static Expression parse(Variables variables,
                               java.lang.String string)
                        throws ExpressionException
Parse the given string into an executable expression. The first argument allows you to parse any predefined variables which are available to the expression. Any variables defined by the expression will be added to this.

Parameters:
variables - any predefined variables.
string - the string to parse.
Returns:
the parsed expression.
Throws:
ExpressionException - if there was an error parsing the expression.

parse

public static Expression parse(java.lang.String string)
                        throws ExpressionException
Parse the given string into an executable expression.

Parameters:
string - the string to parse.
Returns:
the parsed expression.
Throws:
ExpressionException - if there was an error parsing the expression.

Venice 0.751beta