Home | History | Annotate | Line # | Download | only in lint1
scan.l revision 1.142
      1 %{
      2 /* $NetBSD: scan.l,v 1.142 2024/05/12 08:48:36 rillig Exp $ */
      3 
      4 /*
      5  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
      6  * Copyright (c) 1994, 1995 Jochen Pohl
      7  * All Rights Reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by Jochen Pohl for
     20  *	The NetBSD Project.
     21  * 4. The name of the author may not be used to endorse or promote products
     22  *    derived from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 #if defined(__RCSID)
     38 __RCSID("$NetBSD: scan.l,v 1.142 2024/05/12 08:48:36 rillig Exp $");
     39 #endif
     40 
     41 #include "lint1.h"
     42 #include "cgram.h"
     43 
     44 %}
     45 
     46 
     47 HEX	[0-9A-Fa-f]
     48 EXP	([eE][+-]?[0-9]+)
     49 PEXP	(p[+-]?[0-9A-Fa-f]+)
     50 FSUF	([fFlL]?[i]?)
     51 
     52 %pointer
     53 %option nounput
     54 
     55 %%
     56 
     57 [_A-Za-z][_A-Za-z0-9]*		return lex_name(yytext, yyleng);
     58 0[bB][01]+[lLuU]*		return lex_integer_constant(yytext, yyleng, 2);
     59 0[0-7]*[lLuU]*			return lex_integer_constant(yytext, yyleng, 8);
     60 [1-9][0-9]*[lLuU]*		return lex_integer_constant(yytext, yyleng, 10);
     61 0[xX]{HEX}+[lLuU]*		return lex_integer_constant(yytext, yyleng, 16);
     62 [0-9]+\.[0-9]*{EXP}?{FSUF}	|
     63 [0-9]+{EXP}{FSUF}		|
     64 0[xX]{HEX}+\.{HEX}*{PEXP}{FSUF}	|
     65 0[xX]{HEX}+{PEXP}{FSUF}		|
     66 \.[0-9]+{EXP}?{FSUF}		return lex_floating_constant(yytext, yyleng);
     67 "="				return T_ASSIGN;
     68 "*="				return lex_operator(T_OPASSIGN, MULASS);
     69 "/="				return lex_operator(T_OPASSIGN, DIVASS);
     70 "%="				return lex_operator(T_OPASSIGN, MODASS);
     71 "+="				return lex_operator(T_OPASSIGN, ADDASS);
     72 "-="				return lex_operator(T_OPASSIGN, SUBASS);
     73 "<<="				return lex_operator(T_OPASSIGN, SHLASS);
     74 ">>="				return lex_operator(T_OPASSIGN, SHRASS);
     75 "&="				return lex_operator(T_OPASSIGN, ANDASS);
     76 "^="				return lex_operator(T_OPASSIGN, XORASS);
     77 "|="				return lex_operator(T_OPASSIGN, ORASS);
     78 "||"				return T_LOGOR;
     79 "&&"				return T_LOGAND;
     80 "|"				return T_BITOR;
     81 "&"				return T_AMPER;
     82 "^"				return T_BITXOR;
     83 "=="				return lex_operator(T_EQUALITY, EQ);
     84 "!="				return lex_operator(T_EQUALITY, NE);
     85 "<"				return lex_operator(T_RELATIONAL, LT);
     86 ">"				return lex_operator(T_RELATIONAL, GT);
     87 "<="				return lex_operator(T_RELATIONAL, LE);
     88 ">="				return lex_operator(T_RELATIONAL, GE);
     89 "<<"				return lex_operator(T_SHIFT, SHL);
     90 ">>"				return lex_operator(T_SHIFT, SHR);
     91 "++"				return yylval.y_inc = true, T_INCDEC;
     92 "--"				return yylval.y_inc = false, T_INCDEC;
     93 "->"				return T_ARROW;
     94 "."				return T_POINT;
     95 "+"				return lex_operator(T_ADDITIVE, PLUS);
     96 "-"				return lex_operator(T_ADDITIVE, MINUS);
     97 "*"				return T_ASTERISK;
     98 "/"				return lex_operator(T_MULTIPLICATIVE, DIV);
     99 "%"				return lex_operator(T_MULTIPLICATIVE, MOD);
    100 "!"				return T_LOGNOT;
    101 "~"				return T_COMPLEMENT;
    102 "\""				return lex_string();
    103 "L\""				return lex_wide_string();
    104 ";"				return T_SEMI;
    105 "{"				return T_LBRACE;
    106 "}"				return T_RBRACE;
    107 ","				return T_COMMA;
    108 ":"				return T_COLON;
    109 "?"				return T_QUEST;
    110 "["				return T_LBRACK;
    111 "]"				return T_RBRACK;
    112 "("				return T_LPAREN;
    113 ")"				return T_RPAREN;
    114 "..."				return T_ELLIPSIS;
    115 "::"				return T_DCOLON;
    116 "'"				return lex_character_constant();
    117 "L'"				return lex_wide_character_constant();
    118 ^#.*$				lex_directive(yytext);
    119 \n				lex_next_line();
    120 \t|" "|\f|\v			;
    121 "/*"				lex_comment();
    122 "//"				lex_slash_slash_comment();
    123 .				lex_unknown_character(yytext[0]);
    124 
    125 %%
    126 
    127 /*
    128  * In the above list of regular expressions, the tokens for character
    129  * constants, string literals and comments are incomplete; they only match
    130  * a prefix.  The remainder of these tokens is scanned by reading bytes
    131  * directly from the input stream.
    132  */
    133 int
    134 lex_input(void)
    135 {
    136 	return input();
    137 }
    138