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