LL (1) grammar

Source: Internet
Author: User

The grammar is as follows:

<program>-><external_declaration> | <program> <external_declaration>

<external_declaration>-><function_definition> | <declaration>

<function_definition>-><type_specifier> <declarator> <compound_statement>

<type_specifier>->void | char | int | Float

<declarator>-><pointer direct_declarator> | <direct_declarator>

<Pointer>-> ' * ' | ' * ' pointer

<direct_declarator>-><IDENTIFIER> |<direct_declarator ' ['] ' >
|<direct_declarator ' [' constant_expression '] ' >
| <identifier ' (' parameter_list ') ' >
| <identifier ' (') ' >|<direct_declarator ', ' identifier_list>

<identifier_list>-><: identifier>| <identifier_list ', ' identifier>

<constant_expression>-><conditional_expression>

<parameter_list>-><parameter_declaration>| <parameter_list> < ', ' > <parameter_declaration>

<parameter_declaration>-><declaration_specifiers><IDENTIFIER>

<compound_statement>->< ' {' < > '} ' > | < ' {' ><statement_list>< '} ' >| < ' {' ><declaration_list statement_list >< '} '

<declaration_list>-><declaration>| <declaration_list><declaration>

<declaration>-><init_declarator>| <init_declarator_list>< ', ' > <init_declarator>

<init_declarator>-><declarator>| <declarator> < ' = ' > <initializer>

<initializer >-><assignment_expression>| < ' {' >< initializer_list>< '}> ' |< ' {' >< initializer_list>< ', ' > < '} ' >

<initializer_program_list>-><initializer_program>| <initializer_program_list>< ', ' > <initializer_program>

<statement_list>-><statement>| <statement_list> <statement>

<statement >->| <compound_statement> | <expression_statement> | <selection_statement> | <iteration_statement> | <jump_statement>

<expression_statement> < '; ' > | <expression>< '; ' >

<selection_statement> <:>< if>< ' (' >< expression >< ') ' > <statement>
| <if> < ' (' >< expression >< ') ' > <statement><else> <statement>

<iteration_statement>-><while>< ' (' >< expression >< ') ' >< statement>
| <for> < ' (' >< expression_statement>< expression_statement>< ') ' >< statement>
| <for> < ' (' >< expression_statement>< expression_statement>< expression >< ') ' > < statement>

<jump_statement>-> | continue< '; ' > | break< '; ' > | RETURN < '; ' > | RETURN <expression> < '; ' >

<expression>-> <: ><assignment_expression> | <expression> < ', ' > <assignment_expression>

<assignment_expression>-><conditional_expression>| <unary_expression>< assignment_operator>< assignment_expression>

<conditional_expression >-> <logical_or_expression>
| <logical_or_expression>< '? ' >< expression >< ': ' >< conditional_expression>

<logical_or_expression >->< logical_and_expression> | <logical_or_expression> Or_op <logical_and_expression>

<logical_and_expression> <:>< inclusive_or_expression> | <logical_and_expression> And_op <inclusive_or_expression>

<inclusive_or_expression>-> <exclusive_or_expression> | <inclusive_or_expression >< ' > | < ' > <exclusive_or_expression>

<exclusive_or_expression>-><:> <and_expression>| <exclusive_or_expression> < ' ><^ ' > <and_expression>

<and_expression>-> <:>< equality_expression> | <and_expression >< ' ><&>< ' >< equality_expression>

<equality_expression>-><:>< relational_expression> | <equality_expression >eq_op <relational_expression> | <equality_expression> Ne_op <relational_expression>

<relational_expression><:> <shift_expression> | <relational_expression> < ' ><<>< ' > <shift_expression>

| <relational_expression ' > ' shift_expression>| <relational_expression Le_op shift_expression>| <relational_expression Ge_op shift_expression>

<shift_expression>-> <:>< additive_expression> | <shift_expression Left_op additive_expression> | <shift_expression Right_op additive_expression>

<additive_expression>-><:> <multiplicative_expression>
| <additive_expression> < ' + ' > <multiplicative_expression>
| <additive_expression> < '-' > <multiplicative_expression>

<multiplicative_expression> <:> <cast_expression>
| <multiplicative_expression> < ' * ' > <cast_expression>
| <multiplicative_expression> < '/' > <cast_expression>
| <multiplicative_expression> < '% ' > <cast_expression>

<cast_expression>-><:>< unary_expression> | < ' (' >< type_name >< ') ' >< cast_expression>

<unary_expression>-><:> <postfix_expression>
| <inc_op unary_expression>
| <dec_op unary_expression>
| <unary_operator>< cast_expression>
| <sizeof unary_expression>
| <SIZEOF> ' (' >< type_name >< ') ' >

<postfix_expression >-><:> <primary_expression>
|< postfix_expression> < ' [' >< expression >< '] ' >
| <postfix_expression >< ' (' >< ') ' >
| <postfix_expression ' (' argument_expression_list ') ' >
| <postfix_expression '. ' Identifier>
| <postfix_expression Ptr_op identifier>
| <postfix_expression inc_op>
| <postfix_expression dec_op>

<primary_expression>->identifier | CONSTANT | string_literal | < ' (' >< expression >< ') ' >

<argument_expression_list>-> <:>< assignment_expression> | <argument_expression_list> < ', ' > <assignment_expression>

<unary_operator>-> <:>< ' & ' > | < ' * ' > | < ' + ' > | < '-' >| < ' ~ ' > | < '! ' >

<storage_class_specifier >-> TYPEDEF | EXTERN | STATIC | AUTO | REGISTER

<struct_or_union_specifier>-><:>< struct_or_union identifier>< ' {' >< struct_ declaration_list>< '} ' >
| <struct_or_union >< ' {' ><struct_declaration_list>< '} ' >
| <struct_or_union> IDENTIFIER

<struct_or_union>-> <: >struct | UNION

<struct_declaration_list> <:>< struct_declaration> | <struct_declaration_list ><struct_declaration>

<struct_declaration>-><:>< specifier_qualifier_list>< struct_declarator_list>< '; ' >

<specifier_qualifier_list >-> < type_specifier>< specifier_qualifier_list>
| <type_specifier>
| <type_qualifier ><specifier_qualifier_list>
| <type_qualifier>

<struct_declarator_list>-><struct_declarator>
| <struct_declarator_list>< ', ' >< struct_declarator>

<struct_declarator>-> <:>< declarator> |< ': ' >< constant_expression>
| <declarator >< ': ' > <constant_expression>

<enum_specifier >-> < enum ' {' Enumerator_list '} ' >
| <enum IDENTIFIER ' {' enumerator_list '} ' >
| ENUM IDENTIFIER

<enumerator_list >-> Enumerator | Enumerator_list < ', ' > Enumerator

<enumerator >->identifier | IDENTIFIER < ' = ' > <constant_expression>

<type_qualifier >->const | VOLATILE

<type_qualifier_list>-> <type_qualifier> | <type_qualifier_list> <type_qualifier>

<parameter_type_list>-> <parameter_list> | <parameter_list >< ', ' > Ellipsis

<parameter_list>-> <:>< parameter_declaration> | <parameter_list>< ', ' >< parameter_declaration>

<type_name>->< specifier_qualifier_list> | <specifier_qualifier_list>< abstract_declarator>

<abstract_declarator>-> pointer | <direct_abstract_declarator> | <pointer direct_abstract_declarator>

LL (1) grammar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.