summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorDan McCabe <zen3d.linux@gmail.com>2011-11-07 15:07:43 -0800
committerDan McCabe <zen3d.linux@gmail.com>2011-11-07 16:31:21 -0800
commit80944599dcf070efa84ebf192c31f4129cee697d (patch)
treebc018dd5e5dda706139714d7aaf7b143a0ff6899 /src/glsl
parent19daba54707b4ff90159850ce97faceba9c336c0 (diff)
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. Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/glsl_parser.yy64
1 files changed, 61 insertions, 3 deletions
diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
index d32d6e4e1ce..8948c34a237 100644
--- a/src/glsl/glsl_parser.yy
+++ b/src/glsl/glsl_parser.yy
@@ -207,6 +207,12 @@
%type <declaration> struct_declarator_list
%type <node> selection_statement
%type <selection_rest_statement> selection_rest_statement
+%type <node> switch_statement
+%type <node> switch_body
+%type <node> case_label
+%type <node> case_label_list
+%type <node> case_statement
+%type <node> case_statement_list
%type <node> iteration_statement
%type <node> condition
%type <node> conditionopt
@@ -1517,8 +1523,7 @@ simple_statement:
declaration_statement
| expression_statement
| selection_statement
- | switch_statement { $$ = NULL; }
- | case_label { $$ = NULL; }
+ | switch_statement
| iteration_statement
| jump_statement
;
@@ -1640,13 +1645,66 @@ 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: