linux/scripts/genksyms/lex.l
<<
>>
Prefs
   1/* Lexical analysis for genksyms.
   2   Copyright 1996, 1997 Linux International.
   3
   4   New implementation contributed by Richard Henderson <rth@tamu.edu>
   5   Based on original work by Bjorn Ekwall <bj0rn@blox.se>
   6
   7   Taken from Linux modutils 2.4.22.
   8
   9   This program is free software; you can redistribute it and/or modify it
  10   under the terms of the GNU General Public License as published by the
  11   Free Software Foundation; either version 2 of the License, or (at your
  12   option) any later version.
  13
  14   This program is distributed in the hope that it will be useful, but
  15   WITHOUT ANY WARRANTY; without even the implied warranty of
  16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17   General Public License for more details.
  18
  19   You should have received a copy of the GNU General Public License
  20   along with this program; if not, write to the Free Software Foundation,
  21   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  22
  23
  24%{
  25
  26#include <limits.h>
  27#include <stdlib.h>
  28#include <string.h>
  29#include <ctype.h>
  30
  31#include "genksyms.h"
  32#include "parse.tab.h"
  33
  34/* We've got a two-level lexer here.  We let flex do basic tokenization
  35   and then we categorize those basic tokens in the second stage.  */
  36#define YY_DECL         static int yylex1(void)
  37
  38%}
  39
  40IDENT                   [A-Za-z_\$][A-Za-z0-9_\$]*
  41
  42O_INT                   0[0-7]*
  43D_INT                   [1-9][0-9]*
  44X_INT                   0[Xx][0-9A-Fa-f]+
  45I_SUF                   [Uu]|[Ll]|[Uu][Ll]|[Ll][Uu]
  46INT                     ({O_INT}|{D_INT}|{X_INT}){I_SUF}?
  47
  48FRAC                    ([0-9]*\.[0-9]+)|([0-9]+\.)
  49EXP                     [Ee][+-]?[0-9]+
  50F_SUF                   [FfLl]
  51REAL                    ({FRAC}{EXP}?{F_SUF}?)|([0-9]+{EXP}{F_SUF}?)
  52
  53STRING                  L?\"([^\\\"]*\\.)*[^\\\"]*\"
  54CHAR                    L?\'([^\\\']*\\.)*[^\\\']*\'
  55
  56MC_TOKEN                ([~%^&*+=|<>/-]=)|(&&)|("||")|(->)|(<<)|(>>)
  57
  58/* We don't do multiple input files.  */
  59%option noyywrap
  60
  61%option noinput
  62
  63%%
  64
  65
  66 /* Keep track of our location in the original source files.  */
  67^#[ \t]+{INT}[ \t]+\"[^\"\n]+\".*\n     return FILENAME;
  68^#.*\n                                  cur_line++;
  69\n                                      cur_line++;
  70
  71 /* Ignore all other whitespace.  */
  72[ \t\f\v\r]+                            ;
  73
  74
  75{STRING}                                return STRING;
  76{CHAR}                                  return CHAR;
  77{IDENT}                                 return IDENT;
  78
  79 /* The Pedant requires that the other C multi-character tokens be
  80    recognized as tokens.  We don't actually use them since we don't
  81    parse expressions, but we do want whitespace to be arranged
  82    around them properly.  */
  83{MC_TOKEN}                              return OTHER;
  84{INT}                                   return INT;
  85{REAL}                                  return REAL;
  86
  87"..."                                   return DOTS;
  88
  89 /* All other tokens are single characters.  */
  90.                                       return yytext[0];
  91
  92
  93%%
  94
  95/* Bring in the keyword recognizer.  */
  96
  97#include "keywords.hash.c"
  98
  99
 100/* Macros to append to our phrase collection list.  */
 101
 102/*
 103 * We mark any token, that that equals to a known enumerator, as
 104 * SYM_ENUM_CONST. The parser will change this for struct and union tags later,
 105 * the only problem is struct and union members:
 106 *    enum e { a, b }; struct s { int a, b; }
 107 * but in this case, the only effect will be, that the ABI checksums become
 108 * more volatile, which is acceptable. Also, such collisions are quite rare,
 109 * so far it was only observed in include/linux/telephony.h.
 110 */
 111#define _APP(T,L)       do {                                               \
 112                          cur_node = next_node;                            \
 113                          next_node = xmalloc(sizeof(*next_node));         \
 114                          next_node->next = cur_node;                      \
 115                          cur_node->string = memcpy(xmalloc(L+1), T, L+1); \
 116                          cur_node->tag =                                  \
 117                            find_symbol(cur_node->string, SYM_ENUM_CONST, 1)?\
 118                            SYM_ENUM_CONST : SYM_NORMAL ;                  \
 119                          cur_node->in_source_file = in_source_file;       \
 120                        } while (0)
 121
 122#define APP             _APP(yytext, yyleng)
 123
 124
 125/* The second stage lexer.  Here we incorporate knowledge of the state
 126   of the parser to tailor the tokens that are returned.  */
 127
 128int
 129yylex(void)
 130{
 131  static enum {
 132    ST_NOTSTARTED, ST_NORMAL, ST_ATTRIBUTE, ST_ASM, ST_BRACKET, ST_BRACE,
 133    ST_EXPRESSION, ST_TABLE_1, ST_TABLE_2, ST_TABLE_3, ST_TABLE_4,
 134    ST_TABLE_5, ST_TABLE_6
 135  } lexstate = ST_NOTSTARTED;
 136
 137  static int suppress_type_lookup, dont_want_brace_phrase;
 138  static struct string_list *next_node;
 139
 140  int token, count = 0;
 141  struct string_list *cur_node;
 142
 143  if (lexstate == ST_NOTSTARTED)
 144    {
 145      next_node = xmalloc(sizeof(*next_node));
 146      next_node->next = NULL;
 147      lexstate = ST_NORMAL;
 148    }
 149
 150repeat:
 151  token = yylex1();
 152
 153  if (token == 0)
 154    return 0;
 155  else if (token == FILENAME)
 156    {
 157      char *file, *e;
 158
 159      /* Save the filename and line number for later error messages.  */
 160
 161      if (cur_filename)
 162        free(cur_filename);
 163
 164      file = strchr(yytext, '\"')+1;
 165      e = strchr(file, '\"');
 166      *e = '\0';
 167      cur_filename = memcpy(xmalloc(e-file+1), file, e-file+1);
 168      cur_line = atoi(yytext+2);
 169
 170      if (!source_file) {
 171        source_file = xstrdup(cur_filename);
 172        in_source_file = 1;
 172        in_source_(   em xstrdup(cur_f,   if (!source(tokeile = 1;
 165    }
 136
 167 148    }
 169
  8switch/a>  if (lilename)
  81<}epts/genksyms/lex.l#L170" id="L1705lex.l#L821" id="L82" class="line" 1name=1L82">  82repeat:
 172 }epts/genksyms/lex.l#L170" id="L1705lx.l#L165"" id="L85" class="line" 1name=1815"> 115 n thsretur>repeat:
 116   APPile = 1;
 117   }epts/genksyms/lex.l#L170" id="L1705lex.l#L18"  id="L18" class="line" naame=1818"> 118     const41  resthe k*rce_fs"seanly o_the    _APP(yytext, ile = 1;
 119     >   rilename)
 120       }epts/genksyms/lex.l#L170" id="L1705lex.l#L911" id="L91" class="line" 1name=1910"> 120       deswitch/ase ifce_rur_node ifilename)
 112           }epts/genksyms/lex.l#L170" id="L1705lex.l#L831" id="L93" class="line" 1name=1913"> 113           n thsAL, ST_AT_KEYW>repeat:
 114             >      lexstatAL, ST_ATile = 1;
 115             token, count = 0;
 116             goto 150 117           n thsASM_KEYW>repeat:
 118             >      lexstatASMile = 1;
 119             token, count = 0;
 120             goto 150 101
 112           n thstaRUCT_KEYW>repeat:
 113           n thsUNION_KEYW>repeat:
 114           n ths   SYKEYW>repeat:
 115             ookup, dont_want_brace, c3ile = 1;
 116             ic int suppress_type, c2ile = 1;
 117             goto finiile = 1;
 158
 119           n ths XPORT_SYMBOLYKEYW>repeat:
 120               goto finiile = 1;
 120       de8    }
 112       /a>    }
 113     >     c int suppress_typeilename)
 114       a>%{
 115         >          find_  _APP(yONSTTYPEDEFM_COilename)
 116           se ifce_TYPEile = 1;
 117       /a>    }
 118   /a>    }
 119   breakile = 1;
 160
 120 n ths'['>repeat:
 112   APPile = 1;
 113   >      lexstatSM, ST_ile = 1;
 114   token, cfile = 1;
 115   goto 150 136
 120 n ths'{'>repeat:
 112   APPile = 1;
 119   >   ookup, dont_want_braceilename)
 120     breakile = 1;
 113   >      lexstatSM, Eile = 1;
 114   token, cfile = 1;
 115   goto 150 124
 115 n ths'='> n ths':'>repeat:
 116   APPile = 1;
 113   >      lexstat    ST_EXPile = 1;
 119   breakile = 1;
 139
 115 n thsretu>repeat:
 113 defaula>repeat:
 112   APPile = 1;
 119   breakile = 1;
 114 /a>    }
 145 136
 147repeat:
 119 119 115 a>%{
 120 n ths'('>repeat:
 112   ++tokenile = 1;
 115   goto 150 120 n ths')'>repeat:
 119   >   --token, token == 0)
 116     a>%{
 117       >      lexstate = ST_NORMAL;
 118       se ifce_AL, ST_AT_PHRASEile = 1;
 119       breakile = 1;
 120     /a>    }
 115   goto 150 162 defaula>repeat:
 115   goto 150 114 /a>    }
 145 136
 147repeat:
 119 119 115 a>%{
 120 n ths'('>repeat:
 112   ++tokenile = 1;
 115   goto 150 120 n ths')'>repeat:
 119   >   --token, token == 0)
 116     a>%{
 117       >      lexstate = ST_NORMAL;
 118       se ifce_ASM_PHRASEile = 1;
 119       breakile = 1;
 120     /a>    }
 115   goto 150 162 defaula>repeat:
 115   goto 150 114 /a>    }
 145  86
 147repeat:
 119 119 115 a>%{
 120 n ths'['>repeat:
 112   ++tokenile = 1;
 113   goto 150 120 n ths']'>repeat:
 115   >   --token, token == 0)
 116     a>%{
 117       >      lexstate = ST_NORMAL;
 118       se ifce_SM, ST__PHRASEile = 1;
 119       breakile = 1;
 120     a>%}
 115   goto 150 162 defaula>repeat:
 113   goto 150 114 /a>    }
 145  86
 147repeat:
 119 119 115 a>%{
 120 n ths'{'>repeat:
 112   ++tokenile = 1;
 113   goto 150 120 n ths'}'>repeat:
 115   >   --token, token == 0)
 116     a>%{
 117       >      lexstate = ST_NORMAL;
 118       se ifce_SM, T_PHRASEile = 1;
 119       breakile = 1;
 120     /a>    }
 115   goto 150 162 defaula>repeat:
 113   goto 150 114 /a>    }
 145 136
 147repeat:
 112 119 a>%{
 115 n ths'('> n ths'['> n ths'{'>repeat:
 113   ++tokenile = 1;
 114   APPile = 1;
 115   goto 150 120 n ths'}'>repeat:
 115   /*, whbut i* Sa"L3tame anof a a kno de="Lrour l?stage.  */
 116   >    oken, token == 0)
 113   > a>%{
 119   >   /*,Put bKeeptailor th.  Hjus  read so's.  Hca a     so again>%{
 119          af forregis fo>tail parse exp.ssages.  */
 120       uion ase ifiile = 1;
  41
 112       >      lexstate = ST_NORMAL;
 119       se ifce_    ST_EXP_PHRASEile = 1;
 114       breakile = 1;
 115     /a>    }
 115   /*,FALLTHRUsages.  */
 120 n ths')'> n ths']'>repeat:
 119   --tokenile = 1;
 114   APPile = 1;
 115   goto 150 120 n ths','> n ths';'>repeat:
 112   >    oken, token == 0)
 115   > a>%{
 114       /*,Put bKeeptailor th.  Hjus  read so's.  Hca a     so again>%{
 119          af forregis fo>tail parse exp.ssages.  */
 116       uion ase ifiile = 1;
  57
 118       >      lexstate = ST_NORMAL;
 119       se ifce_    ST_EXP_PHRASEile = 1;
 120       breakile = 1;
 115     /a>    }
 114   APPile = 1;
 115   goto 150 114 defaula>repeat:
 114   APPile = 1;
 115   goto 150 120 /a>    }
 119 169
 115repeat:
 120 152
 115repeat:
 120 119 a>%{
 116   se ifce_   ORT_SYMBOLYKEYWile = 1;
 117   >      lexstat    ST_ile = 1;
 118   APPile = 1;
 119   breakile = 1;
 120 /a>    }
 115      lexstat    ST6ile = 1;
 162 163
 114repeat:
 145 116 a>%{
 120 n ths'{'> n ths'['> n ths'('>repeat:
 118   ++tokenile = 1;
 119   breakile = 1;
 115 n ths'}'> n ths']'> n ths')'>repeat:
 120   --tokenile = 1;
 112   breakile = 1;
 113 n ths','>le = 1;
 114   >    oken, token == 0)
 115     >      lexstat    ST2ile = 1;
 116   breakile = 1;
 117 }ile = 1;
 118  99
 115le = 1;
 120 152
 115le = 1;
 120 115 >      lexstate = ST_NORMAL;
 116  57
 119le = 1;
 119 115 a>%{
 120 n ths','>le = 1;
 112   se ifce_';'ile = 1;
 113   >      lexstat    ST2ile = 1;
 114   APPile = 1;
 115   breakile = 1;
 116 defaula>repeat:
 117   APPile = 1;
 118   breakile = 1;
 119 /a>    }
 120 121
 162repeat:
 113 114    }
 fini>repeat:
 136
 14  elic int suppress_type,r_nooken == 0)
 112<--ic int suppress_typefile+1);
 11>   ookup, dont_want_brace,r_nooken == 0)
 115<--ookup, dont_want_brace_phrase;
 121
 11yylvalce_&>      next_node-&_phrase;
 163
 12/a>    se if_phrase;
 /a>    }
 


originalcLXR softws thby;tail> } LXR community6"> ,hbut iexperimentalcver exphby;> } lxr@claux.no6"> .
lxr.claux.no kindly hostedhby;> } Redpill Llaino AS6"> ,hinovidernof Llaux consula>lenaoperour ls anlyices aince=1915.