How to deal with compilation principles

Source: Internet
Author: User
I am interested in the compilation principles. at the end of this post, xuzuning was edited at 2012-08-2716: 40: 33. Recently, I tried to perform grammar analysis, which has many problems. Please provide suggestions. The code cannot be stored. There are two pages. & Nbsp; http://download.csdn is interested in the compilation principle
At the end of this post, xuzuning edited the grammar analysis stuff at 16:40:33 on. There are many problems.
Please provide suggestions. The code cannot be stored. There are two pages. Http://download.csdn.net/detail/xuzuning/4529066
Include 'ttrie. php ';

Class Rule extends TTrie {
Public $ rule = array ();
Public $ savematch = 0;

Function _ construct ($ s = ''){
$ This-> set (array (
''=> 'Paramted ',
"\ R \ n" => 'set _ rule ',
"\ N" => 'set _ rule ',
"\ T" => 'paramted ',
'->' => 'Paramted ',
'→' => 'Paramd ',
'|' => 'Set _ parallel_rule ',
));
$ This-> match ($ s );
If ($ this-> rule [0] [0] = $ this-> rule [0] [1]) {
If (count ($ this-> rule [0]) = 2) $ this-> rule [0] [0]. = "'";
Else array_unshift ($ this-> rule, array ($ this-> rule [0] [0]. "'", $ this-> rule [0] [0]);
} Else {
$ C = $ this-> rule [0] [0];
$ N = 0;
Foreach ($ this-> rule as $ r) if ($ r [0] = $ c) $ n ++;
If ($ n> 1) array_unshift ($ this-> rule, array ($ this-> rule [0] [0]. "'", $ this-> rule [0] [0]);
}
}
Function Separated (){
}
Function set_rule (){
$ This-> rule [] = $ this-> buffer;
$ This-> buffer = array ();
}
Function set_parallel_rule (){
$ T = $ this-> buffer [0];
$ This-> set_rule ();
$ This-> buffer [] = $ t;
}
}


Class Grammar {
Var $ closure = array ();
Var $ first = array ();
Var $ follow = array ();
Var $ rule = array ();
Var $ identifier = array ();
Var $ leay = array ();
Var $ forecast = array ();
Var $ stack = array ();
Var $ ll ='ll (0 )';
Var $ lr = 'LR (0 )';

Function _ construct ($ s = ''){
$ P = new Rule ($ s );
$ This-> rule = $ p-> rule;
$ This-> set_grammar ();
}

Function set_grammar (){
Foreach ($ this-> rule as $ rule ){
If (! In_array ($ rule [0], $ this-> identifier) $ this-> identifier [] = $ rule [0];
}
Foreach ($ this-> rule as $ rule ){
Foreach ($ rule as $ v)
If (! In_array ($ v, $ this-> identifier )&&! In_array ($ v, $ this-> leay ))
$ This-> leay [] = $ v;
}
$ This-> set_first ();
$ This-> set_follow ();
$ This-> set_closure ();
$ This-> set_select ();
$ This-> set_forecast ();
}
Function set_first (){
Foreach ($ this-> rule as $ rule) $ this-> first [$ rule [0] = array ();
// Directly collect data, such as U->... Generate (where a is the Terminator), and send a's revenue to First (U)
Foreach ($ this-> rule as $ v ){
If (in_array ($ v [1], $ this-> leay) $ this-> first [$ v [0] [] = $ v [1];
}
// Repeatedly transmitted to the U-> P1P2P3... In the production formula of Pn (where P is not a Terminator), the full content in First (P1) should be First transmitted to First (U). If P1 contains ε, the First (P2) the content in is transmitted to First (U), and so on until there is no ε in Pi.
Do {
$ T = serialize ($ this-> first );
Foreach ($ this-> rule as $ rule ){
For ($ I = 1; $ I

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.