/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * See LICENSE.txt included in this distribution for the specific * language governing permissions and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at LICENSE.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. * Portions Copyright (c) 2017-2018, Chris Fraire . * * Copyright (c) 2018 cppreference.com * http://en.cppreference.com/w/Cppreference:FAQ * "You can use this site in almost any way you like, including mirroring, * copying, translating, etc. All we would ask is to provide link back to * cppreference.com so that people know where to get the most up-to-date * content." */ Identifier = [a-zA-Z_] [a-zA-Z0-9_]* /* * An integer literal is a primary expression of the form * * decimal-literal integer-suffix(optional) (1) * octal-literal integer-suffix(optional) (2) * hex-literal integer-suffix(optional) (3) * binary-literal integer-suffix(optional) (4) (since C++14) * where * * decimal-literal is a non-zero decimal digit (1, 2, 3, 4, 5, 6, 7, 8, 9), * followed by zero or more decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) * * octal-literal is the digit zero (0) followed by zero or more octal digits * (0, 1, 2, 3, 4, 5, 6, 7) * * hex-literal is the character sequence 0x or the character sequence 0X * followed by one or more hexadecimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, * A, b, B, c, C, d, D, e, E, f, F) * * binary-literal is the character sequence 0b or the character sequence 0B * followed by one or more binary digits (0, 1) * * integer-suffix, if provided, may contain one or both of the following (if * both are provided, they may appear in any order: * * unsigned-suffix (the character u or the character U) * * long-suffix (the character l or the character L) or the long-long-suffix * (the character sequence ll or the character sequence LL) (since C++11) * * Optional single quotes(') may be inserted between the digits as a separator. * They are ignored by the compiler. */ integer_literal = ({decimal_literal} | {octal_literal} | {hex_literal} | {binary_literal}) decimal_literal = [1-9]([0-9\']+[0-9] | [0-9]*) {integer_suffix}? octal_literal = (0 | 0[0-7]([0-7\']+[0-7] | [0-7]*)) {integer_suffix}? hex_literal = 0[xX][0-9a-fA-F]([0-9a-fA-F\']+[0-9a-fA-F] | [0-9a-fA-F]*) {integer_suffix}? binary_literal = 0[bB][01]([01\']+[01] | [01]*) {integer_suffix}? integer_suffix = ({unsigned_suffix} | {long_suffix})+ unsigned_suffix = [uU] long_suffix = ([lL] | "ll" | "LL") /* * Floating point literal syntax * * significand exponent(optional) suffix(optional) * Where the significand has one of the following forms * * digit-sequence (1) * digit-sequence . (2) * digit-sequence(optional) . digit-sequence (3) * 0x | 0X hex-digit-sequence (4) (since C++17) * 0x | 0X hex-digit-sequence . (5) (since C++17) * 0x | 0X hex-digit-sequence(optional) . hex-digit-sequence (6) (since C++17) * * 1) digit-sequence representing a whole number without a decimal separator, * in this case the exponent is not optional: 1e10, 1e-5L * * 2) digit-sequence representing a whole number with a decimal separator, in * this case the exponent is optional: 1., 1.e-2 * * 3) digit-sequence representing a fractional number. The exponent is * optional: 3.14, .1f, 0.1e-1L * * 4) Hexadecimal digit-sequence representing a whole number without a radix * separator. The exponent is never optional for hexadecimal floating-point * literals: 0x1ffp10, 0X0p-1 * * 5) Hexadecimal digit-sequence representing a whole number with a radix * separator. The exponent is never optional for hexadecimal floating-point * literals: 0x1.p0, 0xf.p-1 * * 6) Hexadecimal digit-sequence representing a fractional number with a radix * separator. The exponent is never optional for hexadecimal floating-point * literals: 0x0.123p-1, 0xa.bp10l * * The exponent has the form * e | E exponent-sign(optional) digit-sequence (1) * p | P exponent-sign(optional) digit-sequence (2) (since C++17) * * 1) The exponent syntax for a decimal floating-point literal * * 2) The exponent syntax for hexadecimal floating-point literal * exponent-sign, if present, is either + or - * * suffix, if present, is one of f, F, l, or L. The suffix determines the type * of the floating-point literal: * * (no suffix) defines double * f F defines float * l L defines long double * Optional single quotes(') can be inserted between the digits as a separator, * they are ignored when compiling. */ fp_literal = ({fp1} | {fp2} | {fp3} | {fp4} | {fp5} | {fp6}) {fp_suffix}? fp1 = {digit_seq} {fp_exp} fp2 = {digit_seq} \. {fp_exp}? fp3 = (\. {digit_seq} | {digit_seq} \. {digit_seq}) {fp_exp}? fp4 = 0[xX] {hex_digit_seq} {fp_exp} fp5 = 0[xX] {hex_digit_seq} \. {fp_exp}? fp6 = 0[xX] (\. {hex_digit_seq} | {hex_digit_seq} \. {hex_digit_seq}) {fp_exp}? digit_seq = [0-9] ([0-9\']+[0-9] | [0-9]*) hex_digit_seq = [0-9a-fA-F] ([0-9a-fA-F\']+[0-9a-fA-F] | [0-9a-fA-F]*) fp_exp = [eEpP][\+\-]?{digit_seq} fp_suffix = [fFlLdD] // [dD] is only present for OpenGrok compatibility Number = [\+\-]? ({integer_literal} | {fp_literal})