/**********************/ /* LOTOS-2-MML filter */ /**********************/ /* Daniel Amyot, University of Ottawa, August 10, 1996 */ /* Translates a LOTOS spec into a readable MML file. */ /* MML files can then be imported in FrameMaker. */ /* Compile using: flex -i flex -i lot2html.lex */ /* gcc -O2 lexyy.c -o lot2html.exe */ /* Keywords and comments (only) are enhanced with */ /* user-defined tags (MML macros) */ /* The structure of the spec and upper/lowercase characters */ /* remain unchanged. No grammatical checking done. */ /* Last update: September 14 1996 */ /************************************************************/ %option noyywrap %{ #define VERSION "0.2" #define TODAY "September 14, 1996" #include #include struct tm *date_time; time_t timer; %} %% [ ] printf(""); \t printf("\t"); \n printf("

\n"); \< printf("\\<");; \> printf("\\>"); \\ printf("\\"); accept|actualizedby|any|behavior|behaviour|endlib|endproc|endspec|endtype|eqns|exit|for|forall|formaleqns|formalopns|formalsorts|hide|i|in|is|let|library|noexit|of|ofsort|opnnames|opns|par|process|renamedby|specification|sorts|sortnames|stop|type|using|where { /* ALL KEYWORDS */ printf("%s", yytext); }; "(*" { /* COMMENTS */ register int c; printf("(*"); for ( ; ; ) { while ( (c = input()) != '*' && c != EOF ) switch (c) { case ' ' : printf(""); break; case '\t' : printf("\t"); break; case '\n' : printf("\\n\n"); break; case '<' : printf("\\<"); break; case '>' : printf("\\>"); break; case '\\' : printf("\\"); break; default : printf("%c", c); }; /* text comment */ if ( c == '*' ) { printf("*"); while ( (c = input()) == '*' ) printf("*"); if ( c == ')' ) { /* End of comment */ printf(")"); break; } else switch (c) { case ' ' : printf(""); break; case '\t' : printf("\t"); break; case '\n' : printf("\\n\n"); break; case '<' : printf("\\<"); break; case '>' : printf("\\>"); break; case '\\' : printf("\\"); break; default : printf("%c", c); }; /* text comment */ } if ( c == EOF ) { fprintf(stderr, "Warning: EOF in comment." ); printf(")"); break; } } } [a-z0-9_][a-z0-9_]* { /* IDENTIFIERS */; printf("%s", yytext); }; %% /**************************************************************/ main( argc, argv ) int argc; char **argv; { char def_file[128]=""; char title[128]="Untitled"; char exist_def_file=0; /* No definition file assumed */ /* SDTIN or file? */ ++argv, --argc; /* skip over program name */ yyin = stdin; if ( argc > 0 ) if (strnicmp(argv[0], "-h", 2)) { if (!strnicmp(argv[0], "-d", 2)) { strcpy(def_file, argv[1]); exist_def_file = 1; if (argc > 2) if ((yyin = fopen( argv[2], "r" ))==NULL) { fprintf(stderr, "Unknown input file. Translation aborted.\n\n"); exit(0); } else strcpy(title, argv[2]); } else if ((yyin = fopen( argv[0], "r" ))==NULL) { fprintf(stderr, "Unknown input file. Translation aborted.\n\n"); exit(0); } else strcpy(title, argv[0]); } else /* HELP FILE */ { printf("\n\tlot2mml, (c) Daniel Amyot (damyot@csi.uottawa.ca).\n"); printf("\tVersion %s, %s\n\n", VERSION, TODAY); printf("\tUsage: lot2mml [-d DefFile] [InFile] [>OutFile]\n"); printf("\t lot2mml -h (get this help file)\n\n"); printf("\tWhere: DefFile = Definition file (MML Macros). Internal default values.\n"); printf("\t InFile = Input file (in LOTOS). Default is stdin\n"); printf("\t OutFile = Output file (in MML). Default is stdout\n"); printf("\tSee also the configuration file: lot2mml.def\n\n"); exit(0); } printf("\n\n", title); printf("\n", VERSION, TODAY); time(&timer); date_time=localtime(&timer); printf("\n\n", asctime(date_time)); /************************************************************/ if (exist_def_file == 1) printf("\n\n", def_file); else /* Default definitions */ printf("\n\ \n\n\ \n\ \">\n\ \">\n\ \">\n\n\ \n\ \n\ \n\ \n\ >\n\ \n\ >\n\n\ \n\ \n\ \">\n\ \">\n\ \n\ \">\n\ \">\n\n\ \n\n" ); /************************************************************/ yylex(); }