jmathlib.core.interpreter
Class Parser

java.lang.Object
  extended by jmathlib.core.interpreter.RootObject
      extended by jmathlib.core.interpreter.Parser
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ErrorCodes, TokenConstants

public class Parser
extends RootObject
implements TokenConstants, ErrorCodes

The parser uses the Lexer to produce a list of tokens which it builds into an abstract syntax tree.

See Also:
Serialized Form

Field Summary
 java.lang.String evaluationLockWords
           
 
Fields inherited from interface jmathlib.core.constants.TokenConstants
ADDSUB_PRIORITY, AND_PRIORITY, ANDAND_PRIORITY, ASSIGN_PRIORITY, BRACKET_PRIORITY, COMPARE_PRIORITY, CONCAT, MATRIX, MULDIV_PRIORITY, OR_PRIORITY, OROR_PRIORITY, PARAMETER, POWER_PRIORITY, RELATION_PRIORITY, SINGLE, ttDelimiter, ttNotSet, ttOperand, ttOperator
 
Fields inherited from interface jmathlib.core.constants.ErrorCodes
ERR_BRACKET_OPEN, ERR_BRACKET_ORDER, ERR_FUNCTION_NOT_FOUND, ERR_FUNCTION_NOT_IMPLEMENTED, ERR_INSUFFICIENT_PARAMETERS, ERR_INVALID_PARAMETER, ERR_LVALUE_REQUIRED, ERR_MATRIX_SINGULAR, ERR_NOT_SQUARE_MATRIX, ERR_OPNOTSUPPORTED, ERR_TOO_MANY_PARAMETERS, ERR_USER_ERROR, ERR_VARIABLE_NOTDEFINED, OK, OK_FUNCTION_PROCESS
 
Constructor Summary
Parser()
          default constructor - creates the Parser object with an empty string
 
Method Summary
 Token getNextToken()
          get next token from the lexical analyser
 java.lang.String getScannedLineOfCode()
          return the currently scanned line of code to identify the possible errors.
 OperandToken parseExpression(java.lang.String expression)
          Parse an expression and return an operand tree of the expression
 OperandToken parseRemainingExpression()
          parse remaining tokens of a m-function file or m-script file
 Token peekNextToken()
          get next Token from lexical analyser, without moving forward
 void setExpression(java.lang.String expression)
          set expression of a m-function file or m-script file.
 
Methods inherited from class jmathlib.core.interpreter.RootObject
clone, getContextList, getDebug, getFunctionManager, getGlobalVariables, getGraphicsManager, getInterpreter, getPluginsManager, getVariable, getVariables, getWorkingDirectory, setConstants, setDebug, setWorkingDirectory, toString, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

evaluationLockWords

public java.lang.String evaluationLockWords
Constructor Detail

Parser

public Parser()
default constructor - creates the Parser object with an empty string

Method Detail

parseExpression

public OperandToken parseExpression(java.lang.String expression)
Parse an expression and return an operand tree of the expression

Parameters:
expression - = a vector of tokens
Returns:
the parsed expressions as a tree of operands

setExpression

public void setExpression(java.lang.String expression)
set expression of a m-function file or m-script file. This method is used for parsing m-scripts/functions.

Parameters:
expression - = code of a function as a string

parseRemainingExpression

public OperandToken parseRemainingExpression()
parse remaining tokens of a m-function file or m-script file

Returns:
the parsed expresssion

getScannedLineOfCode

public java.lang.String getScannedLineOfCode()
return the currently scanned line of code to identify the possible errors. (e.g. a=sin(3]+4 is an eroror and returns a=sin(3] to display to the user

Returns:
the currently scanned line of code

getNextToken

public Token getNextToken()
get next token from the lexical analyser

Returns:
the next token

peekNextToken

public Token peekNextToken()
get next Token from lexical analyser, without moving forward

Returns:
the next token