public function compile() { $compiler = new Compiler(); $compiler->setReader(new File($this->getTemplatePath())); $compiler->setWriter(new File($this->getScriptPath())); $compiler->compile(); }
public static function validateCode($sourceCode, $language, $testCases) { $inputTestCases = self::bindTestCases($testCases, true); $outputTestCases = self::bindTestCases($testCases, false); $compilerInstance = new Compiler($sourceCode, $language, $inputTestCases, $outputTestCases); $compilerInstance->compile(); return $compilerInstance; }
public function translate($query) { $lexer = new Lexer(); $parser = new Parser(); $compiler = new Compiler($this->schema); $tokens = $lexer->tokenize($query); $request = $parser->parse($tokens); return $compiler->compile($request); }
public function render($input, $scope = null, $includes = array()) { if ($scope !== null && is_array($scope)) { extract($scope); } $parser = new Parser($input, array('includes' => $includes)); $compiler = new Compiler($this->prettyprint); return $compiler->compile($parser->parse($input)); }
/** * Returns a callback that binds the data with the template * * @param string $source The template string * @return callable The template binding handler */ public function compile(string $source) : callable { $name = $this->namePrefix . md5(self::VERSION . $source); if (isset($this->compiledTemplates[$name])) { goto returner; } elseif (class_exists($name) === true) { goto instantiator; } if ($this->loadCache($name . '.php') === false) { $code = $this->compiler->compile($source); $formattedCode = sprintf(self::$layout, $name, $code); $this->saveCache($name . '.php', $formattedCode); eval('?>' . $formattedCode); } instantiator: $this->compiledTemplates[$name] = new $name($this->runtime, $this->dataFactory); returner: return $this->compiledTemplates[$name]; }
public function test_it_compiles_finished_statement() { $str = <<<EOL @finished echo 'shutdown'; @endfinished EOL; $compiler = new Compiler(); $result = $compiler->compile($str); $this->assertEquals(1, preg_match('/\\$__container->finished\\(.*?\\}\\);/s', $result, $matches)); }
function __compile($context, $source, $name) { $sourceStr = __toString($source); /* Compiler initialisieren */ static $compiler; if ($compiler == null) { include_once "compiler.php"; $compiler = new Compiler(); } /* Modul Kompilieren */ $code = $compiler->compile($sourceStr); if (isset($code['Module'])) { /* Libarymodule bearbeiten */ $dir = BIN_DIR . preg_replace("/\\W/", "_", $code['Module']); $name = $dir . ".php"; if (is_dir($dir)) { foreach (__ls_r($dir . "/") as $file) { if (is_dir($file)) { rmdir($file); } else { unlink($file); } } } /* Ordner neu anlegen */ mkdir($dir); chmod($dir, 0777); /* Funktionen niederschreiben */ foreach ($code['Functions'] as $fnName => $body) { $fp = fopen($dir . "/" . $fnName . ".php", 'w'); fwrite($fp, $body); fclose($fp); chmod($dir . "/" . $fnName . ".php", 0777); } /* Name von Mainmodulen anpassen */ } else { $name = BIN_DIR . preg_replace("/\\W/", "_", substr($name, strrpos($name, "/") + 1)) . ".php"; } /* Hauptteil niederschreiben */ if (($fp = @fopen($name, 'w')) == false) { PEAR::raiseError("Die Datei '" . $name . "' kann nicht geöffnet werden!"); } fwrite($fp, $code['Main']); fclose($fp); chmod($name, 0777); /* Leere Sequenz zurückgeben */ return array(); }
<span class='label label-info'><?php echo $Cp->state['name']; ?> <?php echo $Cp->state['ver']; ?> </span> <?php echo $Cp->state['memo']; ?> </div> <div class='alert alert-success'> 正在编译... <?php flush(); $csucc = $Cp->compile(); flush(); if ($csucc) { ?> 开始运行 <table class='table table-condensed'> <tr> <th>点</th> <th>结果</th> <th>得分</th> <th>运行时间</th> <th>内存使用</th> <th>返回</th> </tr> <tr> <?php
function lxEditRejection() { global $DB, $C; VerifyAdministrator(); $validator = new Validator(); $validator->Register($_REQUEST['identifier'], V_EMPTY, 'The Identifier field must be filled in'); $validator->Register($_REQUEST['subject'], V_EMPTY, 'The Subject field must be filled in'); if (!$validator->Validate()) { $GLOBALS['errstr'] = join('<br />', $validator->GetErrors()); lxEditRejection(); return; } $_REQUEST['plain'] = trim($_REQUEST['plain']); $_REQUEST['html'] = trim($_REQUEST['html']); $ini_data = IniWrite(null, $_REQUEST, array('subject', 'plain', 'html')); $compiled_code = ''; $compiler = new Compiler(); if ($compiler->compile($ini_data, $compiled_code)) { $DB->Update('UPDATE lx_rejections SET ' . 'identifier=?, ' . 'plain=?, ' . 'compiled=? ' . 'WHERE email_id=?', array($_REQUEST['identifier'], $ini_data, $compiled_code, $_REQUEST['email_id'])); $GLOBALS['message'] = 'Rejection e-mail has been successfully updated'; $GLOBALS['added'] = true; } else { $GLOBALS['errstr'] = "Rejection e-mail could not be saved:<br />" . nl2br($compiler->get_error_string()); } lxShEditRejection(); }
private function logic($formula, $variables) { //dd($variables); $compiler = new Compiler(); //dd($formula); try { $executable = $compiler->compile($formula); $result = $executable->run($variables); } catch (ParserException $e) { throw new GeneralException('Logical check formula error!'); } return $result; }
function path($file, $sys = null) { if (!$sys && file_exists($this->dir . $file . '.html')) { $path = $this->dir; $cache = $this->cache; } elseif (file_exists(SKIN_DIR . $file . '.html')) { $path = SKIN_DIR; $cache = VIEW_DIR; } elseif (file_exists('style/system/' . $file . '.html')) { $path = './style/system/'; $cache = './cache/system/'; } else { exit('Cannot find template: ' . $file . '.html'); } #Check modification date if ($this->check && filemtime($path . $file . '.html') > @filemtime($cache . $file . '.html')) { static $compiler; if (!isset($compiler)) { include_once './lib/compiler.php'; $compiler = new Compiler(); } try { $compiler->compile($file, $path, $cache); } catch (Exception $e) { exit($e->getMessage()); } } return $cache . $file . '.html'; }
} $output = ''; foreach (token_get_all($source) as $token) { if (is_string($token)) { $output .= $token; } elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) { $output .= str_repeat("\n", substr_count($token[1], "\n")); } elseif (T_WHITESPACE === $token[0]) { // reduce wide spaces $whitespace = preg_replace('{[ \\t]+}', ' ', $token[1]); // normalize newlines to \n $whitespace = preg_replace('{(?:\\r\\n|\\r|\\n)}', "\n", $whitespace); // trim leading spaces $whitespace = preg_replace('{\\n +}', "\n", $whitespace); $output .= $whitespace; } else { $output .= $token[1]; } } return $output; } private function getStub() { $entryPath = $this->getPath($this->entryPoint); return "#!/usr/bin/env php\n<?php\n\nPhar::mapPhar('{$this->pharName}');\n\nrequire 'phar://{$this->pharName}/{$entryPath}';\n\n__HALT_COMPILER();"; } } $root = __DIR__ . '/../'; $compile = new Compiler($root . 'bin/sync', array($root . 'bin', $root . 'src', $root . 'vendor')); $compile->compile('db-sync.phar'); chmod(__DIR__ . '/db-sync.phar', 0777);
<?php declare (strict_types=1); namespace ajf\pico8bot; require_once __DIR__ . "/vendor/autoload.php"; if ($argc < 3) { die("gib 2 arguments pl0x\n"); } $expr = $argv[1]; $out = $argv[2]; $tokeniser = new Tokeniser(); $tokens = $tokeniser->tokenise($expr); $parser = new Parser(); $ast = $parser->parse($tokens); $compiler = new Compiler(); $closure = $compiler->compile($ast); $renderer = new Renderer($closure); $image = $renderer->renderFrame(0, 320, 320); \imageGIF($image, $out);
public function load($template, $from = '') { if ($template instanceof Template) { return $template; } if (!is_string($template)) { throw new \InvalidArgumentException('string expected'); } $source = $this->options['source']; $adapter = $this->options['adapter']; if (isset($this->paths[$template . $from])) { $path = $this->paths[$template . $from]; } else { $path = $this->resolvePath($template, $from); $this->paths[$template . $from] = $path; } $class = self::CLASS_PREFIX . md5($path); if (isset($this->cache[$class])) { return $this->cache[$class]; } if (!class_exists($class, false)) { if (!$adapter->isReadable($path)) { throw new \RuntimeException(sprintf('%s is not a valid readable template', $template)); } $target = $this->options['target'] . '/' . $class . '.php'; switch ($this->options['mode']) { case self::RECOMPILE_ALWAYS: $compile = true; break; case self::RECOMPILE_NEVER: $compile = !file_exists($target); break; case self::RECOMPILE_NORMAL: default: $compile = !file_exists($target) || filemtime($target) < $adapter->lastModified($path); break; } if ($compile) { try { $lexer = new Lexer($adapter->getContents($path)); $parser = new Parser($lexer->tokenize()); $compiler = new Compiler($parser->parse()); $compiler->compile($path, $target); } catch (SyntaxError $e) { throw $e->setMessage($path . ': ' . $e->getMessage()); } } require_once $target; } $this->cache[$class] = new $class($this, $this->options['helpers']); return $this->cache[$class]; }
* * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @category Swagger * @package Swagger */ require dirname(__DIR__) . '/vendor/autoload.php'; use Symfony\Component\Finder\Finder; $compiler = new Compiler(); $compiler->compile(); chmod('swagger.phar', 0777); /** * Shamelessly copied and modified from the Composer project, * because it works well * - git://github.com/composer/composer.git * - https://github.com/composer/composer * - http://getcomposer.org */ class Compiler { protected $version; /** * Compiles composer into a single phar file * * @throws \RuntimeException
function txScriptTemplateSave() { global $DB, $C; VerifyAdministrator(); CheckAccessList(); $_REQUEST['code'] = trim($_REQUEST['code']); // Compile global templates first, if this is not one if (!preg_match('~global-~', $_REQUEST['loaded_template'])) { $t = new Template(); foreach (glob("{$GLOBALS['BASE_DIR']}/templates/*global-*.tpl") as $global_template) { $t->compile_template(basename($global_template)); } } $compiled_code = ''; $compiler = new Compiler(); if ($compiler->compile($_REQUEST['code'], $compiled_code)) { $template_file = SafeFilename("{$GLOBALS['BASE_DIR']}/templates/{$_REQUEST['loaded_template']}"); FileWrite($template_file, $_REQUEST['code']); $compiled_file = SafeFilename("{$GLOBALS['BASE_DIR']}/templates/compiled/{$_REQUEST['loaded_template']}", FALSE); FileWrite($compiled_file, $compiled_code); $GLOBALS['message'] = 'Template has been successully saved'; } else { $GLOBALS['errstr'] = "Template could not be saved:<br />" . nl2br($compiler->get_error_string()); } $GLOBALS['warnstr'] = CheckTemplateCode($_REQUEST['code']); // Recompile all templates if a global template was updated if (preg_match('~global-~', $_REQUEST['loaded_template'])) { RecompileTemplates(); } txShScriptTemplates(); }
{ echo "gcc (Debian 4.9.2-10) 4.9.2 -- fictitious compiler\n"; } public function compile($input, $output) { // creating scanner from InputStream $scanner = new Scanner($input); // creating builder for abstract syntax tree $builder = new ProgramNodeBuilder(); // creating Parser $parser = new Parser(); // parsing using scanner and builder, hence creating AST $parser->parse($scanner, $builder); // creating target code generator $generator = new RISCCodeGenerator($output); // retrieving abstract syntax tree from builder $parseTree = $builder->getRootNode(); // generating target code from AST and generator $parseTree->traverse($generator); echo "compilation complete"; // newline introduced without '\n'... why? } } // main $input = new InputStream("source.c"); $output = new BytecodeStream(); $compiler = new Compiler(); $compiler->compile($input, $output); ?>
/** * @param $input * @return string */ public function compile($input) { $parser = new Parser($input, null, $this->options['extension']); $compiler = new Compiler($this->options['prettyprint'], $this->options['phpSingleLine'], $this->options['allowMixinOverride'], $this->filters); return $compiler->compile($parser->parse($input)); }
/** * Constructor * * If no parameters are specified, database-parameters like username/passwd are read from the default configfile config.xml * The connection should be explicitly set up by calling the connect-method after the DB-object is constructed. * If you specify a $pdoHandle, this method should not be called. * * @param {PDO} $pdoHandle (optional) Use this if you already have a PDO database connection. * @param {string} $configFile (optional) Use this to specify your custom XML-configfile * @param {Profiler|boolean} $profiler (optional) If 'true' then a Profiler object is created and run is called; if 'false' the object is also created but not initialized * @param {boolean} $neverAutoCompile (optional) This can be used to overrule the setting in the config file */ public function __construct($pdoHandle = null, $configFile = null, $profiler = null, $neverAutoCompile = false) { // Initialize profiler object if (is_object($profiler)) { $this->profiler =& $profiler; } else { $this->profiler = new Profiler($profiler ? true : false); } $config = new Config($configFile); // Import settings $this->driver = $config->database->driver; $this->host = $config->database->host ? $config->database->host : 'localhost'; $this->port = $config->database->port; $this->dbname = $config->database->name; $this->user = $config->database->user; $this->pw = $config->database->password; $this->initQuery = $config->database->initQuery; $this->nested = $config->postprocessor->nest_fields; // Call the compiler if autocompile is set if (!$neverAutoCompile && $config->compiler->autocompile) { $compiler = new Compiler($configFile); $compiler->compile(false, true); } $this->queries = new QuerySet($config->compiler->output); $this->globals = array(); $this->primaryKey = 'id'; if ($pdoHandle) { $this->dbh = $pdoHandle; } }
function parse($template) { if (!class_exists('compiler')) { require_once dirname(__FILE__) . '/' . $this->compiler_file; } $compiled_code = ''; $compiler = new Compiler(); $compiler->compile($template, $compiled_code); ob_start(); eval('?>' . $compiled_code); $contents = ob_get_contents(); ob_end_clean(); return $contents; }
function tlxRejectionTemplateEdit() { global $DB, $C; VerifyAdministrator(); $v = new Validator(); $v->Register($_REQUEST['identifier'], V_EMPTY, 'The Identifier field must be filled in'); $v->Register($_REQUEST['subject'], V_EMPTY, 'The Subject field must be filled in'); if (!$v->Validate()) { return $v->ValidationError('tlxShRejectionTemplateEdit'); } $_REQUEST['plain'] = trim($_REQUEST['plain']); $_REQUEST['html'] = trim($_REQUEST['html']); $ini_data = IniWrite(null, $_REQUEST, array('subject', 'plain', 'html')); $compiled_code = ''; $compiler = new Compiler(); if ($compiler->compile($ini_data, $compiled_code)) { $DB->Update('UPDATE `tlx_rejections` SET ' . '`identifier`=?, ' . '`plain`=?, ' . '`compiled`=? ' . 'WHERE `email_id`=?', array($_REQUEST['identifier'], $ini_data, $compiled_code, $_REQUEST['email_id'])); $GLOBALS['message'] = 'Rejection e-mail has been successfully updated'; $GLOBALS['added'] = true; } else { $GLOBALS['errstr'] = "Rejection e-mail could not be saved:<br />" . nl2br($compiler->get_error_string()); } tlxShRejectionTemplateEdit(); }