Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/ntuple/qp_scanner_l.l is written in an unsupported language. File is not indexed.

0001 /*
0002  *  qp_scanner.l  - (flex) scanner source for selfun
0003  *
0004  *  Original: 15-Jun-1994 15:16
0005  *
0006  *  Author:   Maarten Ballintijn <Maarten.Ballintijn@cern.ch>
0007  *
0008  *  $Id$
0009  *
0010  *  $Log$
0011  *  Revision 1.10  1996/05/14 12:23:31  maartenb
0012  *  - Fix prototypes.
0013  *
0014  *  - Fix static bool conversions
0015  *
0016  *  Revision 1.9  1996/04/23 18:38:57  maartenb
0017  *  - Add RCS keywords
0018  *
0019  *
0020  */
0021 
0022 %{
0023 /* Derived from $Id$ */
0024 
0025 #define         YY_NEVER_INTERACTIVE    1
0026 
0027 #include        <ctype.h>
0028 #include        <math.h>
0029 #include        <stdlib.h>
0030 #include        <string.h>
0031 
0032 #include        "str.h"
0033 #include        "mstr.h"
0034 #include        "qp_lexyacc.h"
0035 #include        "qp_report.h"
0036 #include        "qp_tree.h"
0037 
0038 #include        "qp_parser.h" /* generated, should be included last */
0039 
0040 #ifdef LEX_DEBUG
0041 #define DB { printf( "\"%s\"\n", yytext ); }
0042 #define DB1(ID) { printf( "%s: \"%s\"\n", ID, yytext ); }
0043 #else
0044 #define DB
0045 #define DB1(ID)
0046 #endif
0047 
0048 
0049 static int      inp_len = 0;
0050 static int      inp_index = 0;
0051 static char     *inp_buf = 0;
0052 
0053 void
0054 qp_scanner_set_input( char *s )
0055 {
0056         if ( inp_buf ) free( inp_buf );
0057 
0058         inp_buf = str_new( s );
0059         inp_len = strlen( s );
0060         inp_index = 0;
0061 
0062         yyrestart( stdin ); /* stdin is just ref'd for isatty :-( */
0063 }
0064 
0065 
0066 void
0067 qp_scanner_get_pos( char **s, int *i )
0068 {
0069         if ( inp_buf ) {
0070                 *s = inp_buf;
0071                 *i = inp_index;
0072         } else {
0073                 *s = 0;
0074                 *i = -1;
0075         }
0076 }
0077 
0078 
0079 /*
0080 #define YY_INPUT( buf, result, max_size ) { \
0081         int len = max_size > inp_len ? inp_len : max_size; \
0082         memcpy( buf, &inp_buf[inp_index], len ); \
0083         inp_index += len; inp_len -= len; \
0084         result = len; }
0085 */
0086         
0087 yy_input_routine( char *buf, int * result, int max_size )
0088 {
0089 /*
0090         int len = max_size > inp_len ? inp_len : max_size;
0091         memcpy( buf, &inp_buf[inp_index], len );
0092         inp_index += len;
0093         inp_len -= len;
0094         *result = len;
0095 */
0096         if ( inp_len > 0 ) {
0097                 buf[0] = inp_buf[inp_index];
0098                 inp_index += 1;
0099                 inp_len -= 1;
0100                 *result = 1;
0101         } else {
0102                 *result = YY_NULL;
0103         }
0104 }
0105 
0106 #define YY_INPUT( buf, result, max_size ) \
0107         yy_input_routine( buf, &(result), max_size )
0108 
0109 static int
0110 int_conv( char  * const str )
0111 {
0112         return atoi( str );
0113 }
0114 
0115 
0116 static int
0117 uint_conv( char *str )
0118 {
0119         int     r, base;
0120 
0121         switch ( *str ) {
0122         case 'z': case 'Z':     base = 16; break;
0123         case 'o': case 'O':     base = 8; break;
0124         case 'b': case 'B':     base = 2; break;
0125         }
0126 
0127         for ( r=0, str += 2; *str != '\''; str++ ) {
0128                 if ( isdigit( *str ) )
0129                         r = r * base + ( *str - '0' );
0130                 else if ( isupper( *str ) )
0131                         r = r * base + ( *str - 'A' + 10 );
0132                 else /* islower( *str ) */
0133                         r = r * base + ( *str - 'a' + 10 );
0134         }
0135 
0136         return r;
0137 }
0138 
0139 
0140 static double
0141 double_conv( char * const str )
0142 {
0143         double  lfval;
0144         char    *p, *end, save;
0145 
0146         p = strchr( str, 'd' );
0147 
0148         if ( p != 0 ) {
0149                 save = *p;
0150                 *p = 'e';
0151         } else {
0152                 p = strchr( str, 'D' );
0153                 if ( p != 0 ) {
0154                         save = *p;
0155                         *p = 'e';
0156                 }
0157         }
0158 
0159         lfval = strtod( str, & end );
0160 
0161         if ( *end != '\0' ) {   /* did not convert the full string ?? */
0162                 qp_abort( "double_conv: strtod failed\n" );
0163         }
0164 
0165         if ( p != 0 ) {
0166                 *p = save;
0167         }
0168 
0169         return lfval;
0170 }
0171 
0172 
0173 %}
0174 
0175 OR      \.[Oo][Rr]\.
0176 AND     \.[Aa][Nn][Dd]\.
0177 NOT     \.[Nn][Oo][Tt]\.
0178 
0179 LT      \.[Ll][Tt]\.
0180 LE      \.[Ll][Ee]\.
0181 GT      \.[Gg][Tt]\.
0182 GE      \.[Gg][Ee]\.
0183 
0184 EQ      \.[Ee][Qq]\.
0185 NE      \.[Nn][Ee]\.
0186 CT      \.[Cc][Tt]\.
0187 
0188 TRUE    \.[Tt][Rr][Uu][Ee]\.
0189 FALSE   \.[Ff][Aa][Ll][Ss][Ee]\.
0190 
0191 LET     [a-zA-Z_$]
0192 NUMLET  [a-zA-Z0-9_$]
0193 INT     [0-9]+
0194 EXP     ([eE][+-]?{INT})
0195 DEXP    ([dD][+-]?{INT})
0196 MANT    (({INT}"."?)|({INT}?"."{INT}))
0197 IN      \.[Ii][Nn]\.
0198 
0199 %%
0200 
0201 ">>"            { DB1("T_PUT_MASK"); return T_PUT_MASK;}
0202 
0203 {IN}            { DB1("T_IN"); return T_IN;}
0204 
0205 "||"|{OR}       { DB1("T_OR"); return T_OR;}
0206 "&&"|{AND}      { DB1("T_AND"); return T_AND;}
0207 "!"|{NOT}       { DB1("T_NOT"); return T_NOT;}
0208 
0209 "<"|{LT}        { DB1("T_LT"); return T_LT;}
0210 "<="|{LE}       { DB1("T_LE"); return T_LE;}
0211 
0212 ">"|{GT}        { DB1("T_GT"); return T_GT;}
0213 ">="|{GE}       { DB1("T_GE"); return T_GE;}
0214 
0215 "=="|"="|{EQ}   { DB1("T_EQ"); return T_EQ;}
0216 "!="|"<>"|{NE}  { DB1("T_NE"); return T_NE;}
0217 "#"|{CT}        { DB1("T_NE"); return T_NE;}
0218 
0219 "**"|"^"        { DB1("T_POWER"); return T_POWER;}
0220 
0221 "$"{INT}        { DB1("T_CUT"); qp_parser_lval.num = int_conv(&yytext[1]); return T_CUT;}
0222 
0223 {TRUE}          { DB1("T_BOOL"); qp_parser_lval.num = 1; return T_BOOL;}
0224 {FALSE}         { DB1("T_BOOL"); qp_parser_lval.num = 0; return T_BOOL;}
0225 
0226 [Zz]\'[a-fA-F0-9]+\'    |
0227 [Oo]\'[0-7]+\'          |
0228 [Bb]\'[01]+\'   { DB1("T_UNSIGNED"); qp_parser_lval.num = uint_conv(yytext); return T_UNSIGNED;}
0229 
0230 {LET}{NUMLET}*  { DB1("T_IDENT"); qp_parser_lval.str = mstr_new(yytext); return T_IDENT;}
0231 
0232 {INT}/{OR}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0233 {INT}/{AND}     { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0234 {INT}/{EQ}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0235 {INT}/{NE}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0236 {INT}/{LT}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0237 {INT}/{LE}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0238 {INT}/{GT}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0239 {INT}/{GE}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0240 {INT}/{CT}      { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0241 {INT}           { DB1("T_INT"); qp_parser_lval.num = int_conv(yytext); return T_INT;}
0242 
0243 {MANT}{EXP}?    { DB1("T_FLOAT"); qp_parser_lval.real = double_conv(yytext); return T_FLOAT;}
0244 
0245 {MANT}{DEXP}?   { DB1("T_DOUBLE"); qp_parser_lval.real = double_conv(yytext); return T_DOUBLE;}
0246 
0247 \'[^'\n]*\'     { DB1("T_STRING"); qp_parser_lval.str = mstr_new(&yytext[1]);
0248                         qp_parser_lval.str[strlen(yytext)-2] = 0; return T_STRING;}
0249 
0250 \"[^"\n]*\"     { DB1("T_IDENT"); qp_parser_lval.str = mstr_new(&yytext[1]);
0251                         qp_parser_lval.str[strlen(yytext)-2] = 0; return T_IDENT;}
0252 
0253 [*/+\-$[\].():,~]       { DB; return *yytext; }
0254 
0255 \n              yyterminate();
0256 <<EOF>>         yyterminate();
0257 
0258 .               { DB1("T_UNKNOWN"); return T_UNKNOWN;}