File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ namespace  igorw \lambda ;
4+ 
5+ use  Symfony \Component \Debug \ErrorHandler ;
6+ 
7+ require  'vendor/autoload.php ' ;
8+ 
9+ function  prompt ($ mode ) {
10+     echo  "$ mode>  " ;
11+ 
12+     return  true ;
13+ }
14+ 
15+ function  format ($ result ) {
16+     if  (is_bool ($ result )) {
17+         return  json_encode ($ result );
18+     }
19+ 
20+     return  $ result ;
21+ }
22+ 
23+ $ mode  = 'i ' ;
24+ 
25+ while  (prompt ($ mode ) && false  !== ($ line  = fgets (STDIN ))) {
26+     $ exp  = trim ($ line );
27+ 
28+     if  (in_array ($ exp , ['i ' , 'b ' ], true )) {
29+         $ mode  = $ exp ;
30+         continue ;
31+     }
32+ 
33+     $ factories  = [
34+         'i '  => 'igorw\lambda\to_int ' ,
35+         'b '  => 'igorw\lambda\to_bool ' ,
36+     ];
37+ 
38+     try  {
39+         $ factory  = $ factories [$ mode ];
40+         echo  format (evaluate ($ factory (parse ($ exp ))))."\n" ;
41+     } catch  (\Exception   $ e ) {
42+         echo  $ e ->getMessage ()."\n" ;
43+     }
44+ }
45+ 
46+ echo  "\n" ;
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments