PHP Classes

File: Symbol.class.php

Recommend this page to a friend!
  Classes of Alejandro Siri   PHPCC   Symbol.class.php   Download  
File: Symbol.class.php
Role: Class source
Content type: text/plain
Description: Symbol
Class: PHPCC
Parse language string according to a given grammar
Author: By
Last change: Adding left-recursive support
Date: 17 years ago
Size: 857 bytes
 

Contents

Class file image Download
<?php

class EregSymbol extends Parser {
    function
EregSymbol($sym) {
       
parent :: Parser();
       
$bars = explode('/',$sym);
       
$mods = array_pop($bars);
       
array_shift($bars);
       
$spaces = '[\s\t\n]*';
       
$this->preg = '/^'.$spaces.'('.implode('/',$bars).')'.$spaces.'/'.$mods;
       
$this->sym = $sym;
    }
    function
parse($tks) {
       
$spaces = '[\s\t\n]*';
        if (
preg_match($this->preg, $tks->str, $matches)) {
            return array (
ParseResult::match($matches[1]),new ParseInput(substr($tks->str,strlen($matches[0]))));
        } else {
           
$this->setError(array((string)strlen(preg_replace('/^'.$spaces.'/','',$tks->str))=>$this->sym));
            return array (
ParseResult::fail(),$tks);
        }
    }
    function
print_tree() {
        return
$this->sym;
    }
}

class
Symbol extends EregSymbol {
    function
Symbol($ss) {
       
parent :: EregSymbol('/'.preg_quote($ss).'/');
       
$this->sym='"'.$ss.'"';
    }
}
?>