%{ static char const rcsid [] = "$Id: maps_scan.l,v 1.1 1998/04/22 10:21:22 stojanov Exp $"; /*****************************************************************************/ /* */ /* Unit: MAPS_SCAN (Lex source specification module - language tokens) */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 15 APR 98 */ /* */ /* Lex source code for the lexical analysis of the specification file in */ /* the description language */ /* */ /*****************************************************************************/ #include #include #include "maps_pars.h" #include "maps_pars.tab.h" #define STRING_PICK_SIZE 88 extern int current_line_number; extern char *current_file_name; char *numer; void llerror (char *message); /* Internal conversion procedures of the scanner module */ long int SCAN_Int_Conv (char *str); double SCAN_Float (char *str); char *SCAN_String (char first); /* Macro TOKEN defined for token return */ #define TOKEN(x) return x; %} letter [a-zA-Z] digit [0-9] anum {letter}|{digit} %% \#.*\n { current_line_number++; } [\t" "] ; \n { current_line_number++; } ABSOLUTE { TOKEN (T_ABSOLUTE); } ADJUSTMENT { TOKEN (T_ADJUSTMENT); } ALIAS { TOKEN (T_ALIAS); } ALIGNMENT { TOKEN (T_ALIGNMENT); } ALL { TOKEN (T_ALL); } ANNOTATIONS { TOKEN (T_ANNOTATIONS); } AT { TOKEN (T_AT); } BANNER { TOKEN (T_BANNER); } BLACK { TOKEN (T_BLACK); } BOTTOM { TOKEN (T_BOTTOM); } BOX { TOKEN (T_BOX); } BOXED { TOKEN (T_BOXED); } CENTERED { TOKEN (T_CENTERED); } CONTENT { TOKEN (T_CONTENT); } COUNTER { TOKEN (T_COUNTER); } DARKGRAY { TOKEN (T_DARKGRAY); } DARK[" "\t\n]+GRAY { TOKEN (T_DARKGRAY); } DASHED { TOKEN (T_DASHED); } DESCRIPTION { TOKEN (T_DESCRIPTION); } DOTTED { TOKEN (T_DOTTED); } DOT"-"DASH { TOKEN (T_DOTDASH); } DOT[" "\t\n]+"-"[" "\t\n]+DASH { TOKEN (T_DOTDASH); } DOT[" "\t\n]*DASH { TOKEN (T_DOTDASH); } DOTTED"-"DASHED { TOKEN (T_DOTDASH); } DOTTED[" "\t\n]+"-"[" "\t\n]+DASHED { TOKEN (T_DOTDASH); } DOTTED[" "\t\n]*DASHED { TOKEN (T_DOTDASH); } DOUBLE { TOKEN (T_DOUBLE); } ENDED { TOKEN (T_ENDED); } EVERY { TOKEN (T_EVERY); } FIELD { TOKEN (T_FIELD); } FILE { TOKEN (T_FILE); } FONT { TOKEN (T_FONT); } FROM { TOKEN (T_FROM); } GENERAL { TOKEN (T_GENERAL); } GRAY { TOKEN (T_GRAY); } IN { TOKEN (T_IN); } INFORMATION { TOKEN (T_INFORMATION); } INTERMEDIATE { TOKEN (T_INTERMEDIATE); } LABEL { TOKEN (T_LABEL); } LANDMARK { TOKEN (T_LANDMARK); } LANDMARKS { TOKEN (T_LANDMARKS); } LANDSCAPE { TOKEN (T_LANDSCAPE); } LEFT { TOKEN (T_LEFT); } LENGTH { TOKEN (T_LENGTH); } LIGHTGRAY { TOKEN (T_LIGHTGRAY); } LIGHT[" "\t\n]+GRAY { TOKEN (T_LIGHTGRAY); } LITERALLY { TOKEN (T_LITERALLY); } LOAD { TOKEN (T_LOAD); } MARK { TOKEN (T_MARK); } MARKED { TOKEN (T_MARKED); } NAME { TOKEN (T_NAME); } NO { TOKEN (T_NO); } NOT { TOKEN (T_NOT); } NULL { TOKEN (T_NULL); } ORIENTATION { TOKEN (T_ORIENTATION); } ORIGIN { TOKEN (T_ORIGIN); } ORIGINS { TOKEN (T_ORIGINS); } OUTPUT { TOKEN (T_OUTPUT); } PAGE { TOKEN (T_PAGE); } PATH { TOKEN (T_PATH); } PIVOT { TOKEN (T_PIVOT); } PORTRAIT { TOKEN (T_PORTRAIT); } POSITION { TOKEN (T_POSITION); } POSTSCRIPT { TOKEN (T_POSTSCRIPT); } RANGE { TOKEN (T_RANGE); } REPEATED { TOKEN (T_REPEATED); } RIGHT { TOKEN (T_RIGHT); } SEQUENCES { TOKEN (T_SEQUENCES); } SHADE { TOKEN (T_SHADE); } SHOW { TOKEN (T_SHOW); } SINGLE { TOKEN (T_SINGLE); } SIZE { TOKEN (T_SIZE); } SOLID { TOKEN (T_SOLID); } SPACING { TOKEN (T_SPACING); } STARTED { TOKEN (T_STARTED); } STRICT { TOKEN (T_STRICT); } STRIPPED { TOKEN (T_STRIPPED); } STYLE { TOKEN (T_STYLE); } TEXT { TOKEN (T_TEXT); } TICKMARK { TOKEN (T_TICKMARK); } TO { TOKEN (T_TO); } TOP { TOKEN (T_TOP); } TRAILER { TOKEN (T_TRAILER); } UNDERLINE { TOKEN (T_UNDERLINE); } UNDERLINED { TOKEN (T_UNDERLINED); } WHITE { TOKEN (T_WHITE); } WIDTH { TOKEN (T_WIDTH); } WILDCARD { TOKEN (T_WILDCARD); } ";" { TOKEN (*yytext); } "," { TOKEN (*yytext); } "-"(" "|\t)*{digit}+ { numer = yytext; while ((*numer < '0') || (*numer > '9')) numer++; yylval.lint = - SCAN_Int_Conv (numer); TOKEN (T_INTNUM); } {digit}+ { yylval.lint = SCAN_Int_Conv (yytext); TOKEN (T_INTNUM); } {digit}+"."{digit}+ { yylval.real = SCAN_Float (yytext); TOKEN (T_REALNUM); } \". { yylval.strg = SCAN_String (yytext [1]); TOKEN (T_STRING); } . { llerror ("Illegal character"); } %% /*****************************************************************************/ /* */ /* Procedure: llerror */ /* */ /* Error reporting for lexical analysis */ void llerror (char *message) { fprintf (stderr, "ERROR: %s\n in line %d of file %s\n\n", message, current_line_number, current_file_name); exit (1); } /*****************************************************************************/ /* */ /* Procedure: SCAN_Int_Conv */ /* */ /* Conversion of integer in string form to a number */ long int SCAN_Int_Conv (char *str) { long int extract, current; int size; char *browse; extract = 0; size = 0; browse = str; while (*browse != '\0') { current = (int) (*browse - '0'); browse++; extract = 10 * extract + current; size++; } return extract; } /*****************************************************************************/ /* */ /* Procedure: SCAN_Float */ /* */ /* Conversion of float in string form to a number */ double SCAN_Float (char *str) { long int whole, fraction; double extract; char *browse; int fr_size; /* Divide the simple float at '.'; calculate whole and fraction part of the */ /* number separately */ browse = str; while (*browse != '.') browse++; *browse = '\0'; whole = SCAN_Int_Conv (str); *browse = '.'; browse++; fraction = SCAN_Int_Conv (browse); /* Determine the actual value of the fractional part */ fr_size = 0; while (*browse != '\0') { fr_size++; browse++; } extract = 0.0; while (fr_size > 0) { extract = extract / 10.0 + (fraction % 10); fraction /= 10; fr_size--; } /* Calculate and return the exact value of the simple float */ return extract / 10.0 + (double) whole; } /*****************************************************************************/ /* */ /* Procedure: SCAN_String */ /* */ /* Procedure to collect a quoted string from the input; returns the string */ char *SCAN_String (char first) { char *in_buff, *rep_string, *out_string, pick; bool escaped; int buff_size, buff_pos; if (first == '\"') { rep_string = (char *) NTL0_ckalloc ((44 + strlen (current_file_name)) * sizeof (char)); sprintf (rep_string, "Empty string in line %d of file %s", current_line_number, current_file_name); CONT_Warning (rep_string); free (rep_string); out_string = (char *) NTL0_ckalloc (sizeof (char)); out_string [0] = '\0'; } else if (first == EOF) llerror ("Unexpected end-of-file in string"); else if ((first < ' ') || (first > 126)) llerror ("Illegal character in string"); else { in_buff = (char *) NTL0_ckalloc (STRING_PICK_SIZE * sizeof (char)); in_buff [0] = first; if (first == '\\') escaped = TRUE; else escaped = FALSE; buff_size = STRING_PICK_SIZE; buff_pos = 1; while ((escaped) || ((pick = input ())) != '\"') { if (pick == EOF) llerror ("Unexpected end-of-file in string"); else if ((pick < ' ') || (pick > 126)) llerror ("Illegal character in string"); else if ((!escaped) && (pick == '\\')) escaped = TRUE; else if (escaped) escaped = FALSE; in_buff [buff_pos] = pick; buff_pos++; if (buff_pos == buff_size) { in_buff = (char *) NTL0_ckrealloc (in_buff, 2 * buff_size * sizeof (char)); buff_size *= 2; } } in_buff [buff_pos] = '\0'; out_string = (char *) NTL0_ckalloc ((strlen (in_buff) + 1) * sizeof (char)); strcpy (out_string, in_buff); free (in_buff); } return out_string; }