xref: /netbsd-src/usr.bin/xlint/lint1/scan.l (revision 4f645668ed707e1f969c546666f8c8e45e6f8888)
1 %{
2 /* $NetBSD: scan.l,v 1.136 2022/05/20 21:18:55 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.136 2022/05/20 21:18:55 rillig Exp $");
39 #endif
40 
41 #include "lint1.h"
42 #include "cgram.h"
43 
44 %}
45 
46 
47 L	[_A-Za-z]
48 D	[0-9]
49 NZD	[1-9]
50 BD	[0-1]
51 OD	[0-7]
52 HD	[0-9A-Fa-f]
53 EX	([eE][+-]?[0-9]+)
54 HX	(p[+-]?[0-9A-Fa-f]+)
55 TL	([fFlL]?[i]?)
56 
57 %option nounput
58 
59 %%
60 
61 {L}({L}|{D})*			return lex_name(yytext, yyleng);
62 0[bB]{BD}+[lLuU]*		return lex_integer_constant(yytext, yyleng, 2);
63 0{OD}*[lLuU]*			return lex_integer_constant(yytext, yyleng, 8);
64 {NZD}{D}*[lLuU]*		return lex_integer_constant(yytext, yyleng, 10);
65 0[xX]{HD}+[lLuU]*		return lex_integer_constant(yytext, yyleng, 16);
66 {D}+\.{D}*{EX}?{TL}		|
67 {D}+{EX}{TL}			|
68 0[xX]{HD}+\.{HD}*{HX}{TL}	|
69 0[xX]{HD}+{HX}{TL}		|
70 \.{D}+{EX}?{TL}			return lex_floating_constant(yytext, yyleng);
71 "="				return T_ASSIGN;
72 "*="				return lex_operator(T_OPASSIGN, MULASS);
73 "/="				return lex_operator(T_OPASSIGN, DIVASS);
74 "%="				return lex_operator(T_OPASSIGN, MODASS);
75 "+="				return lex_operator(T_OPASSIGN, ADDASS);
76 "-="				return lex_operator(T_OPASSIGN, SUBASS);
77 "<<="				return lex_operator(T_OPASSIGN, SHLASS);
78 ">>="				return lex_operator(T_OPASSIGN, SHRASS);
79 "&="				return lex_operator(T_OPASSIGN, ANDASS);
80 "^="				return lex_operator(T_OPASSIGN, XORASS);
81 "|="				return lex_operator(T_OPASSIGN, ORASS);
82 "||"				return T_LOGOR;
83 "&&"				return T_LOGAND;
84 "|"				return T_BITOR;
85 "&"				return T_AMPER;
86 "^"				return T_BITXOR;
87 "=="				return lex_operator(T_EQUALITY, EQ);
88 "!="				return lex_operator(T_EQUALITY, NE);
89 "<"				return lex_operator(T_RELATIONAL, LT);
90 ">"				return lex_operator(T_RELATIONAL, GT);
91 "<="				return lex_operator(T_RELATIONAL, LE);
92 ">="				return lex_operator(T_RELATIONAL, GE);
93 "<<"				return lex_operator(T_SHIFT, SHL);
94 ">>"				return lex_operator(T_SHIFT, SHR);
95 "++"				return lex_operator(T_INCDEC, INC);
96 "--"				return lex_operator(T_INCDEC, DEC);
97 "->"				return T_ARROW;
98 "."				return T_POINT;
99 "+"				return lex_operator(T_ADDITIVE, PLUS);
100 "-"				return lex_operator(T_ADDITIVE, MINUS);
101 "*"				return T_ASTERISK;
102 "/"				return lex_operator(T_MULTIPLICATIVE, DIV);
103 "%"				return lex_operator(T_MULTIPLICATIVE, MOD);
104 "!"				return T_LOGNOT;
105 "~"				return T_COMPLEMENT;
106 "\""				return lex_string();
107 "L\""				return lex_wide_string();
108 ";"				return T_SEMI;
109 "{"				return T_LBRACE;
110 "}"				return T_RBRACE;
111 ","				return T_COMMA;
112 ":"				return T_COLON;
113 "?"				return T_QUEST;
114 "["				return T_LBRACK;
115 "]"				return T_RBRACK;
116 "("				return T_LPAREN;
117 ")"				return T_RPAREN;
118 "..."				return T_ELLIPSIS;
119 "'"				return lex_character_constant();
120 "L'"				return lex_wide_character_constant();
121 ^#.*$				lex_directive(yytext);
122 \n				lex_next_line();
123 \t|" "|\f|\v			;
124 "/*"				lex_comment();
125 "//"				lex_slash_slash_comment();
126 .				lex_unknown_character(yytext[0]);
127 
128 %%
129 
130 int
131 lex_input(void)
132 {
133 	return input();
134 }
135