xref: /OpenGrok/opengrok-indexer/src/main/jflex/analysis/c/C.lexh (revision d219b4cea555a12b602d2d5518daa22134ad4879)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * See LICENSE.txt included in this distribution for the specific
9 * language governing permissions and limitations under the License.
10 *
11 * When distributing Covered Code, include this CDDL HEADER in each
12 * file and include the License file at LICENSE.txt.
13 * If applicable, add the following below this CDDL HEADER, with the
14 * fields enclosed by brackets "[]" replaced with your own identifying
15 * information: Portions Copyright [yyyy] [name of copyright owner]
16 *
17 * CDDL HEADER END
18 */
19
20/*
21 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
22 * Portions Copyright (c) 2017-2018, Chris Fraire <cfraire@me.com>.
23 *
24 * Copyright (c) 2018 cppreference.com
25 * http://en.cppreference.com/w/Cppreference:FAQ
26 * "You can use this site in almost any way you like, including mirroring,
27 * copying, translating, etc. All we would ask is to provide link back to
28 * cppreference.com so that people know where to get the most up-to-date
29 * content."
30 */
31
32Identifier = [a-zA-Z_] [a-zA-Z0-9_]*
33
34/*
35 * An integer constant is a non-lvalue expression of the form
36 *
37 * decimal-constant integer-suffix(optional)	(1)
38 * octal-constant integer-suffix(optional)	(2)
39 * hex-constant integer-suffix(optional)	(3)
40 * where
41 *
42 * decimal-constant is a non-zero decimal digit (1, 2, 3, 4, 5, 6, 7, 8, 9),
43 * followed by zero or more decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
44 *
45 * octal-constant is the digit zero (0) followed by zero or more octal digits
46 * (0, 1, 2, 3, 4, 5, 6, 7)
47 *
48 * hex-constant is the character sequence 0x or the character sequence 0X
49 * followed by one or more hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a,
50 * A, b, B, c, C, d, D, e, E, f, F)
51 *
52 * integer-suffix, if provided, may contain one or both of the following (if
53 * both are provided, they may appear in any order:
54 *
55 * unsigned-suffix (the character u or the character U)
56 *
57 * long-suffix (the character l or the character L) or the long-long-suffix
58 * (the character sequence ll or the character sequence LL) (since C99)
59 */
60integer_literal = ({decimal_literal} | {octal_literal} | {hex_literal})
61decimal_literal = [1-9] [0-9]* {integer_suffix}?
62octal_literal =   0[0-7]+ {integer_suffix}?
63hex_literal =     0[xX][0-9a-fA-F]+ {integer_suffix}?
64
65integer_suffix = ({unsigned_suffix} | {long_suffix})+
66unsigned_suffix = [uU]
67long_suffix = ([lL] | "ll" | "LL")
68
69/*
70 * A floating constant is a non-lvalue expression having the form:
71 *
72 * significand exponent(optional) suffix(optional)
73 * Where the significand has the form
74 *
75 * whole-number(optional) .(optional) fraction(optional)
76 * The exponent has the form
77 *
78 * e | E exponent-sign(optional) digit-sequence	(1)
79 * p | P exponent-sign(optional) digit-sequence	(2)	(since C99)
80 * 1) The exponent syntax for a decimal floating-point constant
81 * 2) The exponent syntax for hexadecimal floating-point constant
82 *
83 * (The C++ standard had better break-down of "significand" so the following
84 * is taken from it, without support for apostrophe delimiters.)
85 */
86fp_literal = ({fp1} | {fp2} | {fp3} | {fp4} | {fp5} | {fp6}) {fp_suffix}?
87fp1 = {digit_seq} {fp_exp}
88fp2 = {digit_seq} \. {fp_exp}?
89fp3 = (\. {digit_seq} | {digit_seq} \. {digit_seq}) {fp_exp}?
90fp4 = 0[xX] {hex_digit_seq} {fp_exp}
91fp5 = 0[xX] {hex_digit_seq} \. {fp_exp}?
92fp6 = 0[xX] (\. {hex_digit_seq} | {hex_digit_seq} \. {hex_digit_seq}) {fp_exp}?
93
94digit_seq = [0-9]+
95hex_digit_seq = [0-9a-fA-F]+
96fp_exp = [eEpP][\+\-]?{digit_seq}
97fp_suffix = [fFlLdD]	// [dD] is only present for OpenGrok compatibility
98
99Number = [\+\-]? ({integer_literal} | {fp_literal})
100