Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some grammar constructs. #247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 30 additions & 62 deletions chapters/grammar.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ endif::GLSL[]

[role="bnf"]
--
_variable_identifier_ : ::
_IDENTIFIER_

_primary_expression_ : ::
_variable_identifier_ +
_IDENTIFIER_ +
_INTCONSTANT_ +
_UINTCONSTANT_ +
_FLOATCONSTANT_ +
Expand All @@ -116,7 +114,7 @@ endif::GLSL[]

_postfix_expression_ : ::
_primary_expression_ +
_postfix_expression_ _LEFT_BRACKET_ _integer_expression_ _RIGHT_BRACKET_ +
_postfix_expression_ _LEFT_BRACKET_ _expression_ _RIGHT_BRACKET_ +
_function_call_ +
_postfix_expression_ _DOT_ _FIELD_SELECTION_ +
_postfix_expression_ _INC_OP_ +
Expand All @@ -128,16 +126,7 @@ FIELD_SELECTION includes members in structures, component selection for
vectors and the 'length' identifier for the length() method
====

_integer_expression_ : ::
_expression_

_function_call_ : ::
_function_call_or_method_

_function_call_or_method_ : ::
_function_call_generic_

_function_call_generic_ : ::
_function_call_header_with_parameters_ _RIGHT_PAREN_ +
_function_call_header_no_parameters_ _RIGHT_PAREN_

Expand All @@ -152,6 +141,25 @@ _function_call_header_with_parameters_ : ::
_function_call_header_ : ::
_function_identifier_ _LEFT_PAREN_

_function_definition_ : ::
_function_declarator_ _RIGHT_PAREN_ _compound_statement_no_new_scope_

_function_identifier_ : ::
_type_specifier_ +
_postfix_expression_

_function_declarator_ : ::
_function_header_ +
_function_header_with_parameters_

_function_header_with_parameters_ : ::
_function_header_ _parameter_declaration_ +
_function_header_with_parameters_ _COMMA_ _parameter_declaration_

_function_header_ : ::
_fully_specified_type_ _IDENTIFIER_ _LEFT_PAREN_


[NOTE]
====
Grammar Note: Constructors look like functions, but lexical analysis
Expand All @@ -171,10 +179,6 @@ _postfix_expression_.
endif::ESSL[]
====

_function_identifier_ : ::
_type_specifier_ +
_postfix_expression_

_unary_expression_ : ::
_postfix_expression_ +
_INC_OP_ _unary_expression_ +
Expand Down Expand Up @@ -276,11 +280,8 @@ _expression_ : ::
_assignment_expression_ +
_expression_ _COMMA_ _assignment_expression_

_constant_expression_ : ::
_conditional_expression_

_declaration_ : ::
_function_prototype_ _SEMICOLON_ +
_function_declarator_ _RIGHT_PAREN_ _SEMICOLON_ +
_init_declarator_list_ _SEMICOLON_ +
_PRECISION_ _precision_qualifier_ _type_specifier_ _SEMICOLON_ +
_type_qualifier_ _IDENTIFIER_ _LEFT_BRACE_ _struct_declaration_list_
Expand All @@ -297,31 +298,14 @@ _identifier_list_ : ::
_COMMA_ _IDENTIFIER_ +
_identifier_list_ _COMMA_ _IDENTIFIER_

_function_prototype_ : ::
_function_declarator_ _RIGHT_PAREN_

Comment on lines -300 to -302
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a different change to remove this annoying rule in #252. We do need to keep function_prototype (it's referred to in function_definition, above), but if we structure it properly then this step isn't needed at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good catch, I'd missed that one earlier because function_definition was weirdly at the end of the grammar instead of with the other functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged it into function_defintion to keep this Cl correct, but either way these rules are very confusing to read.

_function_declarator_ : ::
_function_header_ +
_function_header_with_parameters_

_function_header_with_parameters_ : ::
_function_header_ _parameter_declaration_ +
_function_header_with_parameters_ _COMMA_ _parameter_declaration_

_function_header_ : ::
_fully_specified_type_ _IDENTIFIER_ _LEFT_PAREN_

_parameter_declarator_ : ::
_type_specifier_ _IDENTIFIER_ +
_type_specifier_ _IDENTIFIER_ _array_specifier_

_parameter_declaration_ : ::
_type_qualifier_ _parameter_declarator_ +
_parameter_declarator_ +
_type_qualifier_ _parameter_type_specifier_ +
_parameter_type_specifier_

_parameter_type_specifier_ : ::
_type_qualifier_ _type_specifier_ +
_type_specifier_

_init_declarator_list_ : ::
Expand Down Expand Up @@ -349,9 +333,6 @@ _fully_specified_type_ : ::
_type_specifier_ +
_type_qualifier_ _type_specifier_

_invariant_qualifier_ : ::
_INVARIANT_

_interpolation_qualifier_ : ::
_SMOOTH_ +
ifdef::GLSL[]
Expand All @@ -362,38 +343,32 @@ ifdef::ESSL[]
_FLAT_
endif::ESSL[]

_layout_qualifier_ : ::
_LAYOUT_ _LEFT_PAREN_ _layout_qualifier_id_list_ _RIGHT_PAREN_

_layout_qualifier_id_list_ : ::
_layout_qualifier_id_ +
_layout_qualifier_id_list_ _COMMA_ _layout_qualifier_id_

_layout_qualifier_id_ : ::
_IDENTIFIER_ +
ifdef::GLSL[]
_IDENTIFIER_ _EQUAL_ _constant_expression_ +
_IDENTIFIER_ _EQUAL_ __conditional_expression__ +
endif::GLSL[]
ifdef::ESSL[]
_IDENTIFIER_ _EQUAL_ _INTCONSTANT_ +
_IDENTIFIER_ _EQUAL_ _UINTCONSTANT_ +
endif::ESSL[]
_SHARED_

_precise_qualifier_ : ::
_PRECISE_

_type_qualifier_ : ::
_single_type_qualifier_ +
_type_qualifier_ _single_type_qualifier_

_single_type_qualifier_ : ::
_storage_qualifier_ +
_layout_qualifier_ +
_LAYOUT_ _LEFT_PAREN_ _layout_qualifier_id_list_ _RIGHT_PAREN_ +
_precision_qualifier_ +
_interpolation_qualifier_ +
_invariant_qualifier_ +
_precise_qualifier_
_INVARIANT_ +
_PRECISE_

_storage_qualifier_ : ::
_CONST_ +
Expand Down Expand Up @@ -574,8 +549,7 @@ _precision_qualifier_ : ::
_LOW_PRECISION_

_struct_specifier_ : ::
_STRUCT_ _IDENTIFIER_ _LEFT_BRACE_ _struct_declaration_list_
_RIGHT_BRACE_ +
_STRUCT_ _IDENTIFIER_ _LEFT_BRACE_ _struct_declaration_list_ _RIGHT_BRACE_ +
_STRUCT_ _LEFT_BRACE_ _struct_declaration_list_ _RIGHT_BRACE_

_struct_declaration_list_ : ::
Expand Down Expand Up @@ -608,9 +582,6 @@ ifdef::ESSL[]
_assignment_expression_
endif::ESSL[]

_declaration_statement_ : ::
_declaration_

_statement_ : ::
_compound_statement_ +
_simple_statement_
Expand All @@ -621,7 +592,7 @@ Grammar Note: labeled statements for SWITCH only; 'goto' is not supported.
====

_simple_statement_ : ::
_declaration_statement_ +
_declaration_ +
_expression_statement_ +
_selection_statement_ +
_switch_statement_ +
Expand Down Expand Up @@ -682,7 +653,7 @@ _iteration_statement_ : ::

_for_init_statement_ : ::
_expression_statement_ +
_declaration_statement_
_declaration_

_conditionopt_ : ::
/* _empty_ */ +
Expand Down Expand Up @@ -719,9 +690,6 @@ ifdef::ESSL[]
_declaration_
endif::ESSL[]

_function_definition_ : ::
_function_prototype_ _compound_statement_no_new_scope_

--

In general the above grammar describes a super set of the {slname}.
Expand Down