[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/lib/excel/ -> Parser.php (summary)

Class for parsing Excel formulas License Information:

File Size: 996 lines (37 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Parser:: (19 methods):
  Parser()
  _initialize_hashes()
  _convert()
  _convert_number()
  _convert_function()
  _convert_range2d()
  _convert_ref2d()
  _cell_to_packed_rowcol()
  _cell_to_rowcol()
  _advance()
  _match()
  parse()
  _expression()
  _parenthesized_expression()
  _term()
  _fact()
  _func()
  _create_tree()
  to_reverse_polish()


Class: Parser  - X-Ref

Class for parsing Excel formulas

Parser($byte_order = 0)   X-Ref
The class constructor

param: integer $byte_order The byte order (Little endian or Big endian) of the architecture

_initialize_hashes()   X-Ref
Initialize the ptg and function hashes.


_convert($token)   X-Ref
Convert a token to the proper ptg value.

param: mixed $token The token to convert.

_convert_number($num)   X-Ref
Convert a number token to ptgInt or ptgNum

param: mixed $num an integer or double for conersion to its ptg value

_convert_function($token, $num_args)   X-Ref
Convert a function to a ptgFunc or ptgFuncVarV depending on the number of
args that it takes.

param: string  $token    The name of the function for convertion to ptg value.
param: integer $num_args The number of arguments the function recieves.

_convert_range2d($range)   X-Ref
Convert an Excel range such as A1:D4 to a ptgRefV.

param: string $range An Excel range in the A1:A2 or A1..A2 format.

_convert_ref2d($cell)   X-Ref
Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.

param: string $cell An Excel cell reference

_cell_to_packed_rowcol($cell)   X-Ref
pack() row and column into the required 3 byte format.

param: string $cell The Excel cell reference to be packed

_cell_to_rowcol($cell)   X-Ref
Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero
indexed row and column number. Also returns two boolean values to indicate
whether the row or column are relative references.

param: string $cell The Excel cell reference in A1 format.

_advance()   X-Ref
Advance to the next valid token.


_match($token)   X-Ref
Checks if it's a valid token.

param: mixed $token The token to check.

parse($formula)   X-Ref
The parsing method. It parses a formula.

param: string $formula The formula to parse, without the initial equal sign (=).

_expression()   X-Ref
It parses a expression. It assumes the following rule:
Expr -> Term [("+" | "-") Term]

return: mixed The parsed ptg'd tree

_parenthesized_expression()   X-Ref
This function just introduces a ptgParen element in the tree, so that Excel
doesn't get confused when working with a parenthesized formula afterwards.

return: mixed The parsed ptg'd tree

_term()   X-Ref
It parses a term. It assumes the following rule:
Term -> Fact [("*" | "/") Fact]

return: mixed The parsed ptg'd tree

_fact()   X-Ref
It parses a factor. It assumes the following rule:
Fact -> ( Expr )
| CellRef
| CellRange
| Number
| Function

return: mixed The parsed ptg'd tree

_func()   X-Ref
It parses a function call. It assumes the following rule:
Func -> ( Expr [,Expr]* )


_create_tree($value, $left, $right)   X-Ref
Creates a tree. In fact an array which may have one or two arrays (sub-trees)
as elements.

param: mixed $value The value of this node.
param: mixed $left  The left array (sub-tree) or a final node.
param: mixed $right The right array (sub-tree) or a final node.

to_reverse_polish($tree = array()   X-Ref
Builds a string containing the tree in reverse polish notation (What you
would use in a HP calculator stack).
The following tree:

+
/ \
2   3

produces: "23+"

The following tree:

+
/ \
3   *
/ \
6   A1

produces: "36A1*+"

In fact all operands, functions, references, etc... are written as ptg's

param: array $tree The optional tree to convert.



Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7