[Mesa-dev] [PATCH 2/5] glsl: Add productions to GLSL grammar for switch statement
The grammar is modified to support switch statements. Rather than follow the grammar in the appendix, which allows case labels to be placed ANYWHERE as a regular statement, we follow the development of the grammar as described in the body of the GLSL spec. In this variation, the switch statement has a body which consists of a list of case statements. A case statement is preceded by a list of case labels and ends with a list of statements. --- src/glsl/glsl_parser.yy | 64 -- 1 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy index 2c0498e..b3727ce 100644 --- a/src/glsl/glsl_parser.yy +++ b/src/glsl/glsl_parser.yy @@ -206,6 +206,12 @@ %type struct_declarator_list %type selection_statement %type selection_rest_statement +%type switch_statement +%type switch_body +%type case_label +%type case_label_list +%type case_statement +%type case_statement_list %type iteration_statement %type condition %type conditionopt @@ -1519,8 +1525,7 @@ simple_statement: declaration_statement | expression_statement | selection_statement - | switch_statement { $$ = NULL; } - | case_label{ $$ = NULL; } + | switch_statement | iteration_statement | jump_statement ; @@ -1642,15 +1647,68 @@ condition: } ; +/* + * siwtch_statement grammar is based on the syntax described in the body + * of the GLSL spec, not in it's appendix!!! + */ switch_statement: - SWITCH '(' expression ')' compound_statement + SWITCH '(' expression ')' switch_body + { + $$ = NULL; + } + ; + +switch_body: + '{' '}' + { + $$ = NULL; + } + | '{' case_statement_list '}' + { + $$ = NULL; + } ; case_label: CASE expression ':' + { + $$ = NULL; + } | DEFAULT ':' + { + $$ = NULL; + } ; +case_label_list: + case_label + { + $$ = NULL; + } + | case_label_list case_label + { + $$ = NULL; + } + ; + +case_statement: + case_label_list statement_list + { + $$ = NULL; + } + ; + +case_statement_list: + case_statement + { + $$ = NULL; + } + | case_statement_list case_statement + { + $$ = NULL; + } + ; + iteration_statement: WHILE '(' condition ')' statement_no_new_scope { -- 1.7.4.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/5] glsl: Add productions to GLSL grammar for switch statement
On 06/28/2011 02:48 PM, Dan McCabe wrote: > The grammar is modified to support switch statements. Rather than follow the > grammar in the appendix, which allows case labels to be placed ANYWHERE > as a regular statement, we follow the development of the grammar as > described in the body of the GLSL. "body of the GLSL spec." > In this variation, the switch statement has a body which consists of a list > of case statements. A case statement is preceded by a list of case labels and > ends with a list of statements. This one looks good to me. Reviewed-by: Kenneth Graunke ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 2/5] glsl: Add productions to GLSL grammar for switch statement
The grammar is modified to support switch statements. Rather than follow the grammar in the appendix, which allows case labels to be placed ANYWHERE as a regular statement, we follow the development of the grammar as described in the body of the GLSL. In this variation, the switch statement has a body which consists of a list of case statements. A case statement is preceded by a list of case labels and ends with a list of statements. --- src/glsl/glsl_parser.yy | 64 -- 1 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy index 2c0498e..b3727ce 100644 --- a/src/glsl/glsl_parser.yy +++ b/src/glsl/glsl_parser.yy @@ -206,6 +206,12 @@ %type struct_declarator_list %type selection_statement %type selection_rest_statement +%type switch_statement +%type switch_body +%type case_label +%type case_label_list +%type case_statement +%type case_statement_list %type iteration_statement %type condition %type conditionopt @@ -1519,8 +1525,7 @@ simple_statement: declaration_statement | expression_statement | selection_statement - | switch_statement { $$ = NULL; } - | case_label{ $$ = NULL; } + | switch_statement | iteration_statement | jump_statement ; @@ -1642,15 +1647,68 @@ condition: } ; +/* + * siwtch_statement grammar is based on the syntax described in the body + * of the GLSL spec, not in it's appendix!!! + */ switch_statement: - SWITCH '(' expression ')' compound_statement + SWITCH '(' expression ')' switch_body + { + $$ = NULL; + } + ; + +switch_body: + '{' '}' + { + $$ = NULL; + } + | '{' case_statement_list '}' + { + $$ = NULL; + } ; case_label: CASE expression ':' + { + $$ = NULL; + } | DEFAULT ':' + { + $$ = NULL; + } ; +case_label_list: + case_label + { + $$ = NULL; + } + | case_label_list case_label + { + $$ = NULL; + } + ; + +case_statement: + case_label_list statement_list + { + $$ = NULL; + } + ; + +case_statement_list: + case_statement + { + $$ = NULL; + } + | case_statement_list case_statement + { + $$ = NULL; + } + ; + iteration_statement: WHILE '(' condition ')' statement_no_new_scope { -- 1.7.4.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev