aboutsummaryrefslogtreecommitdiff
path: root/parser.php
diff options
context:
space:
mode:
Diffstat (limited to 'parser.php')
-rw-r--r--parser.php58
1 files changed, 29 insertions, 29 deletions
diff --git a/parser.php b/parser.php
index 8a21bc3..4a37832 100644
--- a/parser.php
+++ b/parser.php
@@ -65,7 +65,7 @@ class qtype_algebra_parser_term {
* @param $text the text from the expression associated with the array
* @param $commutes if set to true then this term commutes (only for 2 argument terms)
*/
- function qtype_algebra_parser_term($nargs,$formats,$text='',$commutes=false) {
+ function __construct($nargs,$formats,$text='',$commutes=false) {
$this->_value=$text;
$this->_nargs=$nargs;
$this->_formats=$formats;
@@ -427,8 +427,8 @@ class qtype_algebra_parser_nullterm extends qtype_algebra_parser_term {
* Initializes a null term class. Since this class represents nothing no special
* initialization is required and no arguments are needed.
*/
- function qtype_algebra_parser_nullterm() {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats,'');
+ function __construct() {
+ parent::__construct(self::NARGS,self::$formats,'');
}
/**
@@ -480,7 +480,7 @@ class qtype_algebra_parser_number extends qtype_algebra_parser_term {
*
* @param $text string matching the number regular expression
*/
- function qtype_algebra_parser_number($text='') {
+ function __construct($text='') {
// Unfortunately PHP maths will only support a '.' as a decimal point and will not support
// ',' as used in Danish, French etc. To allow for this we always convert any commas into
// decimal points before we parse the string
@@ -492,11 +492,11 @@ class qtype_algebra_parser_number extends qtype_algebra_parser_term {
$this->_exp=$m[2];
$eformats=array('str' => '%sE%s',
'tex' => '%s \\times 10^{%s}');
- parent::qtype_algebra_parser_term(self::NARGS,$eformats,$text);
+ parent::__construct(self::NARGS,$eformats,$text);
} else {
$this->_base=$text;
$this->_exp='';
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats,$text);
+ parent::__construct(self::NARGS,self::$formats,$text);
}
}
@@ -628,7 +628,7 @@ class qtype_algebra_parser_variable extends qtype_algebra_parser_term {
*
* @param $text text matching the variable name
*/
- function qtype_algebra_parser_variable($text) {
+ function __construct($text) {
// Create the array to store the regular expression matches in
$m=array();
// Set the sign of the variable to be empty
@@ -645,7 +645,7 @@ class qtype_algebra_parser_variable extends qtype_algebra_parser_term {
}
// Call the base class constructor with the variable text set to the combination of the
// base name and the subscript without an underscore between them
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats['greek'],
+ parent::__construct(self::NARGS,self::$formats['greek'],
$this->_base.$this->_subscript);
}
// Otherwise we have a simple multi-letter variable name. Treat the fist letter as the base
@@ -661,7 +661,7 @@ class qtype_algebra_parser_variable extends qtype_algebra_parser_term {
}
// Call the base class constructor with the variable text set to the combination of the
// base name and the subscript without an underscore between them
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats['std'],
+ parent::__construct(self::NARGS,self::$formats['std'],
$this->_base.$this->_subscript);
}
}
@@ -761,8 +761,8 @@ class qtype_algebra_parser_power extends qtype_algebra_parser_term {
*
* @param $text string matching the term's regular expression
*/
- function qtype_algebra_parser_power($text) {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats,$text);
+ function __construct($text) {
+ parent::__construct(self::NARGS,self::$formats,$text);
}
/**
@@ -808,8 +808,8 @@ class qtype_algebra_parser_divide extends qtype_algebra_parser_term {
*
* @param $text string matching the term's regular expression
*/
- function qtype_algebra_parser_divide($text) {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats,$text);
+ function __construct($text) {
+ parent::__construct(self::NARGS,self::$formats,$text);
}
/**
@@ -863,14 +863,14 @@ class qtype_algebra_parser_multiply extends qtype_algebra_parser_term {
*
* @param $text string matching the term's regular expression
*/
- function qtype_algebra_parser_multiply($text) {
+ function __construct($text) {
$this->mformats=array('*' => array('str' => '%s*%s',
'tex' => '%s \\times %s'),
'.' => array('str' => '%s %s',
'tex' => '%s %s',
'sage'=> '%s*%s')
);
- parent::qtype_algebra_parser_term(self::NARGS,$this->mformats['*'],$text,true);
+ parent::__construct(self::NARGS,$this->mformats['*'],$text,true);
}
/**
@@ -956,8 +956,8 @@ class qtype_algebra_parser_add extends qtype_algebra_parser_term {
*
* @param $text string matching the term's regular expression
*/
- function qtype_algebra_parser_add($text) {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats,$text,true);
+ function __construct($text) {
+ parent::__construct(self::NARGS,self::$formats,$text,true);
}
/**
@@ -1003,8 +1003,8 @@ class qtype_algebra_parser_subtract extends qtype_algebra_parser_term {
*
* @param $text string matching the term's regular expression
*/
- function qtype_algebra_parser_subtract($text) {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats,$text);
+ function __construct($text) {
+ parent::__construct(self::NARGS,self::$formats,$text);
}
/**
@@ -1048,8 +1048,8 @@ class qtype_algebra_parser_special extends qtype_algebra_parser_term {
*
* @param $text string matching a constant's regular expression
*/
- function qtype_algebra_parser_special($text) {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats[$text],$text);
+ function __construct($text) {
+ parent::__construct(self::NARGS,self::$formats[$text],$text);
$this->_sign='';
}
@@ -1150,7 +1150,7 @@ class qtype_algebra_parser_function extends qtype_algebra_parser_term {
*
* @param $text string matching the function's regular expression
*/
- function qtype_algebra_parser_function($text) {
+ function __construct($text) {
if(!function_exists($text) and !array_key_exists($text,self::$fnmap)) {
throw new Exception(get_string('undefinedfunction','qtype_algebra',$text));
}
@@ -1161,7 +1161,7 @@ class qtype_algebra_parser_function extends qtype_algebra_parser_term {
$formats['tex']='%s\\'.$text.' %s';
}
$this->_sign='';
- parent::qtype_algebra_parser_term(self::NARGS,$formats,$text);
+ parent::__construct(self::NARGS,$formats,$text);
}
/**
@@ -1304,8 +1304,8 @@ class qtype_algebra_parser_function extends qtype_algebra_parser_term {
*/
class qtype_algebra_parser_bracket extends qtype_algebra_parser_term {
- function qtype_algebra_parser_bracket($text) {
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats[$text],$text);
+ function __construct($text) {
+ parent::__construct(self::NARGS,self::$formats[$text],$text);
$this->_open=$text;
switch($this->_open) {
case '(':
@@ -1362,7 +1362,7 @@ class qtype_algebra_parser_bracket extends qtype_algebra_parser_term {
$this->_open='<';
$this->_close='>';
// Call the base class constructor as if this were a new instance of the bracket
- parent::qtype_algebra_parser_term(self::NARGS,self::$formats['<'],'<');
+ parent::__construct(self::NARGS,self::$formats['<'],'<');
}
// Member variables
@@ -1441,7 +1441,7 @@ class qtype_algebra_parser {
* find tokens in the input string which are then fed to the corresponding term class for
* interpretation.
*/
- function qtype_algebra_parser() {
+ function __construct() {
$this->_tokens = array (
array ('/(\^|\*\*)/A', 'qtype_algebra_parser_power' ),
array ('/('.implode('|',self::$functions).')/A', 'qtype_algebra_parser_function' ),
@@ -1624,7 +1624,7 @@ class qtype_algebra_parser {
// First check to see if we are passed anything at all. If not then simply
// return a qtype_algebra_parser_nullterm
if(count($tree)==0) {
- return new qtype_algebra_parser_nullterm();
+ return new qtype_algebra_parser_nullterm;
}
// Now we check to see if this tree is inside brackets. If so then
// we remove the bracket object from the tree and store it in a
@@ -1711,7 +1711,7 @@ class qtype_algebra_parser {
// If there are no terms in the parse tree then we were passed an empty string
// in which case we create a null term and return it
if(count($tree)==0) {
- return new qtype_algebra_parser_nullterm();
+ return new qtype_algebra_parser_nullterm;
} else if(count($tree)!=1) {
//print_r($tree);
throw new Exception(get_string('notopterm','qtype_algebra'));