CogPar
A versatile parser for mathematical expressions.
 All Classes Functions Variables
Public Member Functions | Private Member Functions | List of all members
uk.co.cogitolearning.cogpar.Parser Class Reference

A parser for mathematical expressions. More...

Collaboration diagram for uk.co.cogitolearning.cogpar.Parser:
Collaboration graph
[legend]

Public Member Functions

ExpressionNode parse (String expression)
 Parse a mathematical expression in a string and return an ExpressionNode.
ExpressionNode parse (LinkedList< Token > tokens)
 Parse a mathematical expression in contained in a list of tokens and return an ExpressionNode.

Private Member Functions

ExpressionNode expression ()
 handles the non-terminal expression
ExpressionNode sumOp (ExpressionNode expr)
 handles the non-terminal sum_op
ExpressionNode signedTerm ()
 handles the non-terminal signed_term
ExpressionNode term ()
 handles the non-terminal term
ExpressionNode termOp (ExpressionNode expression)
 handles the non-terminal term_op
ExpressionNode factor ()
 handles the non-terminal factor
ExpressionNode factorOp (ExpressionNode expr)
 handles the non-terminal factor_op
ExpressionNode argument ()
 handles the non-terminal argument
ExpressionNode value ()
 handles the non-terminal value
void nextToken ()
 Remove the first token from the list and store the next token in lookahead.

Detailed Description

A parser for mathematical expressions.

The parser class defines a method parse() which takes a string and returns an ExpressionNode that holds a representation of the expression.

Parsing is implemented in the form of a recursive descent parser.

Definition at line 64 of file Parser.java.

Member Function Documentation

ExpressionNode uk.co.cogitolearning.cogpar.Parser.parse ( String  expression)

Parse a mathematical expression in a string and return an ExpressionNode.

This is a convenience method that first converts the string into a linked list of tokens using the expression tokenizer provided by the Tokenizer class.

Parameters
expressionthe string holding the input
Returns
the internal representation of the expression in form of an expression tree made out of ExpressionNode objects

Definition at line 83 of file Parser.java.

ExpressionNode uk.co.cogitolearning.cogpar.Parser.parse ( LinkedList< Token tokens)

Parse a mathematical expression in contained in a list of tokens and return an ExpressionNode.

Parameters
tokensa list of tokens holding the tokenized input
Returns
the internal representation of the expression in form of an expression tree made out of ExpressionNode objects

Definition at line 100 of file Parser.java.


The documentation for this class was generated from the following file: