Exemplo n.º 1
0
        public bool Sum()    /*Sum
                              * {  //semantic rule related block using C# as host language
                              * double v;
                              * bool save_()  {v=  result;result=0; return true;}
                              * bool add_()   {v+= result;result=0;return true;}
                              * bool sub_()   {v-= result;result=0;return true;}
                              * bool store_() {result= v; return true;}
                              * }	:
                              * Product save_
                              * ('+' S Product add_
                              * /'-' S Product sub_)* store_		;*/
        {
            var _sem = new _Sum(this);

            var result = And(() =>
                             Product() &&
                             _sem.save_() &&
                             OptRepeat(() =>

                                       And(() =>
                                           Char('+') &&
                                           S() &&
                                           Product() &&
                                           _sem.add_()) ||
                                       And(() =>
                                           Char('-') &&
                                           S() &&
                                           Product() &&
                                           _sem.sub_())) &&
                             _sem.store_()); return(result);
        }
Exemplo n.º 2
0
        public bool Sum()    /*Sum
                              * {  //semantic rule related block using C# as host language (block can be implemented as nested struct)
                              * internal _Sum(calc0_direct parent){parent_=parent;}
                              * calc0_direct parent_;
                              * double v;
                              * internal bool save_(){v= parent_.top.result;parent_.top.result=0; return true;}
                              * internal bool add_() {v+= parent_.top.result;parent_.top.result=0;return true;}
                              * internal bool sub_() {v-= parent_.top.result;parent_.top.result=0;return true;}
                              * internal bool store_(){parent_.top.result= v; return true;}
                              * }	:
                              * Product save_
                              * ('+' S Product add_
                              * /'-' S Product sub_)* store_		;*/
        {
            var _sem = new _Sum(this);

            return(And(() =>
                       Product() &&
                       _sem.save_() &&
                       OptRepeat(() =>

                                 And(() =>
                                     Char('+') &&
                                     S() &&
                                     Product() &&
                                     _sem.add_()) ||
                                 And(() =>
                                     Char('-') &&
                                     S() &&
                                     Product() &&
                                     _sem.sub_())) &&
                       _sem.store_()));
        }
Exemplo n.º 3
0
        public bool Sum()    /*Sum
{  //semantic rule related block using C# as host language (block can be implemented as nested struct)
        internal _Sum(calc0_direct parent){parent_=parent;}
        calc0_direct parent_;
	double v;
  	internal bool save_(){v= parent_.top.result;parent_.top.result=0; return true;}
	internal bool add_() {v+= parent_.top.result;parent_.top.result=0;return true;}
	internal bool sub_() {v-= parent_.top.result;parent_.top.result=0;return true;} 
  	internal bool store_(){parent_.top.result= v; return true;}
}	:     
	Product save_
                ('+' S Product add_
		/'-' S Product sub_)* store_		;*/
        {

             var _sem= new _Sum(this);

           return And(()=>  
                     Product()
                  && _sem.save_()
                  && OptRepeat(()=>    
                            
                               And(()=>        
                                       Char('+')
                                    && S()
                                    && Product()
                                    && _sem.add_() )
                            || And(()=>        
                                       Char('-')
                                    && S()
                                    && Product()
                                    && _sem.sub_() ) )
                  && _sem.store_() );
		}
Exemplo n.º 4
0
        /*Sum
        {  //semantic rule related block using C# as host language
        double v;
          	bool save_()  {v=  result;result=0; return true;}
        bool add_()   {v+= result;result=0;return true;}
        bool sub_()   {v-= result;result=0;return true;}
          	bool store_() {result= v; return true;}
        }	:
        Product save_
                ('+' S Product add_
        /'-' S Product sub_)* store_		;*/
        public bool Sum()
        {
            var _sem= new _Sum(this);

               return And(()=>
                     Product()
                  && _sem.save_()
                  && OptRepeat(()=>

                               And(()=>
                                       Char('+')
                                    && S()
                                    && Product()
                                    && _sem.add_() )
                            || And(()=>
                                       Char('-')
                                    && S()
                                    && Product()
                                    && _sem.sub_() ) )
                  && _sem.store_() );
        }
Exemplo n.º 5
0
        public bool Sum()    /*Sum
{  //semantic rule related block using C# as host language 
   double v;
   bool save_()  {v=  result;result=0; return true;}
   bool add_()   {v+= result;result=0;return true;}
   bool sub_()   {v-= result;result=0;return true;} 
   bool store_() {result= v; return true;}
}	:     
	Product save_
                ('+' S Product add_
		/'-' S Product sub_)* store_		;*/
        {

             var _sem= new _Sum(this);

           return And(()=>  
                     Product()
                  && _sem.save_()
                  && OptRepeat(()=>    
                            
                               And(()=>        
                                       Char('+')
                                    && S()
                                    && Product()
                                    && _sem.add_() )
                            || And(()=>        
                                       Char('-')
                                    && S()
                                    && Product()
                                    && _sem.sub_() ) )
                  && _sem.store_() );
		}