PHP Classes
Icontem

File: example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Debug  >  LR Parsing Tables  >  example.php  
File: example.php
Role: Example script
Content type: text/plain
Description: Example code
Class: LR Parsing Tables
Generate parsing tables for context free grammars
 

Contents

Class file image Download
<?php

// This is our example script.

include("lr_parsing_tables.class.php"); // include class
$productions = array(
    array(
"expression", array("expression""T_PLUS""expression")),
    array(
"expression", array("expression""T_MINUS""expression")),
    array(
"expression", array("T_START_PAREN""expression""T_END_PAREN")),
    array(
"expression", array("T_INT")),
    array(
"expression", array("T_IDENT"))
); 
// these are our productions
// The grammar is:
// E -> E + E
// E -> E - E
// E -> ( E )
// E -> int
// E -> ident

// Of course, it's a bit twisted. Our nonterminals are lowercase (defined by
// if strtolower($name) == $name). Terminals are uppercase otherwise.

$LR_Parsing_Tables = new LR_Parsing_Tables($productions"expression"); // provide productions. expression is our "start" NT.
$tables $LR_Parsing_Tables->build(); // build the tables.
$LR_Parsing_Tables->print_tables($tables); // print them
$LR_Parsing_Tables->print_productions(); // print our productions

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products