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