Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- void main()
- {
- import std.string : toLower, strip, indexOf;
- import SSTlexer;
- // reads the file
- auto sst_lexer = SSTLexer("PAY9.CBL");
- import divisionSST;
- // breaks sentences up into the apropriete divisions
- auto division_sst = DivisionSST(sst_lexer);
- import astContext;
- import sectionSST;
- // initiate the context for the entire program
- ASTContext ast_context;
- // TODO: create the step after nexts output range
- // even if the ast_context isn't already assigned to, we have the reference to it
- // now for each appropriate division do handle the sections sentences
- // assigns the context to ast_context (before it's used)
- division_sst.map(ast_context,
- DivisionHandler("identification", (SectionSST sections, ref ASTContext context) {
- // context
- ubyte lastOne;
- foreach(section; sections) {
- foreach(sentence; section) {
- if (lastOne == 0) {
- string lowered = sentence.toLower[0 .. $-1];
- if (lowered == "program-id") {
- lastOne = 1;
- } else if (lowered == "author") {
- lastOne = 2;
- } else if (lowered == "installation") {
- lastOne = 3;
- } else if (lowered == "date-written") {
- lastOne = 4;
- } else if (lowered == "date-compiled") {
- lastOne = 5;
- } else if (lowered == "security") {
- lastOne = 6;
- } else {} // do nothing
- } else {
- switch(lastOne) {
- case 1:
- context.id = sentence[0 .. $-1].strip;
- break;
- case 2:
- context.author = sentence[0 .. $-1].strip;
- break;
- case 3:
- context.installation = sentence[0 .. $-1].strip;
- break;
- case 4:
- context.date_written = sentence[0 .. $-1].strip;
- break;
- case 5:
- context.date_compiled = sentence[0 .. $-1].strip;
- break;
- case 6:
- context.security = sentence[0 .. $-1].strip;
- break;
- default:
- break;
- }
- lastOne = 0;
- }
- }
- }
- }),
- DivisionHandler("environment", (SectionSST sections, ref ASTContext context) {
- foreach(section; sections) {
- if (section.sectionName.toLower == "configuration") {
- // context
- ubyte lastOne;
- foreach(sentence; section) {
- bool getOne() {
- string lowered = sentence.toLower[0 .. $-1];
- if (lowered == "source-computer") {
- lastOne = 1;
- } else if (lowered == "object-computer") {
- lastOne = 2;
- } else if (lowered == "special-names") {
- lastOne = 3;
- } else {
- return false;
- }
- return true;
- }
- void handle() {
- import std.algorithm : count;
- switch(lastOne) {
- case 1:
- context.source_computer = setence[0 .. $-1].strip;
- break;
- case 2:
- context.object_computer = setence[0 .. $-1].strip;
- break;
- case 3:
- if (getOne()) {
- handle();
- } else {
- if (sentence.count(' ') == 2) {
- auto iloc = sentence.indexOf(' ');
- auto first = sentence[0 .. iloc];
- auto second = sentence[iloc + 1 .. $];
- assert(second[0 .. 2].toLower == "is"); // TODO: really?
- second = second[second.indexOf(' ') + 1 .. $-1];
- context.specialNames = ASTSpecialName(second, first);
- }
- }
- break;
- default:
- break;
- }
- lastOne = 0;
- }
- if (lastOne == 0) {
- getOne();
- } else {}
- }
- } else if (section.sectionName.toLower == "input-output") {
- // code gen
- // its illegal for code gen divisions to occur before context
- // so we should have all the info we need to do this
- foreach(sentence; section) {
- }
- }
- }
- }),
- DivisionHandler("data", (SectionSST sections, ref ASTContext context) {
- // code gen
- // its illegal for code gen divisions to occur before context
- // so we should have all the info we need to do this
- foreach(section; sections) {
- if (section.sectionName.toLower == "file") {
- } else if (section.sectionName.toLower == "working-storage") {
- }
- }
- }),
- DivisionHandler("procedure", (SectionSST sections, ref ASTContext context) {
- // code gen
- // its illegal for code gen divisions to occur before context
- // so we should have all the info we need to do this
- foreach(section; sections) {
- }
- })
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement