scan.l revision 1.139 1 1.1 cgd %{
2 1.139 rillig /* $NetBSD: scan.l,v 1.139 2023/07/13 08:40:38 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.139 rillig * This product includes software developed by Jochen Pohl for
20 1.139 rillig * 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.139 rillig __RCSID("$NetBSD: scan.l,v 1.139 2023/07/13 08:40:38 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.138 rillig HEX [0-9A-Fa-f]
48 1.138 rillig EXP ([eE][+-]?[0-9]+)
49 1.138 rillig PEXP (p[+-]?[0-9A-Fa-f]+)
50 1.138 rillig FSUF ([fFlL]?[i]?)
51 1.1 cgd
52 1.46 christos %option nounput
53 1.46 christos
54 1.1 cgd %%
55 1.1 cgd
56 1.138 rillig [_A-Za-z][_A-Za-z0-9]* return lex_name(yytext, yyleng);
57 1.138 rillig 0[bB][01]+[lLuU]* return lex_integer_constant(yytext, yyleng, 2);
58 1.138 rillig 0[0-7]*[lLuU]* return lex_integer_constant(yytext, yyleng, 8);
59 1.138 rillig [1-9][0-9]*[lLuU]* return lex_integer_constant(yytext, yyleng, 10);
60 1.138 rillig 0[xX]{HEX}+[lLuU]* return lex_integer_constant(yytext, yyleng, 16);
61 1.138 rillig [0-9]+\.[0-9]*{EXP}?{FSUF} |
62 1.138 rillig [0-9]+{EXP}{FSUF} |
63 1.138 rillig 0[xX]{HEX}+\.{HEX}*{PEXP}{FSUF} |
64 1.138 rillig 0[xX]{HEX}+{PEXP}{FSUF} |
65 1.138 rillig \.[0-9]+{EXP}?{FSUF} return lex_floating_constant(yytext, yyleng);
66 1.132 rillig "=" return T_ASSIGN;
67 1.130 rillig "*=" return lex_operator(T_OPASSIGN, MULASS);
68 1.130 rillig "/=" return lex_operator(T_OPASSIGN, DIVASS);
69 1.130 rillig "%=" return lex_operator(T_OPASSIGN, MODASS);
70 1.130 rillig "+=" return lex_operator(T_OPASSIGN, ADDASS);
71 1.130 rillig "-=" return lex_operator(T_OPASSIGN, SUBASS);
72 1.130 rillig "<<=" return lex_operator(T_OPASSIGN, SHLASS);
73 1.130 rillig ">>=" return lex_operator(T_OPASSIGN, SHRASS);
74 1.130 rillig "&=" return lex_operator(T_OPASSIGN, ANDASS);
75 1.130 rillig "^=" return lex_operator(T_OPASSIGN, XORASS);
76 1.130 rillig "|=" return lex_operator(T_OPASSIGN, ORASS);
77 1.132 rillig "||" return T_LOGOR;
78 1.132 rillig "&&" return T_LOGAND;
79 1.132 rillig "|" return T_BITOR;
80 1.132 rillig "&" return T_AMPER;
81 1.133 rillig "^" return T_BITXOR;
82 1.130 rillig "==" return lex_operator(T_EQUALITY, EQ);
83 1.130 rillig "!=" return lex_operator(T_EQUALITY, NE);
84 1.130 rillig "<" return lex_operator(T_RELATIONAL, LT);
85 1.130 rillig ">" return lex_operator(T_RELATIONAL, GT);
86 1.130 rillig "<=" return lex_operator(T_RELATIONAL, LE);
87 1.130 rillig ">=" return lex_operator(T_RELATIONAL, GE);
88 1.130 rillig "<<" return lex_operator(T_SHIFT, SHL);
89 1.130 rillig ">>" return lex_operator(T_SHIFT, SHR);
90 1.130 rillig "++" return lex_operator(T_INCDEC, INC);
91 1.130 rillig "--" return lex_operator(T_INCDEC, DEC);
92 1.134 rillig "->" return T_ARROW;
93 1.134 rillig "." return T_POINT;
94 1.130 rillig "+" return lex_operator(T_ADDITIVE, PLUS);
95 1.130 rillig "-" return lex_operator(T_ADDITIVE, MINUS);
96 1.132 rillig "*" return T_ASTERISK;
97 1.130 rillig "/" return lex_operator(T_MULTIPLICATIVE, DIV);
98 1.130 rillig "%" return lex_operator(T_MULTIPLICATIVE, MOD);
99 1.135 rillig "!" return T_LOGNOT;
100 1.135 rillig "~" return T_COMPLEMENT;
101 1.130 rillig "\"" return lex_string();
102 1.131 rillig "L\"" return lex_wide_string();
103 1.97 rillig ";" return T_SEMI;
104 1.97 rillig "{" return T_LBRACE;
105 1.97 rillig "}" return T_RBRACE;
106 1.97 rillig "," return T_COMMA;
107 1.97 rillig ":" return T_COLON;
108 1.97 rillig "?" return T_QUEST;
109 1.97 rillig "[" return T_LBRACK;
110 1.97 rillig "]" return T_RBRACK;
111 1.108 rillig "(" return T_LPAREN;
112 1.108 rillig ")" return T_RPAREN;
113 1.123 rillig "..." return T_ELLIPSIS;
114 1.131 rillig "'" return lex_character_constant();
115 1.131 rillig "L'" return lex_wide_character_constant();
116 1.130 rillig ^#.*$ lex_directive(yytext);
117 1.131 rillig \n lex_next_line();
118 1.1 cgd \t|" "|\f|\v ;
119 1.130 rillig "/*" lex_comment();
120 1.131 rillig "//" lex_slash_slash_comment();
121 1.131 rillig . lex_unknown_character(yytext[0]);
122 1.1 cgd
123 1.1 cgd %%
124 1.1 cgd
125 1.137 rillig /*
126 1.137 rillig * In the above list of regular expressions, the tokens for character
127 1.137 rillig * constants, string literals and comments are incomplete; they only match
128 1.137 rillig * a prefix. The remainder of these tokens is scanned by reading bytes
129 1.137 rillig * directly from the input stream.
130 1.137 rillig */
131 1.1 cgd int
132 1.130 rillig lex_input(void)
133 1.6 jpo {
134 1.130 rillig return input();
135 1.1 cgd }
136