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) 2008, 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 literal is a primary expression of the form 36 * 37 * decimal-literal integer-suffix(optional) (1) 38 * octal-literal integer-suffix(optional) (2) 39 * hex-literal integer-suffix(optional) (3) 40 * binary-literal integer-suffix(optional) (4) (since C++14) 41 * where 42 * 43 * decimal-literal is a non-zero decimal digit (1, 2, 3, 4, 5, 6, 7, 8, 9), 44 * followed by zero or more decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) 45 * 46 * octal-literal is the digit zero (0) followed by zero or more octal digits 47 * (0, 1, 2, 3, 4, 5, 6, 7) 48 * 49 * hex-literal is the character sequence 0x or the character sequence 0X 50 * followed by one or more hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, 51 * A, b, B, c, C, d, D, e, E, f, F) 52 * 53 * binary-literal is the character sequence 0b or the character sequence 0B 54 * followed by one or more binary digits (0, 1) 55 * 56 * integer-suffix, if provided, may contain one or both of the following (if 57 * both are provided, they may appear in any order: 58 * 59 * unsigned-suffix (the character u or the character U) 60 * 61 * long-suffix (the character l or the character L) or the long-long-suffix 62 * (the character sequence ll or the character sequence LL) (since C++11) 63 * 64 * Optional single quotes(') may be inserted between the digits as a separator. 65 * They are ignored by the compiler. 66 */ 67integer_literal = ({decimal_literal} | {octal_literal} | {hex_literal} | 68 {binary_literal}) 69decimal_literal = [1-9]([0-9\']+[0-9] | [0-9]*) {integer_suffix}? 70octal_literal = (0 | 0[0-7]([0-7\']+[0-7] | [0-7]*)) {integer_suffix}? 71hex_literal = 0[xX][0-9a-fA-F]([0-9a-fA-F\']+[0-9a-fA-F] | 72 [0-9a-fA-F]*) {integer_suffix}? 73binary_literal = 0[bB][01]([01\']+[01] | [01]*) {integer_suffix}? 74 75integer_suffix = ({unsigned_suffix} | {long_suffix})+ 76unsigned_suffix = [uU] 77long_suffix = ([lL] | "ll" | "LL") 78 79/* 80 * Floating point literal syntax 81 * 82 * significand exponent(optional) suffix(optional) 83 * Where the significand has one of the following forms 84 * 85 * digit-sequence (1) 86 * digit-sequence . (2) 87 * digit-sequence(optional) . digit-sequence (3) 88 * 0x | 0X hex-digit-sequence (4) (since C++17) 89 * 0x | 0X hex-digit-sequence . (5) (since C++17) 90 * 0x | 0X hex-digit-sequence(optional) . hex-digit-sequence (6) (since C++17) 91 * 92 * 1) digit-sequence representing a whole number without a decimal separator, 93 * in this case the exponent is not optional: 1e10, 1e-5L 94 * 95 * 2) digit-sequence representing a whole number with a decimal separator, in 96 * this case the exponent is optional: 1., 1.e-2 97 * 98 * 3) digit-sequence representing a fractional number. The exponent is 99 * optional: 3.14, .1f, 0.1e-1L 100 * 101 * 4) Hexadecimal digit-sequence representing a whole number without a radix 102 * separator. The exponent is never optional for hexadecimal floating-point 103 * literals: 0x1ffp10, 0X0p-1 104 * 105 * 5) Hexadecimal digit-sequence representing a whole number with a radix 106 * separator. The exponent is never optional for hexadecimal floating-point 107 * literals: 0x1.p0, 0xf.p-1 108 * 109 * 6) Hexadecimal digit-sequence representing a fractional number with a radix 110 * separator. The exponent is never optional for hexadecimal floating-point 111 * literals: 0x0.123p-1, 0xa.bp10l 112 * 113 * The exponent has the form 114 * e | E exponent-sign(optional) digit-sequence (1) 115 * p | P exponent-sign(optional) digit-sequence (2) (since C++17) 116 * 117 * 1) The exponent syntax for a decimal floating-point literal 118 * 119 * 2) The exponent syntax for hexadecimal floating-point literal 120 * exponent-sign, if present, is either + or - 121 * 122 * suffix, if present, is one of f, F, l, or L. The suffix determines the type 123 * of the floating-point literal: 124 * 125 * (no suffix) defines double 126 * f F defines float 127 * l L defines long double 128 * Optional single quotes(') can be inserted between the digits as a separator, 129 * they are ignored when compiling. 130 */ 131fp_literal = ({fp1} | {fp2} | {fp3} | {fp4} | {fp5} | {fp6}) {fp_suffix}? 132fp1 = {digit_seq} {fp_exp} 133fp2 = {digit_seq} \. {fp_exp}? 134fp3 = (\. {digit_seq} | {digit_seq} \. {digit_seq}) {fp_exp}? 135fp4 = 0[xX] {hex_digit_seq} {fp_exp} 136fp5 = 0[xX] {hex_digit_seq} \. {fp_exp}? 137fp6 = 0[xX] (\. {hex_digit_seq} | {hex_digit_seq} \. {hex_digit_seq}) {fp_exp}? 138 139digit_seq = [0-9] ([0-9\']+[0-9] | [0-9]*) 140hex_digit_seq = [0-9a-fA-F] ([0-9a-fA-F\']+[0-9a-fA-F] | [0-9a-fA-F]*) 141fp_exp = [eEpP][\+\-]?{digit_seq} 142fp_suffix = [fFlLdD] // [dD] is only present for OpenGrok compatibility 143 144Number = [\+\-]? ({integer_literal} | {fp_literal}) 145