Esempio n. 1
0
 public function testCommentSkipped()
 {
     $compiler = new PrologCompiler(new WAMService());
     $prog = $compiler->compileFile(FIXTURES_DIR . "basket.pro");
     $this->assertNotNull($prog);
     // @todo I can't further test the preprocessing because it is not decoupled from compiling : need to refactor
 }
 public function runAction()
 {
     $form = $this->createForm(new \Trismegiste\WamBundle\Form\PrologConsole());
     $request = $this->getRequest();
     $result = '';
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $machine = $this->get('prolog.wam');
             $compiler = new Prolog\PrologCompiler($machine);
             $prog = str_replace(array("\r", "\n"), '', $data['program']);
             $prog = $compiler->compile($prog);
             $machine->addProgram($prog);
             $result = $machine->runQuery($data['query']);
         }
     }
     return $this->render('TrismegisteWamBundle:PrologGui:run.html.twig', array('form' => $form->createView(), 'output' => $result));
 }
Esempio n. 3
0
 protected function consult($fileName)
 {
     $pc = new PrologCompiler($this);
     $prog = $pc->compileFile($fileName);
     if ($prog == null) {
         if (false === strpos($fileName, ".pro")) {
             // if compilation didn't work, try with different file extension
             $this->writeLn("Trying \"" . $fileName . ".prolog\" instead.");
             $prog = $pc->compileFile($fileName . ".prolog");
         }
     }
     if ($prog == null) {
         // program could not be compiled/loaded for whatever reason
         $this->backtrack();
     } else {
         if ($this->debugOn > 1) {
             // in case of debug mode, display the WAM code
             $this->writeLn($prog->__toString());
         }
         $this->p->owner = $this;
         $this->p->addProgram($prog);
         // add program to that already in memory
         $this->p->updateLabels();
         // and don't forget to update the jump labels
         $this->programCounter++;
     }
 }