source of /processor/c_parser.php
Contains the CParser class <?php /* Copyright 2008 Josh Heidenreich This file is part of Pelzini. Pelzini is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Pelzini is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Pelzini. If not, see <http://www.gnu.org/licenses/>. */ /** * Contains the {@link CParser} class * * @package Parsers * @author Josh * @since 0.2 **/ /** * Does the complete parsing of a C file. **/ class CParser { private $lexer; private $analyser; public function __construct() { $this->lexer = new CLexer(); $this->analyser = new CAnalyser(); } /** * Parses a file * * @param string $filename The file to parse * @return A ParserFile object, or null if there was an error **/ public function parseFile($base_dir, $filename) { $this->lexer->resetState(); if ($source == null) return null; $tokens = $this->lexer->process($source); if ($tokens === null) return null; //echo "<style>i {color: #777;}</style>"; //echo '<pre>Tokens for file ', $filename, "\n"; //foreach ($tokens as $i => $t) echo "<b>{$i}</b> {$t->getTypeName()} <i>{$t->getValue()}</i>\n"; //echo '</pre>'; $file = new ParserFile(); $file->name = $filename; $file->source = $source; $result = $this->analyser->process($tokens, $file); if ($result === false) return null; return $file; } } ?>
|