Removed some ANSI C things from the HLSL grammar that shaders don't do.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 28 Feb 2009 14:35:09 -0500
changeset 709 6fbd0e20b40f
parent 708 d29c193900b0
child 710 cbcba3ea6a05
Removed some ANSI C things from the HLSL grammar that shaders don't do.
mojoshader_compiler.c
mojoshader_parser_hlsl.lemon
--- a/mojoshader_compiler.c	Sat Feb 28 04:32:56 2009 -0500
+++ b/mojoshader_compiler.c	Sat Feb 28 14:35:09 2009 -0500
@@ -1,14 +1,17 @@
-typedef struct Context Context;
-#include "mojoshader_parser_hlsl.h"
-#include "mojoshader_parser_hlsl.c"
+#define __MOJOSHADER_INTERNAL__ 1
+#include "mojoshader_internal.h"
 
-struct Context
+typedef struct Context
 {
     Preprocessor *preprocessor;
     const char *token;      // assembler token!
     unsigned int tokenlen;  // assembler token!
     Token tokenval;         // assembler token!
-};
+} Context;
+
+#define __MOJOSHADER_HLSL_COMPILER__ 1
+#include "mojoshader_parser_hlsl.h"
+#include "mojoshader_parser_hlsl.c"
 
 static int ConvertToLemonToken(const Context *ctx)
 {
@@ -87,15 +90,14 @@
             if (tokencmp("void")) return TOKEN_HLSL_VOID;
             if (tokencmp("struct")) return TOKEN_HLSL_STRUCT;
             if (tokencmp("union")) return TOKEN_HLSL_UNION;
-            if (tokencmp("enum")) return TOKEN_HLSL_ENUM;
             if (tokencmp("case")) return TOKEN_HLSL_CASE;
             if (tokencmp("default")) return TOKEN_HLSL_DEFAULT;
+            if (tokencmp("discard")) return TOKEN_HLSL_DISCARD;
             if (tokencmp("if")) return TOKEN_HLSL_IF;
             if (tokencmp("switch")) return TOKEN_HLSL_SWITCH;
             if (tokencmp("while")) return TOKEN_HLSL_WHILE;
             if (tokencmp("do")) return TOKEN_HLSL_DO;
             if (tokencmp("for")) return TOKEN_HLSL_FOR;
-            if (tokencmp("goto")) return TOKEN_HLSL_GOTO;
             if (tokencmp("continue")) return TOKEN_HLSL_CONTINUE;
             if (tokencmp("break")) return TOKEN_HLSL_BREAK;
             if (tokencmp("return")) return TOKEN_HLSL_RETURN;
--- a/mojoshader_parser_hlsl.lemon	Sat Feb 28 04:32:56 2009 -0500
+++ b/mojoshader_parser_hlsl.lemon	Sat Feb 28 14:35:09 2009 -0500
@@ -25,8 +25,9 @@
 %extra_argument { Context *ctx }
 
 %include {
-#define __MOJOSHADER_INTERNAL__ 1
-#include "mojoshader_internal.h"
+#ifndef __MOJOSHADER_HLSL_COMPILER__
+#error Do not compile this file directly.
+#endif
 }
 
 %parse_failure {
@@ -192,7 +193,6 @@
 type_specifier ::= VOLATILE.
 type_specifier ::= VOID.
 type_specifier ::= struct_or_union_specifier.
-type_specifier ::= enum_specifier.
 type_specifier ::= TYPE_NAME.
 
 struct_or_union_specifier ::= struct_or_union identifier LBRACE
@@ -216,18 +216,7 @@
 struct_declarator ::= COLON constant_expr.
 struct_declarator ::= declarator COLON constant_expr.
 
-enum_specifier ::= ENUM LBRACE enumerator_list RBRACE.
-enum_specifier ::= ENUM identifier LBRACE enumerator_list RBRACE.
-enum_specifier ::= ENUM identifier.
-
-enumerator_list ::= enumerator.
-enumerator_list ::= enumerator_list COMMA enumerator.
-
-enumerator ::= identifier.
-enumerator ::= identifier ASSIGN constant_expr.
-
 declarator ::= declarator2.
-declarator ::= pointer declarator2.
 
 declarator2 ::= identifier.
 declarator2 ::= LPAREN declarator RPAREN.
@@ -237,22 +226,15 @@
 declarator2 ::= declarator2 LPAREN parameter_type_list RPAREN.
 declarator2 ::= declarator2 LPAREN parameter_identifier_list RPAREN.
 
-pointer ::= STAR.
-pointer ::= STAR type_specifier_list.
-pointer ::= STAR pointer.
-pointer ::= STAR type_specifier_list pointer.
-
 type_specifier_list ::= type_specifier.
 type_specifier_list ::= type_specifier_list type_specifier.
 
 parameter_identifier_list ::= identifier_list.
-parameter_identifier_list ::= identifier_list COMMA ELIPSIS.
 
 identifier_list ::= identifier.
 identifier_list ::= identifier_list COMMA identifier.
 
 parameter_type_list ::= parameter_list.
-parameter_type_list ::= parameter_list COMMA ELIPSIS.
 
 parameter_list ::= parameter_declaration.
 parameter_list ::= parameter_list COMMA parameter_declaration.
@@ -263,9 +245,7 @@
 type_name ::= type_specifier_list.
 type_name ::= type_specifier_list abstract_declarator.
 
-abstract_declarator ::= pointer.
 abstract_declarator ::= abstract_declarator2.
-abstract_declarator ::= pointer abstract_declarator2.
 
 abstract_declarator2 ::= LPAREN abstract_declarator RPAREN.
 abstract_declarator2 ::= LBRACKET RBRACKET.
@@ -324,9 +304,9 @@
 iteration_statement ::= FOR LPAREN expr SEMICOLON expr SEMICOLON RPAREN statement.
 iteration_statement ::= FOR LPAREN expr SEMICOLON expr SEMICOLON expr RPAREN statement.
 
-jump_statement ::= GOTO identifier SEMICOLON.
 jump_statement ::= CONTINUE SEMICOLON.
 jump_statement ::= BREAK SEMICOLON.
+jump_statement ::= DISCARD SEMICOLON.
 jump_statement ::= RETURN SEMICOLON.
 jump_statement ::= RETURN expr SEMICOLON.