Skip to content

Commit 0a6e5cf

Browse files
committed
Simplify some grammar constructs.
A number of constructs in the grammar were only a single entry, or only used once (or both). This CL inlines many of these single entry constructs to the place of usage. This makes it simpler to read the grammar requiring less jumping around to determine what is permitted.
1 parent fe060b9 commit 0a6e5cf

1 file changed

Lines changed: 14 additions & 47 deletions

File tree

chapters/grammar.adoc

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ endif::GLSL[]
100100

101101
[role="bnf"]
102102
--
103-
_variable_identifier_ : ::
104-
_IDENTIFIER_
105103

106104
_primary_expression_ : ::
107-
_variable_identifier_ +
105+
_IDENTIFIER_ +
108106
_INTCONSTANT_ +
109107
_UINTCONSTANT_ +
110108
_FLOATCONSTANT_ +
@@ -116,7 +114,7 @@ endif::GLSL[]
116114

117115
_postfix_expression_ : ::
118116
_primary_expression_ +
119-
_postfix_expression_ _LEFT_BRACKET_ _integer_expression_ _RIGHT_BRACKET_ +
117+
_postfix_expression_ _LEFT_BRACKET_ _expression_ _RIGHT_BRACKET_ +
120118
_function_call_ +
121119
_postfix_expression_ _DOT_ _FIELD_SELECTION_ +
122120
_postfix_expression_ _INC_OP_ +
@@ -128,16 +126,7 @@ FIELD_SELECTION includes members in structures, component selection for
128126
vectors and the 'length' identifier for the length() method
129127
====
130128

131-
_integer_expression_ : ::
132-
_expression_
133-
134129
_function_call_ : ::
135-
_function_call_or_method_
136-
137-
_function_call_or_method_ : ::
138-
_function_call_generic_
139-
140-
_function_call_generic_ : ::
141130
_function_call_header_with_parameters_ _RIGHT_PAREN_ +
142131
_function_call_header_no_parameters_ _RIGHT_PAREN_
143132

@@ -171,6 +160,9 @@ _postfix_expression_.
171160
endif::ESSL[]
172161
====
173162

163+
_function_definition_ : ::
164+
_function_prototype_ _compound_statement_no_new_scope_
165+
174166
_function_identifier_ : ::
175167
_type_specifier_ +
176168
_postfix_expression_
@@ -276,11 +268,8 @@ _expression_ : ::
276268
_assignment_expression_ +
277269
_expression_ _COMMA_ _assignment_expression_
278270

279-
_constant_expression_ : ::
280-
_conditional_expression_
281-
282271
_declaration_ : ::
283-
_function_prototype_ _SEMICOLON_ +
272+
_function_declarator_ _RIGHT_PAREN_ _SEMICOLON_ +
284273
_init_declarator_list_ _SEMICOLON_ +
285274
_PRECISION_ _precision_qualifier_ _type_specifier_ _SEMICOLON_ +
286275
_type_qualifier_ _IDENTIFIER_ _LEFT_BRACE_ _struct_declaration_list_
@@ -297,9 +286,6 @@ _identifier_list_ : ::
297286
_COMMA_ _IDENTIFIER_ +
298287
_identifier_list_ _COMMA_ _IDENTIFIER_
299288

300-
_function_prototype_ : ::
301-
_function_declarator_ _RIGHT_PAREN_
302-
303289
_function_declarator_ : ::
304290
_function_header_ +
305291
_function_header_with_parameters_
@@ -318,10 +304,7 @@ _parameter_declarator_ : ::
318304
_parameter_declaration_ : ::
319305
_type_qualifier_ _parameter_declarator_ +
320306
_parameter_declarator_ +
321-
_type_qualifier_ _parameter_type_specifier_ +
322-
_parameter_type_specifier_
323-
324-
_parameter_type_specifier_ : ::
307+
_type_qualifier_ _type_specifier_ +
325308
_type_specifier_
326309

327310
_init_declarator_list_ : ::
@@ -349,9 +332,6 @@ _fully_specified_type_ : ::
349332
_type_specifier_ +
350333
_type_qualifier_ _type_specifier_
351334

352-
_invariant_qualifier_ : ::
353-
_INVARIANT_
354-
355335
_interpolation_qualifier_ : ::
356336
_SMOOTH_ +
357337
ifdef::GLSL[]
@@ -362,38 +342,32 @@ ifdef::ESSL[]
362342
_FLAT_
363343
endif::ESSL[]
364344

365-
_layout_qualifier_ : ::
366-
_LAYOUT_ _LEFT_PAREN_ _layout_qualifier_id_list_ _RIGHT_PAREN_
367-
368345
_layout_qualifier_id_list_ : ::
369346
_layout_qualifier_id_ +
370347
_layout_qualifier_id_list_ _COMMA_ _layout_qualifier_id_
371348

372349
_layout_qualifier_id_ : ::
373350
_IDENTIFIER_ +
374351
ifdef::GLSL[]
375-
_IDENTIFIER_ _EQUAL_ _constant_expression_ +
352+
_IDENTIFIER_ _EQUAL_ __conditional_expression__ +
376353
endif::GLSL[]
377354
ifdef::ESSL[]
378355
_IDENTIFIER_ _EQUAL_ _INTCONSTANT_ +
379356
_IDENTIFIER_ _EQUAL_ _UINTCONSTANT_ +
380357
endif::ESSL[]
381358
_SHARED_
382359

383-
_precise_qualifier_ : ::
384-
_PRECISE_
385-
386360
_type_qualifier_ : ::
387361
_single_type_qualifier_ +
388362
_type_qualifier_ _single_type_qualifier_
389363

390364
_single_type_qualifier_ : ::
391365
_storage_qualifier_ +
392-
_layout_qualifier_ +
366+
_LAYOUT_ _LEFT_PAREN_ _layout_qualifier_id_list_ _RIGHT_PAREN_ +
393367
_precision_qualifier_ +
394368
_interpolation_qualifier_ +
395-
_invariant_qualifier_ +
396-
_precise_qualifier_
369+
_INVARIANT_ +
370+
_PRECISE_
397371

398372
_storage_qualifier_ : ::
399373
_CONST_ +
@@ -574,8 +548,7 @@ _precision_qualifier_ : ::
574548
_LOW_PRECISION_
575549

576550
_struct_specifier_ : ::
577-
_STRUCT_ _IDENTIFIER_ _LEFT_BRACE_ _struct_declaration_list_
578-
_RIGHT_BRACE_ +
551+
_STRUCT_ _IDENTIFIER_ _LEFT_BRACE_ _struct_declaration_list_ _RIGHT_BRACE_ +
579552
_STRUCT_ _LEFT_BRACE_ _struct_declaration_list_ _RIGHT_BRACE_
580553

581554
_struct_declaration_list_ : ::
@@ -608,9 +581,6 @@ ifdef::ESSL[]
608581
_assignment_expression_
609582
endif::ESSL[]
610583

611-
_declaration_statement_ : ::
612-
_declaration_
613-
614584
_statement_ : ::
615585
_compound_statement_ +
616586
_simple_statement_
@@ -621,7 +591,7 @@ Grammar Note: labeled statements for SWITCH only; 'goto' is not supported.
621591
====
622592

623593
_simple_statement_ : ::
624-
_declaration_statement_ +
594+
_declaration_ +
625595
_expression_statement_ +
626596
_selection_statement_ +
627597
_switch_statement_ +
@@ -682,7 +652,7 @@ _iteration_statement_ : ::
682652

683653
_for_init_statement_ : ::
684654
_expression_statement_ +
685-
_declaration_statement_
655+
_declaration_
686656

687657
_conditionopt_ : ::
688658
/* _empty_ */ +
@@ -719,9 +689,6 @@ ifdef::ESSL[]
719689
_declaration_
720690
endif::ESSL[]
721691

722-
_function_definition_ : ::
723-
_function_prototype_ _compound_statement_no_new_scope_
724-
725692
--
726693

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

0 commit comments

Comments
 (0)