next up previous contents
Next: Parser - the input Up: Design And implementation of Previous: Flex and Bison working   Contents


Scanner - the input file for Flex

Below there is the input file for Flex to generate a scanner which is used in Controller, Generator and Validator to scan during opening an Osiris datafile.

%{
#define MAXBUF 1024

#include <gtk/gtk.h>
#include <glib.h>
#include "main.h"
#include "ogener.tab.h"

char string_buff[MAXBUF];

%}

DIGIT        [0-9]
INTEGER      {DIGIT}+
ID           [[:alnum:]._/]* 

%x text
%%
    char text_buf[MAXBUF];
    char *text_buf_ptr;

"<?xml version=\"1.0\"?>" {return PREAMBLE;}
"<osiris>" {return OSIRISB;}
"</osiris>" {return OSIRISE;}
"<project>" {return PROJECTB;}
"</project>" {return PROJECTE;}
"<outputfn>" {return OUTPUTFNB;}
"</outputfn>" {return OUTPUTFNE;}
"<validator>" {return VALIDATORB;}
"</validator>" {return VALIDATORE;}
"<generator>" {return GENERATORB;}
"</generator>" {return GENERATORE;}
"<launcher>" {return LAUNCHERB;}
"</launcher>" {return LAUNCHERE;}
"<object>" {return OBJECTB;}
"</object>" {return OBJECTE;}
"<id>" {return IDB;}
"</id>" {return IDE;}
"<x>" {return XB;}
"</x>" {return XE;}
"<y>" {return YB;}
"</y>" {return YE;}
"<width>" {return WIDTHB;}
"</width>" {return WIDTHE;}
"<height>" {return HEIGHTB;}
"</height>" {return HEIGHTE;}
"<type>" {return TYPEB;}
"</type>" {return TYPEE;}
"<cols>" {return COLSB;}
"</cols>" {return COLSE;}
"<rows>" {return ROWSB;}
"</rows>" {return ROWSE;}
"<table>" {text_buf_ptr=text_buf; 
           BEGIN(text); 
           return TABLEB;}
"</table>" {return TABLEE;}
"<connection>" {return CONNECTIONB;}
"</connection>" {return CONNECTIONE;}
"<lastid>" {return LASTIDB;}
"</lastid>" {return LASTIDE;}

<text>. {*text_buf_ptr++=yytext[0];}
<text>"</table>" 
    {*text_buf_ptr++=0;
     unput('>'); unput('e'); unput('l'); unput('b');
     unput('a'); unput('t'); unput('/'); unput('<');
     BEGIN(INITIAL);
     yylval=text_buf; return STRING;}

{INTEGER}    {yylval=atoi(yytext) ; return INTEGER;}

{ID}     {strcpy(string_buff,yytext); 
          yylval=string_buff; 
          return STRING;}

[ \t\n]+          /* eat up whitespace */

%%



Igor Wojnicki 2001-02-21