Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 4.55 KB | None | 0 0
  1. import std.stdio;
  2.  
  3. void main()
  4. {
  5.     import std.string : toLower, strip, indexOf;
  6.  
  7.     import SSTlexer;
  8.     // reads the file
  9.     auto sst_lexer = SSTLexer("PAY9.CBL");
  10.  
  11.     import divisionSST;
  12.     // breaks sentences up into the apropriete divisions
  13.     auto division_sst = DivisionSST(sst_lexer);
  14.  
  15.     import astContext;
  16.     import sectionSST;
  17.     // initiate the context for the entire program
  18.     ASTContext ast_context;
  19.  
  20.     // TODO: create the step after nexts output range
  21.     // even if the ast_context isn't already assigned to, we have the reference to it
  22.  
  23.     // now for each appropriate division do handle the sections sentences
  24.     // assigns the context to ast_context (before it's used)
  25.     division_sst.map(ast_context,
  26.         DivisionHandler("identification", (SectionSST sections, ref ASTContext context) {
  27.             // context
  28.  
  29.             ubyte lastOne;
  30.  
  31.             foreach(section; sections) {
  32.                 foreach(sentence; section) {
  33.                     if (lastOne == 0) {
  34.                         string lowered = sentence.toLower[0 .. $-1];
  35.  
  36.                         if (lowered == "program-id") {
  37.                             lastOne = 1;
  38.                         } else if (lowered == "author") {
  39.                             lastOne = 2;
  40.                         } else if (lowered == "installation") {
  41.                             lastOne = 3;
  42.                         } else if (lowered == "date-written") {
  43.                             lastOne = 4;
  44.                         } else if (lowered == "date-compiled") {
  45.                             lastOne = 5;
  46.                         } else if (lowered == "security") {
  47.                             lastOne = 6;
  48.                         } else {} // do nothing
  49.                     } else {
  50.                         switch(lastOne) {
  51.                             case 1:
  52.                                 context.id = sentence[0 .. $-1].strip;
  53.                                 break;
  54.                             case 2:
  55.                                 context.author = sentence[0 .. $-1].strip;
  56.                                 break;
  57.                             case 3:
  58.                                 context.installation = sentence[0 .. $-1].strip;
  59.                                 break;
  60.                             case 4:
  61.                                 context.date_written = sentence[0 .. $-1].strip;
  62.                                 break;
  63.                             case 5:
  64.                                 context.date_compiled = sentence[0 .. $-1].strip;
  65.                                 break;
  66.                             case 6:
  67.                                 context.security = sentence[0 .. $-1].strip;
  68.                                 break;
  69.                             default:
  70.                                 break;
  71.                         }
  72.  
  73.                         lastOne = 0;
  74.                     }
  75.                 }
  76.             }
  77.         }),
  78.         DivisionHandler("environment", (SectionSST sections, ref ASTContext context) {
  79.             foreach(section; sections) {
  80.                 if (section.sectionName.toLower == "configuration") {
  81.  
  82.                     // context
  83.                    
  84.                     ubyte lastOne;
  85.  
  86.                     foreach(sentence; section) {
  87.                         bool getOne() {
  88.                             string lowered = sentence.toLower[0 .. $-1];
  89.                            
  90.                             if (lowered == "source-computer") {
  91.                                 lastOne = 1;
  92.                             } else if (lowered == "object-computer") {
  93.                                 lastOne = 2;
  94.                             } else if (lowered == "special-names") {
  95.                                 lastOne = 3;
  96.                             } else {
  97.                                 return false;
  98.                             }
  99.  
  100.                             return true;
  101.                         }
  102.  
  103.                         void handle() {
  104.                             import std.algorithm : count;
  105.  
  106.                             switch(lastOne) {
  107.                                 case 1:
  108.                                     context.source_computer = setence[0 .. $-1].strip;
  109.                                     break;
  110.                                 case 2:
  111.                                     context.object_computer = setence[0 .. $-1].strip;
  112.                                     break;
  113.                                 case 3:
  114.                                     if (getOne()) {
  115.                                         handle();
  116.                                     } else {
  117.                                         if (sentence.count(' ') == 2) {
  118.                                             auto iloc = sentence.indexOf(' ');
  119.                                            
  120.                                             auto first = sentence[0 .. iloc];
  121.                                             auto second = sentence[iloc + 1 .. $];
  122.                                            
  123.                                             assert(second[0 .. 2].toLower == "is"); // TODO: really?
  124.                                            
  125.                                             second = second[second.indexOf(' ') + 1 .. $-1];
  126.  
  127.                                             context.specialNames = ASTSpecialName(second, first);
  128.                                         }
  129.                                     }
  130.                                     break;
  131.                                    
  132.                                 default:
  133.                                     break;
  134.                             }
  135.                            
  136.                             lastOne = 0;
  137.                         }
  138.  
  139.                         if (lastOne == 0) {
  140.                             getOne();  
  141.                         } else {}
  142.                     }
  143.  
  144.                 } else if (section.sectionName.toLower == "input-output") {
  145.  
  146.                     // code gen
  147.  
  148.                     // its illegal for code gen divisions to occur before context
  149.                     // so we should have all the info we need to do this
  150.  
  151.                     foreach(sentence; section) {
  152.                        
  153.                     }
  154.                 }
  155.             }
  156.         }),
  157.         DivisionHandler("data", (SectionSST sections, ref ASTContext context) {
  158.             // code gen
  159.  
  160.             // its illegal for code gen divisions to occur before context
  161.             // so we should have all the info we need to do this
  162.  
  163.             foreach(section; sections) {
  164.                 if (section.sectionName.toLower == "file") {
  165.                    
  166.                 } else if (section.sectionName.toLower == "working-storage") {
  167.                    
  168.                 }
  169.             }
  170.         }),
  171.         DivisionHandler("procedure", (SectionSST sections, ref ASTContext context) {
  172.             // code gen
  173.  
  174.             // its illegal for code gen divisions to occur before context
  175.             // so we should have all the info we need to do this
  176.  
  177.             foreach(section; sections) {
  178.  
  179.             }
  180.         })
  181.     );
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement