/********************************
*
*  fsl-0.1.0-01.l
*
* Scanner for Atoms of FSL1.0.1
* 
* Standalone Test Version
*
* author: gerd doeben-henisch
* first: may-14, 2004
* last: may-14, 2004
*
**************************************
*
* Which kinds of tokens are needed?
*
* DATA TYPES  <---------> {system, int, float, bool,  str,  struct, [] }
* VARIABLE NAMES <------> {First sign UPPER, then LOWER or UPPER or  DIGIT or MINUS or UNDER }
* UNIT ITEMS <----------> {year, month, week, day, hour, minute, sec, msec, usec }
* SYSTEM NAMES <--------> {First sign LOWER, then LOWER or UPPER or  DIGIT or MINUS or UNDER }
* KONSTANT ITEMS <------> {INT, FLOAT, BOOL, CHAR, STRING }
* SPECIAL SIGNS <-------> {COLON, LB, RB, LSB, RSB, LCB, RCB, SEP, EQU, MINUS, UNDER }
* COMMENTS <------------> '\/\/' as one-line-comment or '\/\* ... \*\/' as multi-line-comment
* 
*********************************************************************************************
* STRING
* Everything between two \" ... \" except the \" itself is a string
* Only the signs between the \"-signs are comitted
*
********************************************************************/
%{
   #include <stdio.h>
   #include <string.h>
%}


%s FSL FSLSTR   
%x COMMENT

LB         \(         
RB          \)       
LSB        "["       
RSB        "]"         
LCB        "{"         
RCB        "}"         
SEP        ","         
COLON      ";"         
EQU        "="         
MINUS      "-"         
UNDER      "_"  
LOWER      [a-z]+
UPPER      [A-Z]+
DIGIT       [0-9]+
INT        [-]?{DIGIT}
FLOAT      {INT}+"."{DIGIT}
ALPHANUM   [[:alnum:]]+
NEWLINE    ("\r"|"\n"|"\r\n")
VARNAME    {UPPER}+[[:alnum:]{MINUS}{UNDER}]*
SYSNAME    {LOWER}+[[:alnum:]{MINUS}{UNDER}]*
%%

%{
	BEGIN (FSL);	
%}




<FSL>"//".*{NEWLINE}  { printf( "ONE-LINE-COMMENT: %s\n", yytext );  
	                /*throw away comment*/
	          ;}

<FSL>"/*" {  printf( "multi-LINE-COMMENT, Begin: %s\n", yytext ); 
	BEGIN (COMMENT);
	yymore();	
}

<COMMENT>[^*]+ { 
	yymore();
}

<COMMENT>"*/" { printf( "multi-LINE-COMMENT, End: %s\n", yytext );
	         /*throw away comment*/
	         BEGIN (FSL);
}

<COMMENT>"*" {
	yymore();
}



<FSL>["]       {  printf( "STRING-START: %s\n", yytext ); 
	          BEGIN (FSLSTR);		
}

<FSLSTR>["]       {  printf( "\n STRING-END:  %s\n", yytext ); 
	          BEGIN (FSL);		
}

<FSL>[ \t]       ;


<FSL>\(          { printf( "LB: %s\n", yytext );  }
<FSL>\)          { printf( "RB: %s\n", yytext );  }
<FSL>"["          { printf( "LSB: %s\n", yytext );  }
<FSL>"]"          {printf( "RSB: %s\n", yytext );  }
<FSL>"{"          { printf( "LCB: %s\n", yytext );  }
<FSL>"}"          { printf( "RCB: %s\n", yytext );  }
<FSL>","           { printf( "SEP: %s\n", yytext );  }
<FSL>";"          { printf( "COLON: %s\n", yytext );  }
<FSL>"."          { printf( "DOT: %s\n", yytext );  }
<FSL>"="          { printf( "EQU: %s\n", yytext );  }
<FSL>"-"          { printf( "MINUS: %s\n", yytext );  }
<FSL>"_"          { printf( "UNDER: %s\n", yytext );  }


<FSL>int    {printf( "TYPE: %s \n", yytext); }
<FSL>float    {printf( "TYPE: %s \n", yytext); }
<FSL>str    {printf( "TYPE: %s \n", yytext); }
<FSL>struct    {printf( "TYPE: %s \n", yytext); }
<FSL>system    {printf( "TYPE: %s \n", yytext); }


<FSL>year    {printf( "UNIT: %s \n", yytext);  }
<FSL>month    {printf( "UNIT: %s \n", yytext);  }
<FSL>week    {printf( "UNIT: %s \n", yytext);  }
<FSL>day    {printf( "UNIT: %s \n", yytext);  }
<FSL>hour    {printf( "UNIT: %s \n", yytext);  }
<FSL>min    {printf( "UNIT: %s \n", yytext);  }
<FSL>sec    {printf( "UNIT: %s \n", yytext);  }
<FSL>msec    {printf( "UNIT: %s \n", yytext);  }
<FSL>usec    {printf( "UNIT: %s \n", yytext);  }



<FSL>if       {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>while    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }

<FSL>add    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>concat   {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>findsubstr   {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>isequ    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>less    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>receive    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>send    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }
<FSL>subst    {printf( "BUILT-IN SYS-CALL: %s \n", yytext);  }


<FSL>{INT}       {printf( "INT: %s \n", yytext);  }
<FSL>{FLOAT}     {printf( "FLOAT: %s \n", yytext);  }

<FSL>true            {printf( "BOOL: %s \n", yytext);  }
<FSL>false            {printf( "BOOL: %s \n", yytext);  }



<FSL>{VARNAME}    {printf( "VARNAME: %s \n", yytext);  }
<FSL>{SYSNAME}    {printf( "SYSNAME: %s \n", yytext);  }








%%

int main( int argc, char **argv ) {
         
         ++argv;
          --argc;  /* skip over program name */

         if ( argc > 0 ){
                 yyin = fopen( argv[0], "r" ); }
         else {
                 yyin = stdin; }

         yylex();
         }