⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grammar.txt

📁 C Preprocessor,antlr的grammar语言描述,用于学习词法分析,语法分析
💻 TXT
📖 第 1 页 / 共 3 页
字号:
gram

Notes: 

DW 23/04/03
This data was originally obtained from, 
http://www.csci.csusb.edu/dick/C++std/cd2/gram.html

I have converted the original hyphens separating words in names to
underscores and the opt(ional) indicator at the end of names to -opt to aid searching.

As this file is stored in text mode the textual distinction between reserved keywords 
and other words has been lost. The keywords should be listed in any book about C++.

DW 27/09/04
This data has been modified to match the grammar listed in Appendix A of
"The C++ Programming Language" Third Edition by Bjarne Stroustrup
ISBN 0201889544

Deleted or amended lines of the original (old) text are shown within []
brackets. Lines copied from the book are shown as "Book line".

One line was added from "C++ In a Nutshell" First edition, ISBN 059600298X

I would be grateful if anyone could let me know if it needs updating
at wiggjd@bcs.org.uk
  ______________________________________________________________________

  Annex 0 (informative)

  Grammar summary                                                 [gram]

  ______________________________________________________________________

1 This summary of C++ syntax is intended to be an aid to  comprehension.
  It  is  not  an  exact  statement of the language.  In particular, the
  grammar described here accepts a superset  of  valid  C++  constructs.
  Disambiguation rules (_stmt.ambig_, _dcl.spec_, _class.member.lookup_)
  must be applied to distinguish expressions  from  declarations.   Fur-
  ther,  access  control, ambiguity, and type rules must be used to weed
  out syntactically valid but meaningless constructs.

  1.1  Keywords                                               [gram.key]

1 New context_dependent keywords are introduced into a program by  type_
  def  (_dcl.typedef_),  namespace  (_namespace.def_),  class (_class_),
  enumeration (_dcl.enum_), and template (_temp_) declarations.
          typedef_name:
                  identifier
          namespace_name:
                  original_namespace_name
                  namespace_alias
          original_namespace_name:
                  identifier
          namespace_alias:
                  identifier
          class_name:
                  identifier
                  template_id
          enum_name:
                  identifier
          template_name:
                  identifier

  Note that a typedef_name naming a class is also a class_name
  (_class.name_).

  1.2  Lexical conventions                                    [gram.lex]
          hex_quad:
                  hexadecimal_digit hexadecimal_digit hexadecimal_digit hexadecimal_digit
          universal_character_name:
                  \u hex_quad
                  \U hex_quad hex_quad
          preprocessing_token:
                  header_name
                  identifier
                  pp_number
                  character_literal
                  string_literal
                  preprocessing_op_or_punc
                  each non_white_space character that cannot be one of the above
          token:
                  identifier
                  keyword
                  literal
                  operator
                  punctuator
          header_name:
                  <h_char_sequence>
                  "q_char_sequence"
          h_char_sequence:
                  h_char
                  h_char_sequence h_char
          h_char:
                  any member of the source character set except
                          new_line and >
          q_char_sequence:
                  q_char
                  q_char_sequence q_char
          q_char:
                  any member of the source character set except
                          new_line and "
          pp_number:
                  digit
                  . digit
                  pp_number digit
                  pp_number nondigit
                  pp_number e sign
                  pp_number E sign
                  pp_number .
          identifier:
                  nondigit
                  identifier nondigit
                  identifier digit
          nondigit: one of
                  universal_character_name
                  _ a b c d e f g h i j k l m
                    n o p q r s t u v w x y z
                    A B C D E F G H I J K L M
                    N O P Q R S T U V W X Y Z
          digit: one of
                  0 1 2 3 4 5 6 7 8 9

          preprocessing_op_or_punc: one of
          {       }       [       ]       #       ##      (       )
          <:      :>      <%      %>      %:      %:%:    ;       :       ...
          new     delete  ?       ::      .       .*
          +       -       *       /       %       ^       &       |       ~
          !       =       <       >       +=      -=      *=      /=      %=
          ^=      &=      |=      <<      >>      >>=     <<=     ==      !=
          <=      >=      &&      ||      ++      --      ,       ->*     ->
          and     and_eq  bitand  bitor   compl   not     not_eq  or      or_eq
          xor     xor_eq

          literal:
                  integer_literal
                  character_literal
                  floating_literal
                  string_literal
                  boolean_literal
          integer_literal:
                  decimal_literal integer_suffix-opt
                  octal_literal integer_suffix-opt
                  hexadecimal_literal integer_suffix-opt
          decimal_literal:
                  nonzero_digit
                  decimal_literal digit
          octal_literal:
                  0
                  octal_literal octal_digit
          hexadecimal_literal:
                  0x hexadecimal_digit
                  0X hexadecimal_digit
                  hexadecimal_literal hexadecimal_digit
          nonzero_digit: one of
                  1  2  3  4  5  6  7  8  9
          octal_digit: one of
                  0  1  2  3  4  5  6  7
          hexadecimal_digit: one of
                  0  1  2  3  4  5  6  7  8  9
                  a  b  c  d  e  f
                  A  B  C  D  E  F
          integer_suffix:
                  unsigned_suffix long_suffix-opt
                  long_suffix unsigned_suffix-opt
          unsigned_suffix: one of
                  u  U
          long_suffix: one of
                  l  L
          character_literal:
                  'c_char_sequence'
                  L'c_char_sequence'
          c_char_sequence:
                  c_char
                  c_char_sequence c_char
          c_char:
                  any member of the source character set except
                    the single_quote ', backslash \, or new_line character
                  escape_sequence
                  universal_character_name
          escape_sequence:
                  simple_escape_sequence
                  octal_escape_sequence
                  hexadecimal_escape_sequence
          simple_escape_sequence: one of
                  \'  \"  \?  \\
                  \a  \b  \f  \n  \r  \t  \v
          octal_escape_sequence:
                  \ octal_digit
                  \ octal_digit octal_digit
                  \ octal_digit octal_digit octal_digit
          hexadecimal_escape_sequence:
                  \x hexadecimal_digit
                  hexadecimal_escape_sequence hexadecimal_digit
          floating_literal:
                  fractional_constant exponent_part-opt floating_suffix-opt
                  digit_sequence exponent_part floating_suffix-opt
          fractional_constant:
                  digit_sequence-opt . digit_sequence
                  digit_sequence .
          exponent_part:
                  e sign-opt digit_sequence
                  E sign-opt digit_sequence
          sign: one of
                  +  -
          digit_sequence:
                  digit
                  digit_sequence digit
          floating_suffix: one of
                  f  l  F  L
          string_literal:
                  "s_char_sequence-opt"
                  L"s_char_sequence-opt"
          s_char_sequence:
                  s_char
                  s_char_sequence s_char
          s_char:
                  any member of the source character set except
                    the double_quote ", backslash \, or new_line character
                  escape_sequence
                  universal_character_name
          boolean_literal:
                  false
                  true

  1.3  Basic concepts                                       [gram.basic]
          translation_unit:
                  declaration_seq-opt

  1.4  Expressions                                           [gram.expr]
          primary_expression:
                  literal
                  this
                  :: identifier
                  :: operator_function_id
                  :: qualified_id
                  ( expression )
                  id_expression
          id_expression:
                  unqualified_id
                  qualified_id
          unqualified_id:
                  identifier
                  operator_function_id
                  conversion_function_id
                  ~ class_name
                  template_id
          qualified_id:
                  nested_name_specifier template-opt unqualified_id
          nested_name_specifier:
                  class_or_namespace_name :: nested_name_specifier-opt
Book line         class_or_namespace_name :: template nested_name_specifier	// DW See qualified_id above re "template"
          class_or_namespace_name:
                  class_name
                  namespace_name
          postfix_expression:
                  primary_expression
                  postfix_expression [ expression ]
                  postfix_expression ( expression_list-opt )
                  simple_type_specifier ( expression_list-opt )
Book line         typename ::-opt nested_name_specifier identifier       
                    ( expression_list-opt )
Book line         typename ::-opt nested_name_specifier template-opt template_id
                    ( expression_list-opt )
                  postfix_expression . template-opt ::-opt id_expression
                  postfix_expression -> template-opt ::-opt id_expression

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -