summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 01:42:31 +0000
committerkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 01:42:31 +0000
commitd267ac762bb0764857fedb92a516a9aa290b0dd2 (patch)
tree7e265d3343685ed89f96b5185058790aa007671a /o3d
parent7e76fdeb4b7f95bc3e315772a0fac5edcc9675cb (diff)
downloadchromium_src-d267ac762bb0764857fedb92a516a9aa290b0dd2.zip
chromium_src-d267ac762bb0764857fedb92a516a9aa290b0dd2.tar.gz
chromium_src-d267ac762bb0764857fedb92a516a9aa290b0dd2.tar.bz2
Adding Bison and ANTLR grammars for GLSL ES. The grammars are derived
from the OpenGL ES specification and are intended to match the structure in the spec as closely as possible while working with existing tools. Hints were taken from the Mesa GLSL grammar, which uses a custom parser generator, to solve reduce/reduce conflicts in the Bison version. The grammars do nothing at the moment except parse inputs and provide rudimentary error reporting. Follow-on work will extend these grammars with the intended functionality. Basic testing has been done but much more is needed. Review URL: http://codereview.chromium.org/159324 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/compiler/glsl_validator/Makefile34
-rw-r--r--o3d/compiler/glsl_validator/build.xml69
-rw-r--r--o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g661
-rw-r--r--o3d/compiler/glsl_validator/glsl_es/GLSL_ES.l221
-rw-r--r--o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y599
-rw-r--r--o3d/compiler/glsl_validator/shaders/ambient.frag10
-rw-r--r--o3d/compiler/glsl_validator/shaders/ambient.vert11
-rw-r--r--o3d/compiler/glsl_validator/shaders/diffuse.frag22
-rw-r--r--o3d/compiler/glsl_validator/shaders/diffuse.vert28
-rw-r--r--o3d/compiler/glsl_validator/shaders/texture_mapping.frag12
-rw-r--r--o3d/compiler/glsl_validator/shaders/texture_mapping.vert18
-rw-r--r--o3d/compiler/glsl_validator/test/Main.java62
12 files changed, 1747 insertions, 0 deletions
diff --git a/o3d/compiler/glsl_validator/Makefile b/o3d/compiler/glsl_validator/Makefile
new file mode 100644
index 0000000..60dba47
--- /dev/null
+++ b/o3d/compiler/glsl_validator/Makefile
@@ -0,0 +1,34 @@
+# Makefile for the Flex/Bison GLSL ES grammar and simple test harness.
+# "make" to build everything.
+# "make clean" to clean the build.
+# "make test" to run tests.
+
+CC=gcc
+BUILD=build
+SRC=glsl_es
+
+LEXER_INPUT=$(SRC)/GLSL_ES.l
+GRAMMAR_INPUT=$(SRC)/GLSL_ES.y
+GRAMMAR_INPUTS=$(LEXER_INPUT) $(GRAMMAR_INPUT)
+LEXER_OUTPUT=$(BUILD)/GLSL_ES.lex.c
+GRAMMAR_OUTPUT=$(BUILD)/GLSL_ES.tab.c
+GRAMMAR_OUTPUTS=$(LEXER_OUTPUT) $(GRAMMAR_OUTPUT)
+
+$(BUILD)/GLSLESParser: $(GRAMMAR_OUTPUTS)
+ $(CC) -I$(BUILD) $(GRAMMAR_OUTPUTS) -o $(BUILD)/GLSLESParser
+
+$(GRAMMAR_OUTPUTS): $(GRAMMAR_INPUTS)
+ mkdir -p $(BUILD)
+ lex -o $(LEXER_OUTPUT) $(LEXER_INPUT)
+ bison -o $(GRAMMAR_OUTPUT) -v -d --debug $(GRAMMAR_INPUT)
+
+.PHONY: test
+
+test:
+ @for i in $(shell ls shaders/*.vert) $(shell ls shaders/*.frag) ; do \
+ echo Parsing $$i ; \
+ time $(BUILD)/GLSLESParser < $$i ; \
+ done
+
+clean:
+ rm $(BUILD)/GLSLESParser $(GRAMMAR_OUTPUTS) $(BUILD)/GLSL_ES.output $(BUILD)/GLSL_ES.tab.h
diff --git a/o3d/compiler/glsl_validator/build.xml b/o3d/compiler/glsl_validator/build.xml
new file mode 100644
index 0000000..be53186
--- /dev/null
+++ b/o3d/compiler/glsl_validator/build.xml
@@ -0,0 +1,69 @@
+<!--
+ - Ant build for the ANTLR GLSL ES grammar and simple test harness.
+ - "ant" to compile everything.
+ - "ant clean" to clean the build.
+ - "ant test" to run tests.
+ -->
+
+<project name="GLSL_ES" basedir="." default="all">
+ <target name="init">
+ <property name="build" value="build" />
+ <property name="test" value="test" />
+ <path id="antlr.classpath">
+ <pathelement location="../../third_party/antlr3/lib/antlr-3.1.1.jar" />
+ </path>
+ <path id="antlr.runtime.classpath">
+ <pathelement location="../../third_party/antlr3/lib/antlr-runtime-3.1.1.jar" />
+ </path>
+ <path id="test.classpath">
+ <pathelement location="../../third_party/antlr3/lib/antlr-runtime-3.1.1.jar" />
+ <pathelement location="${build}" />
+ </path>
+ </target>
+
+ <target name="build" depends="init">
+ <mkdir dir="${build}" />
+ <mkdir dir="${build}/glsl_es" />
+ <!-- Run ANTLR on the grammar -->
+ <java classname="org.antlr.Tool">
+ <classpath refid="antlr.classpath" />
+ <arg value="glsl_es/GLSL_ES.g" />
+ <arg value="-fo" />
+ <arg value="${build}/glsl_es" />
+ </java>
+ <!-- Compile the grammar and test cases -->
+ <javac srcdir="${build}:${test}"
+ destdir="${build}">
+ <classpath refid="antlr.runtime.classpath" />
+ </javac>
+ </target>
+
+ <target name="test" depends="init">
+ <java classname="test.Main">
+ <classpath refid="test.classpath" />
+ <arg value="shaders/ambient.vert" />
+ <arg value="shaders/ambient.frag" />
+ <arg value="shaders/diffuse.vert" />
+ <arg value="shaders/diffuse.frag" />
+ <arg value="shaders/texture_mapping.vert" />
+ <arg value="shaders/texture_mapping.frag" />
+ </java>
+ </target>
+
+ <target name="testgrammar" depends="init">
+ <mkdir dir="${build}" />
+ <!-- Run ANTLR on the grammar -->
+ <java classname="org.antlr.Tool">
+ <classpath refid="antlr.classpath" />
+ <arg value="glsl_es/Test.g" />
+ <arg value="-fo" />
+ <arg value="${build}" />
+ </java>
+ </target>
+
+ <target name="clean" depends="init">
+ <delete dir="${build}" />
+ </target>
+
+ <target name="all" depends="build" />
+</project>
diff --git a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g
new file mode 100644
index 0000000..688fbf8
--- /dev/null
+++ b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.g
@@ -0,0 +1,661 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// This file contains the ANTLR grammar for parsing GLSL ES into an Abstract
+// Syntax Tree (AST).
+
+grammar GLSL_ES;
+
+options {
+ language = Java;
+ }
+
+@lexer::header { package glsl_es; }
+@parser::header { package glsl_es; }
+
+/* Main entry point */
+translation_unit
+ : ( external_declaration )* EOF
+ ;
+
+variable_identifier
+ : IDENTIFIER
+ ;
+
+primary_expression
+ : INTCONSTANT
+ | FLOATCONSTANT
+ | BOOLCONSTANT
+ | variable_identifier
+ | LEFT_PAREN expression RIGHT_PAREN
+ ;
+
+postfix_expression
+ : primary_expression_or_function_call
+ ( LEFT_BRACKET integer_expression RIGHT_BRACKET
+ | DOT field_selection
+ | INC_OP
+ | DEC_OP
+ )*
+ ;
+
+primary_expression_or_function_call
+ : ( INTCONSTANT ) => primary_expression
+ | ( FLOATCONSTANT ) => primary_expression
+ | ( BOOLCONSTANT ) => primary_expression
+ | ( LEFT_PAREN ) => primary_expression
+ | ( function_call_header ) => function_call
+ | primary_expression
+ ;
+
+integer_expression
+ : expression
+ ;
+
+function_call
+ : function_call_generic
+ ;
+
+function_call_generic
+ : function_call_header
+ (
+ (VOID)?
+ | assignment_expression (COMMA assignment_expression)*
+ )
+ RIGHT_PAREN
+ ;
+
+function_call_header
+ : function_identifier LEFT_PAREN
+ ;
+
+function_identifier
+ : constructor_identifier
+ | IDENTIFIER
+ ;
+
+// Grammar Note: Constructors look like functions, but lexical analysis recognized most of them as
+// keywords.
+//
+// FIXME: do we need to register declared struct types in a dictionary
+// and look them up in order to be able to handle the TYPE_NAME
+// constructor identifier type?
+
+constructor_identifier
+ : FLOAT
+ | INT
+ | BOOL
+ | VEC2
+ | VEC3
+ | VEC4
+ | BVEC2
+ | BVEC3
+ | BVEC4
+ | IVEC2
+ | IVEC3
+ | IVEC4
+ | MAT2
+ | MAT3
+ | MAT4
+// | TYPE_NAME
+ ;
+
+unary_expression
+ : (INC_OP | DEC_OP | unary_operator)* postfix_expression
+ ;
+
+// Grammar Note: No traditional style type casts.
+
+unary_operator
+ : PLUS
+ | DASH
+ | BANG
+//| TILDE // reserved
+ ;
+
+// Grammar Note: No '*' or '&' unary ops. Pointers are not supported.
+
+multiplicative_expression
+ : unary_expression ((STAR | SLASH) unary_expression)*
+//| multiplicative_expression PERCENT unary_expression // reserved
+ ;
+
+additive_expression
+ : multiplicative_expression ((PLUS | DASH) multiplicative_expression)*
+ ;
+
+shift_expression
+ : additive_expression
+//| shift_expression LEFT_OP additive_expression // reserved
+//| shift_expression RIGHT_OP additive_expression // reserved
+ ;
+
+relational_expression
+ : shift_expression ((LEFT_ANGLE | RIGHT_ANGLE | LE_OP | GE_OP) shift_expression)*
+ ;
+
+equality_expression
+ : relational_expression ((EQ_OP | NE_OP) relational_expression)*
+ ;
+
+and_expression
+ : equality_expression
+//| and_expression AMPERSAND equality_expression // reserved
+ ;
+
+exclusive_or_expression
+ : and_expression
+//| exclusive_or_expression CARET and_expression // reserved
+ ;
+
+inclusive_or_expression
+ : exclusive_or_expression
+//| inclusive_or_expression VERTICAL_BAR exclusive_or_expression // reserved
+ ;
+
+logical_and_expression
+ : inclusive_or_expression (AND_OP inclusive_or_expression)*
+ ;
+
+logical_xor_expression
+ : logical_and_expression (XOR_OP logical_and_expression)*
+ ;
+
+logical_or_expression
+ : logical_xor_expression (OR_OP logical_xor_expression)*
+ ;
+
+conditional_expression
+ : logical_or_expression (QUESTION expression COLON assignment_expression)?
+ ;
+
+assignment_expression
+ : (unary_expression assignment_operator) => unary_expression assignment_operator assignment_expression
+ | conditional_expression
+ ;
+
+assignment_operator
+ : EQUAL
+ | MUL_ASSIGN
+ | DIV_ASSIGN
+//| MOD_ASSIGN // reserved
+ | ADD_ASSIGN
+ | SUB_ASSIGN
+//| LEFT_ASSIGN // reserved
+//| RIGHT_ASSIGN // reserved
+//| AND_ASSIGN // reserved
+//| XOR_ASSIGN // reserved
+//| OR_ASSIGN // reserved
+ ;
+
+expression
+ : assignment_expression (COMMA assignment_expression)*
+ ;
+
+constant_expression
+ : conditional_expression
+ ;
+
+declaration
+ : (function_header) => function_prototype SEMICOLON
+ | init_declarator_list SEMICOLON
+ | PRECISION precision_qualifier type_specifier_no_prec SEMICOLON
+ ;
+
+function_prototype
+ : function_declarator RIGHT_PAREN
+ ;
+
+function_declarator
+ : function_header (parameter_declaration (COMMA parameter_declaration)* )?
+ ;
+
+function_header
+ : fully_specified_type IDENTIFIER LEFT_PAREN
+ ;
+
+parameter_declaration
+ : (type_qualifier (parameter_qualifier)? )?
+ ( type_specifier
+ // parameter_declarator
+ (IDENTIFIER)?
+ // parameter_type_specifier
+ (LEFT_BRACKET constant_expression RIGHT_BRACKET)?
+ )
+ ;
+
+// NOTE: this originally had "empty" as one of the arms in the grammar
+
+parameter_qualifier
+ : IN
+ | OUT
+ | INOUT
+ ;
+
+init_declarator_list
+ : single_declaration (init_declarator_list_1)*
+ ;
+
+init_declarator_list_1
+ : COMMA IDENTIFIER (init_declarator_list_2)?
+ ;
+
+init_declarator_list_2
+ : LEFT_BRACKET constant_expression RIGHT_BRACKET
+ | EQUAL initializer
+ ;
+
+single_declaration
+ : fully_specified_type
+ ( IDENTIFIER
+ ( LEFT_BRACKET constant_expression RIGHT_BRACKET
+ | EQUAL initializer
+ ) ?
+ ) ?
+ | INVARIANT IDENTIFIER // Vertex only.
+ ;
+
+// Grammar Note: No 'enum', or 'typedef'.
+
+fully_specified_type
+ : type_specifier
+ | type_qualifier type_specifier
+ ;
+
+type_qualifier
+ : CONST
+ | ATTRIBUTE // Vertex only.
+ | VARYING
+ | INVARIANT VARYING
+ | UNIFORM
+ ;
+
+type_specifier
+ : type_specifier_no_prec
+ | precision_qualifier type_specifier_no_prec
+ ;
+
+type_specifier_no_prec
+ : VOID
+ | FLOAT
+ | INT
+ | BOOL
+ | VEC2
+ | VEC3
+ | VEC4
+ | BVEC2
+ | BVEC3
+ | BVEC4
+ | IVEC2
+ | IVEC3
+ | IVEC4
+ | MAT2
+ | MAT3
+ | MAT4
+ | SAMPLER2D
+ | SAMPLERCUBE
+ | struct_specifier
+// | TYPE_NAME
+ ;
+
+precision_qualifier
+ : HIGH_PRECISION
+ | MEDIUM_PRECISION
+ | LOW_PRECISION
+ ;
+
+struct_specifier
+ : STRUCT (IDENTIFIER)? LEFT_BRACE struct_declaration_list RIGHT_BRACE
+ ;
+
+struct_declaration_list
+ : (struct_declaration)+
+ ;
+
+struct_declaration
+ : type_specifier struct_declarator_list SEMICOLON
+ ;
+
+struct_declarator_list
+ : struct_declarator (COMMA struct_declarator)*
+ ;
+
+struct_declarator
+ : IDENTIFIER (LEFT_BRACKET constant_expression RIGHT_BRACKET)?
+ ;
+
+initializer
+ : assignment_expression
+ ;
+
+declaration_statement
+ : declaration
+ ;
+
+statement_no_new_scope
+ : compound_statement_with_scope
+ | simple_statement
+ ;
+
+simple_statement
+ : declaration_statement
+ | expression_statement
+ | selection_statement
+ | iteration_statement
+ | jump_statement
+ ;
+
+compound_statement_with_scope
+ : LEFT_BRACE (statement_list)? RIGHT_BRACE
+ ;
+
+statement_with_scope
+ : compound_statement_no_new_scope
+ | simple_statement
+ ;
+
+compound_statement_no_new_scope
+ : LEFT_BRACE (statement_list)? RIGHT_BRACE
+ ;
+
+statement_list
+ : (statement_no_new_scope)+
+ ;
+
+expression_statement
+ : (expression)? SEMICOLON
+ ;
+
+selection_statement
+options { backtrack=true; }
+ : IF LEFT_PAREN expression RIGHT_PAREN statement_with_scope ELSE statement_with_scope
+ | IF LEFT_PAREN expression RIGHT_PAREN statement_with_scope
+ ;
+
+condition
+ : expression
+ | fully_specified_type IDENTIFIER EQUAL initializer
+ ;
+
+iteration_statement
+ : WHILE LEFT_PAREN condition RIGHT_PAREN statement_no_new_scope
+ | DO statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
+ | FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope
+ ;
+
+for_init_statement
+ : expression_statement
+ | declaration_statement
+ ;
+
+for_rest_statement
+ : (condition)? SEMICOLON (expression)?
+ ;
+
+jump_statement
+ : CONTINUE SEMICOLON
+ | BREAK SEMICOLON
+ | RETURN (expression)? SEMICOLON
+ | DISCARD SEMICOLON // Fragment shader only.
+ ;
+
+external_declaration
+ : (function_header) => function_definition
+ | declaration
+ ;
+
+function_definition
+ : function_prototype compound_statement_no_new_scope
+ ;
+
+// ----------------------------------------------------------------------
+// Keywords
+
+ATTRIBUTE : 'attribute';
+BOOL : 'bool';
+BREAK : 'break';
+BVEC2 : 'bvec2';
+BVEC3 : 'bvec3';
+BVEC4 : 'bvec4';
+CONST : 'const';
+CONTINUE : 'continue';
+DISCARD : 'discard';
+DO : 'do';
+ELSE : 'else';
+FALSE : 'false';
+FLOAT : 'float';
+FOR : 'for';
+HIGH_PRECISION : 'highp';
+IF : 'if';
+IN : 'in';
+INOUT : 'inout';
+INT : 'int';
+INVARIANT : 'invariant';
+IVEC2 : 'ivec2';
+IVEC3 : 'ivec3';
+IVEC4 : 'ivec4';
+LOW_PRECISION : 'lowp';
+MAT2 : 'mat2';
+MAT3 : 'mat3';
+MAT4 : 'mat4';
+MEDIUM_PRECISION : 'mediump';
+OUT : 'out';
+PRECISION : 'precision';
+RETURN : 'return';
+SAMPLER2D : 'sampler2D';
+SAMPLERCUBE : 'samplerCube';
+STRUCT : 'struct';
+TRUE : 'true';
+UNIFORM : 'uniform';
+VARYING : 'varying';
+VEC2 : 'vec2';
+VEC3 : 'vec3';
+VEC4 : 'vec4';
+VOID : 'void';
+WHILE : 'while';
+
+IDENTIFIER
+ : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
+ ;
+
+/*
+// FIXME: it isn't clear whether we need to support the TYPE_NAME
+// token type; that may only be needed if typedef is supported
+TYPE_NAME
+ : IDENTIFIER
+ ;
+*/
+
+// NOTE difference in handling of leading minus sign compared to HLSL
+// grammar
+
+fragment EXPONENT_PART : ('e'|'E') (PLUS | DASH)? ('0'..'9')+ ;
+
+FLOATCONSTANT
+ : ('0'..'9')+ '.' ('0'..'9')* (EXPONENT_PART)?
+ | '.' ('0'..'9')+ (EXPONENT_PART)?
+ ;
+
+fragment DECIMAL_CONSTANT
+ : ('1'..'9')('0'..'9')*
+ ;
+
+fragment OCTAL_CONSTANT
+ : '0' ('0'..'7')*
+ ;
+
+fragment HEXADECIMAL_CONSTANT
+ : '0' ('x'|'X') HEXDIGIT+
+ ;
+
+fragment HEXDIGIT
+ : ('0'..'9'|'a'..'f'|'A'..'F')
+ ;
+
+INTCONSTANT
+ : DECIMAL_CONSTANT
+ | OCTAL_CONSTANT
+ | HEXADECIMAL_CONSTANT
+ ;
+
+fragment BOOLCONSTANT
+ : TRUE
+ | FALSE
+ ;
+
+// FIXME: this needs much more work
+field_selection
+ : IDENTIFIER
+ ;
+
+//LEFT_OP : '<<'; - reserved
+//RIGHT_OP : '>>'; - reserved
+
+INC_OP : '++';
+DEC_OP : '--';
+LE_OP : '<=';
+GE_OP : '>=';
+EQ_OP : '==';
+NE_OP : '!=';
+
+AND_OP : '&&';
+OR_OP : '||';
+XOR_OP : '^^';
+MUL_ASSIGN : '*=';
+DIV_ASSIGN : '/=';
+ADD_ASSIGN : '+=';
+MOD_ASSIGN : '%=';
+// LEFT_ASSIGN : '<<='; - reserved
+// RIGHT_ASSIGN : '>>='; - reserved
+// AND_ASSIGN : '&='; - reserved
+// XOR_ASSIGN : '^='; - reserved
+// OR_ASSIGN : '|='; - reserved
+SUB_ASSIGN : '-=';
+
+LEFT_PAREN : '(';
+RIGHT_PAREN : ')';
+LEFT_BRACKET : '[';
+RIGHT_BRACKET : ']';
+LEFT_BRACE : '{';
+RIGHT_BRACE : '}';
+DOT : '.';
+
+COMMA : ',';
+COLON : ':';
+EQUAL : '=';
+SEMICOLON : ';';
+BANG : '!';
+DASH : '-';
+TILDE : '~';
+PLUS : '+';
+STAR : '*';
+SLASH : '/';
+PERCENT : '%';
+
+LEFT_ANGLE : '<';
+RIGHT_ANGLE : '>';
+VERTICAL_BAR : '|';
+CARET : '^';
+AMPERSAND : '&';
+QUESTION : '?';
+
+// ----------------------------------------------------------------------
+// skipped elements
+
+WHITESPACE
+ : ( ' ' | '\t' | '\f' | '\r' | '\n' )
+ { $channel = HIDDEN; }
+ ;
+
+COMMENT
+ : '//' (~('\n'|'\r'))*
+ { $channel = HIDDEN; }
+ ;
+
+MULTILINE_COMMENT
+ : '/*' ( options {greedy=false;} : . )* '*/'
+ { $channel = HIDDEN; }
+ ;
+
+// ----------------------------------------------------------------------
+// Keywords reserved for future use
+
+//RESERVED_KEYWORDS
+// : 'asm'
+// | 'cast'
+// | 'class'
+// | 'default'
+// | 'double'
+// | 'dvec2'
+// | 'dvec3'
+// | 'dvec4'
+// | 'enum'
+// | 'extern'
+// | 'external'
+// | 'fixed'
+// | 'flat'
+// | 'fvec2'
+// | 'fvec3'
+// | 'fvec4'
+// | 'goto'
+// | 'half'
+// | 'hvec2'
+// | 'hvec3'
+// | 'hvec4'
+// | 'inline'
+// | 'input'
+// | 'interface'
+// | 'long'
+// | 'namespace'
+// | 'noinline'
+// | 'output'
+// | 'packed'
+// | 'public'
+// | 'sampler1D'
+// | 'sampler1DShadow'
+// | 'sampler2DRect'
+// | 'sampler2DRectShadow'
+// | 'sampler2DShadow'
+// | 'sampler3D'
+// | 'sampler3DRect'
+// | 'short'
+// | 'sizeof'
+// | 'static'
+// | 'superp'
+// | 'switch'
+// | 'template'
+// | 'this'
+// | 'typedef'
+// | 'union'
+// | 'unsigned'
+// | 'using'
+// | 'volatile'
+// ;
diff --git a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.l b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.l
new file mode 100644
index 0000000..07ab141
--- /dev/null
+++ b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.l
@@ -0,0 +1,221 @@
+ /*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+%{
+#include <stdio.h>
+#define YYSTYPE char *
+#include "GLSL_ES.tab.h"
+%}
+
+EXPONENT_PART [eE][+-]?[0-9]+
+
+DECIMAL_CONSTANT [1-9][0-9]*
+HEXADECIMAL_CONSTANT 0[xX][0-9a-fA-F]+
+OCTAL_CONSTANT 0[0-7]*
+
+%s IN_COMMENT
+%%
+
+ /**********************************************************************/
+ /* Keywords */
+ /**/
+
+attribute return ATTRIBUTE;
+bool return BOOL;
+break return BREAK;
+bvec2 return BVEC2;
+bvec3 return BVEC3;
+bvec4 return BVEC4;
+const return CONST;
+continue return CONTINUE;
+discard return DISCARD;
+do return DO;
+else return ELSE;
+false return FALSE;
+float return FLOAT;
+for return FOR;
+highp return HIGH_PRECISION;
+if return IF;
+in return IN;
+inout return INOUT;
+int return INT;
+invariant return INVARIANT;
+ivec2 return IVEC2;
+ivec3 return IVEC3;
+ivec4 return IVEC4;
+lowp return LOW_PRECISION;
+mat2 return MAT2;
+mat3 return MAT3;
+mat4 return MAT4;
+mediump return MEDIUM_PRECISION;
+out return OUT;
+precision return PRECISION;
+return return RETURN;
+sampler2D return SAMPLER2D;
+samplerCube return SAMPLERCUBE;
+struct return STRUCT;
+true return TRUE;
+uniform return UNIFORM;
+varying return VARYING;
+vec2 return VEC2;
+vec3 return VEC3;
+vec4 return VEC4;
+void return VOID;
+while return WHILE;
+
+ /**********************************************************************/
+ /* Basic tokens and operators */
+ /**/
+
+\/\/.* /* ignore single-line comments */;
+
+ /* Ignore C-style multi-line comments */
+<INITIAL>{
+"/*" BEGIN(IN_COMMENT);
+}
+<IN_COMMENT>{
+"*/" BEGIN(INITIAL);
+[^*\n]+ // eat comment in chunks
+"*" // eat the lone star
+\n yylineno++;
+}
+
+DECIMAL_CONSTANT |
+HEXADECIMAL_CONSTANT |
+OCTAL_CONSTANT yylval=strdup(yytext); return INTCONSTANT;
+
+[0-9]+\.[0-9]*{EXPONENT_PART}? |
+\.[0-9]+{EXPONENT_PART}? yylval=strdup(yytext); return FLOATCONSTANT;
+
+\n /* ignore EOL */;
+[ \t\r\f]+ /* ignore whitespace */;
+
+\+\+ return INC_OP;
+\-\- return DEC_OP;
+\<= return LE_OP;
+\>= return GE_OP;
+== return EQ_OP;
+!= return NE_OP;
+
+&& return AND_OP;
+\|\| return OR_OP;
+\^\^ return XOR_OP;
+\*= return MUL_ASSIGN;
+\/= return DIV_ASSIGN;
+\+= return ADD_ASSIGN;
+\%= return MOD_ASSIGN;
+-= return SUB_ASSIGN;
+
+\( return LEFT_PAREN;
+\) return RIGHT_PAREN;
+\[ return LEFT_BRACKET;
+\] return RIGHT_BRACKET;
+\{ return LEFT_BRACE;
+\} return RIGHT_BRACE;
+\. return DOT;
+
+, return COMMA;
+: return COLON;
+; return SEMICOLON;
+= return EQUAL;
+! return BANG;
+\- return DASH;
+~ return TILDE;
+\+ return PLUS;
+\* return STAR;
+\/ return SLASH;
+\% return PERCENT;
+
+\< return LEFT_ANGLE;
+\> return RIGHT_ANGLE;
+\| return VERTICAL_BAR;
+\^ return CARET;
+& return AMPERSAND;
+\? return QUESTION;
+
+ /* Catch-all for user identifiers */
+[a-zA-Z_][a-zA-Z0-9_]* yylval=strdup(yytext); return IDENTIFIER;
+
+ /**********************************************************************/
+ /* Keywords reserved for future use */
+ /**/
+
+ /**************************/
+ /* asm | */
+ /* cast | */
+ /* class | */
+ /* default | */
+ /* double | */
+ /* dvec2 | */
+ /* dvec3 | */
+ /* dvec4 | */
+ /* enum | */
+ /* extern | */
+ /* external | */
+ /* fixed | */
+ /* flat | */
+ /* fvec2 | */
+ /* fvec3 | */
+ /* fvec4 | */
+ /* goto | */
+ /* half | */
+ /* hvec2 | */
+ /* hvec3 | */
+ /* hvec4 | */
+ /* inline | */
+ /* input | */
+ /* interface | */
+ /* long | */
+ /* namespace | */
+ /* noinline | */
+ /* output | */
+ /* packed | */
+ /* public | */
+ /* sampler1D | */
+ /* sampler1DShadow | */
+ /* sampler2DRect | */
+ /* sampler2DRectShadow | */
+ /* sampler2DShadow | */
+ /* sampler3D | */
+ /* sampler3DRect | */
+ /* short | */
+ /* sizeof | */
+ /* static | */
+ /* superp | */
+ /* switch | */
+ /* template | */
+ /* this | */
+ /* typedef | */
+ /* union | */
+ /* unsigned | */
+ /* using | */
+ /* volatile | */
+%%
diff --git a/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y
new file mode 100644
index 0000000..16b5352
--- /dev/null
+++ b/o3d/compiler/glsl_validator/glsl_es/GLSL_ES.y
@@ -0,0 +1,599 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+%{
+#include <stdio.h>
+#include <string.h>
+
+#define YYSTYPE char *
+
+int yydebug=0;
+
+void yyerror(const char *str)
+{
+ fprintf(stderr,"error: %s\n",str);
+}
+
+int yywrap()
+{
+ return 1;
+}
+
+main()
+{
+ yyparse();
+}
+
+%}
+
+%token
+ INTCONSTANT FLOATCONSTANT IDENTIFIER
+
+ INC_OP DEC_OP LE_OP GE_OP EQ_OP NE_OP AND_OP OR_OP XOR_OP
+
+ MUL_ASSIGN DIV_ASSIGN ADD_ASSIGN MOD_ASSIGN SUB_ASSIGN
+
+ LEFT_PAREN RIGHT_PAREN LEFT_BRACKET RIGHT_BRACKET LEFT_BRACE RIGHT_BRACE DOT
+
+ COMMA COLON SEMICOLON EQUAL BANG DASH TILDE PLUS STAR SLASH PERCENT
+
+ LEFT_ANGLE RIGHT_ANGLE VERTICAL_BAR CARET AMPERSAND QUESTION
+
+ ATTRIBUTE BOOL BREAK BVEC2 BVEC3
+ BVEC4 CONST CONTINUE DISCARD DO
+ ELSE FALSE FLOAT FOR HIGH_PRECISION
+ IF IN INOUT INT INVARIANT
+ IVEC2 IVEC3 IVEC4 LOW_PRECISION MAT2
+ MAT3 MAT4 MEDIUM_PRECISION OUT PRECISION
+ RETURN SAMPLER2D SAMPLERCUBE STRUCT TRUE
+ UNIFORM VARYING VEC2 VEC3 VEC4
+ VOID WHILE
+
+%%
+
+/* Main entry point */
+translation_unit
+ : external_declaration
+ | translation_unit external_declaration
+
+/* FIXME: this requires much more work */
+FIELD_SELECTION
+ : IDENTIFIER
+ ;
+
+variable_identifier
+ : IDENTIFIER
+ ;
+
+primary_expression
+ : variable_identifier
+ | INTCONSTANT
+ | FLOATCONSTANT
+ | TRUE | FALSE
+ | primary_expression_1
+ ;
+
+primary_expression_1
+ : LEFT_PAREN expression RIGHT_PAREN
+ ;
+
+postfix_expression
+ : postfix_expression_1
+ | postfix_expression postfix_expression_2
+ ;
+
+postfix_expression_1
+ : primary_expression
+ | function_call
+ ;
+
+postfix_expression_2
+ : LEFT_BRACKET integer_expression RIGHT_BRACKET
+ | DOT FIELD_SELECTION
+ | INC_OP
+ | DEC_OP
+ ;
+
+integer_expression
+ : expression
+ ;
+
+function_call
+ : function_call_generic
+ ;
+
+function_call_generic
+ : function_call_header_with_parameters RIGHT_PAREN
+ | function_call_header_no_parameters RIGHT_PAREN
+ ;
+
+function_call_header_no_parameters
+ : function_call_header VOID
+ | function_call_header
+ ;
+
+function_call_header_with_parameters
+ : function_call_header assignment_expression
+ | function_call_header_with_parameters function_call_header_with_parameters_1
+ ;
+
+function_call_header_with_parameters_1
+ : COMMA assignment_expression
+ ;
+
+function_call_header
+ : function_identifier LEFT_PAREN
+ ;
+
+function_identifier
+ : constructor_identifier
+ | IDENTIFIER
+ ;
+
+constructor_identifier
+ : FLOAT
+ | INT
+ | BOOL
+ | VEC2
+ | VEC3
+ | VEC4
+ | BVEC2
+ | BVEC3
+ | BVEC4
+ | IVEC2
+ | IVEC3
+ | IVEC4
+ | MAT2
+ | MAT3
+ | MAT4
+// | TYPE_NAME
+ ;
+
+unary_expression
+ : postfix_expression
+ | INC_OP unary_expression
+ | DEC_OP unary_expression
+ | unary_operator unary_expression
+ ;
+
+/* Grammar Note: No traditional style type casts. */
+
+unary_operator
+ : PLUS
+ | DASH
+ | BANG
+/*| TILDE // reserved */
+ ;
+
+/* Grammar Note: No '*' or '&' unary ops. Pointers are not supported. */
+
+multiplicative_expression
+ : unary_expression
+ | multiplicative_expression multiplicative_expression_1
+ ;
+
+multiplicative_expression_1
+ : STAR unary_expression
+ | SLASH unary_expression
+/*| PERCENT unary_expression */
+ ;
+
+additive_expression
+ : multiplicative_expression
+ | additive_expression additive_expression_1
+ ;
+
+additive_expression_1
+ : PLUS multiplicative_expression
+ | DASH multiplicative_expression
+ ;
+
+shift_expression
+ : additive_expression
+/*| shift_expression LEFT_OP additive_expression // reserved */
+/*| shift_expression RIGHT_OP additive_expression // reserved */
+ ;
+
+relational_expression
+ : shift_expression
+ | relational_expression relational_expression_1
+ ;
+
+relational_expression_1
+ : LEFT_ANGLE shift_expression
+ | RIGHT_ANGLE shift_expression
+ | LE_OP shift_expression
+ | GE_OP shift_expression
+ ;
+
+equality_expression
+ : relational_expression
+ | equality_expression equality_expression_1
+ ;
+
+equality_expression_1
+ : EQ_OP relational_expression
+ | NE_OP relational_expression
+ ;
+
+and_expression
+ : equality_expression
+/*| and_expression AMPERSAND equality_expression // reserved */
+ ;
+
+exclusive_or_expression
+ : and_expression
+/*| exclusive_or_expression CARET and_expression // reserved */
+ ;
+
+inclusive_or_expression
+ : exclusive_or_expression
+/*| inclusive_or_expression VERTICAL_BAR exclusive_or_expression // reserved */
+ ;
+
+logical_and_expression
+ : inclusive_or_expression
+ | logical_and_expression logical_and_expression_1
+ ;
+
+logical_and_expression_1
+ : AND_OP inclusive_or_expression
+ ;
+
+logical_xor_expression
+ : logical_and_expression
+ | logical_xor_expression logical_xor_expression_1
+ ;
+
+logical_xor_expression_1
+ : XOR_OP logical_and_expression
+ ;
+
+logical_or_expression
+ : logical_xor_expression
+ | logical_or_expression logical_or_expression_1
+ ;
+
+logical_or_expression_1
+ : OR_OP logical_xor_expression
+ ;
+
+conditional_expression
+ : logical_or_expression
+ | logical_or_expression conditional_expression_1
+ ;
+
+/* NOTE (FIXME): difference between Mesa's grammar and GLSL ES spec;
+ Mesa uses conditional_expression after the colon, GLSL ES uses assignment_expression */
+conditional_expression_1
+ : QUESTION expression COLON assignment_expression
+ ;
+
+assignment_expression
+ : conditional_expression
+ | unary_expression assignment_operator assignment_expression
+ ;
+
+assignment_operator
+ : EQUAL
+ | MUL_ASSIGN
+ | DIV_ASSIGN
+/*| MOD_ASSIGN // reserved */
+ | ADD_ASSIGN
+ | SUB_ASSIGN
+/*| LEFT_ASSIGN // reserved */
+/*| RIGHT_ASSIGN // reserved */
+/*| AND_ASSIGN // reserved */
+/*| XOR_ASSIGN // reserved */
+/*| OR_ASSIGN // reserved */
+ ;
+
+expression
+ : assignment_expression
+ | expression expression_1
+ ;
+
+expression_1
+ : COMMA assignment_expression
+ ;
+
+constant_expression
+ : conditional_expression
+ ;
+
+declaration
+ : function_prototype SEMICOLON
+ | init_declarator_list SEMICOLON
+ | PRECISION precision_qualifier type_specifier_no_prec SEMICOLON
+ ;
+
+function_prototype
+ : function_declarator RIGHT_PAREN
+ ;
+
+function_declarator
+ : function_header
+ | function_header_with_parameters
+ ;
+
+function_header_with_parameters
+ : function_header parameter_declaration
+ | function_header_with_parameters function_header_with_parameters_1
+ ;
+
+function_header_with_parameters_1
+ : COMMA parameter_declaration
+ ;
+
+/* NOTE: Mesa grammar differs substantially in handling of types ("space" vs. "non-space") */
+function_header
+ : fully_specified_type IDENTIFIER LEFT_PAREN
+ ;
+
+parameter_declarator
+ : type_specifier IDENTIFIER
+ | type_specifier IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
+ ;
+
+/* NOTE: difference between both Mesa and ANTLR grammars */
+parameter_declaration
+ : type_qualifier parameter_qualifier parameter_declarator
+ | parameter_qualifier parameter_declarator
+ | type_qualifier parameter_qualifier parameter_type_specifier
+ | parameter_qualifier parameter_type_specifier
+ ;
+
+/* NOTE empty arm at beginning */
+parameter_qualifier
+ :
+ | IN
+ | OUT
+ | INOUT
+ ;
+
+parameter_type_specifier
+ : type_specifier
+ | type_specifier LEFT_BRACKET constant_expression RIGHT_BRACKET
+ ;
+
+init_declarator_list
+ : single_declaration
+ | single_declaration init_declarator_list_1
+ ;
+
+init_declarator_list_1
+ : COMMA IDENTIFIER init_declarator_list_2
+ ;
+
+init_declarator_list_2
+ : init_declarator_list_3
+ | init_declarator_list_4
+ | /* empty */
+ ;
+
+init_declarator_list_3
+ : LEFT_BRACKET constant_expression RIGHT_BRACKET
+ ;
+
+init_declarator_list_4
+ : EQUAL initializer
+ ;
+
+/* NOTE: significant differences between this formulation and Mesa's */
+single_declaration
+ : fully_specified_type
+ | fully_specified_type IDENTIFIER
+ | fully_specified_type IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
+ | fully_specified_type IDENTIFIER EQUAL initializer
+ | INVARIANT IDENTIFIER // Vertex only.
+ ;
+
+/* Grammar Note: No 'enum', or 'typedef'. */
+
+fully_specified_type
+ : type_specifier
+ | type_qualifier type_specifier
+ ;
+
+type_qualifier
+ : CONST
+ | ATTRIBUTE // Vertex only.
+ | VARYING
+ | INVARIANT VARYING
+ | UNIFORM
+ ;
+
+type_specifier
+ : type_specifier_no_prec
+ | precision_qualifier type_specifier_no_prec
+ ;
+
+type_specifier_no_prec
+ : VOID
+ | FLOAT
+ | INT
+ | BOOL
+ | VEC2
+ | VEC3
+ | VEC4
+ | BVEC2
+ | BVEC3
+ | BVEC4
+ | IVEC2
+ | IVEC3
+ | IVEC4
+ | MAT2
+ | MAT3
+ | MAT4
+ | SAMPLER2D
+ | SAMPLERCUBE
+ | struct_specifier
+// | TYPE_NAME
+ ;
+
+precision_qualifier
+ : HIGH_PRECISION
+ | MEDIUM_PRECISION
+ | LOW_PRECISION
+ ;
+
+struct_specifier
+ : STRUCT IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE
+ | STRUCT LEFT_BRACE struct_declaration_list RIGHT_BRACE
+ ;
+
+struct_declaration_list
+ : struct_declaration
+ | struct_declaration struct_declaration_list_1
+ ;
+
+struct_declaration_list_1
+ : struct_declaration struct_declaration_list
+ ;
+
+struct_declaration
+ : type_specifier struct_declarator_list SEMICOLON
+ ;
+
+/* NOTE difference with spec grammar in where recursion occurs */
+struct_declarator_list
+ : struct_declarator
+ | struct_declarator struct_declarator_list_1
+ ;
+
+/* NOTE difference with Mesa grammar */
+struct_declarator_list_1
+ : COMMA struct_declarator_list
+ ;
+
+struct_declarator
+ : IDENTIFIER
+ | IDENTIFIER LEFT_BRACKET constant_expression RIGHT_BRACKET
+ ;
+
+initializer
+ : assignment_expression
+ ;
+
+declaration_statement
+ : declaration
+ ;
+
+statement_no_new_scope
+ : compound_statement_with_scope
+ | simple_statement
+ ;
+
+simple_statement
+ : declaration_statement
+ | expression_statement
+ | selection_statement
+ | iteration_statement
+ | jump_statement
+ ;
+
+compound_statement_with_scope
+ : LEFT_BRACE RIGHT_BRACE
+ | LEFT_BRACE statement_list RIGHT_BRACE
+ ;
+
+statement_with_scope
+ : compound_statement_no_new_scope
+ | simple_statement
+ ;
+
+compound_statement_no_new_scope
+ : LEFT_BRACE RIGHT_BRACE
+ | LEFT_BRACE statement_list RIGHT_BRACE
+ ;
+
+/* FIXME: may need refactoring */
+statement_list
+ : statement_no_new_scope
+ | statement_list statement_no_new_scope
+ ;
+
+expression_statement
+ : SEMICOLON
+ | expression SEMICOLON
+ ;
+
+selection_statement
+ : IF LEFT_PAREN expression RIGHT_PAREN selection_rest_statement
+ ;
+
+selection_rest_statement
+ : statement_with_scope ELSE statement_with_scope
+ | statement_with_scope
+ ;
+
+condition
+ : expression
+ | fully_specified_type IDENTIFIER EQUAL initializer
+ ;
+
+iteration_statement
+ : WHILE LEFT_PAREN condition RIGHT_PAREN statement_no_new_scope
+ | DO statement_with_scope WHILE LEFT_PAREN expression RIGHT_PAREN SEMICOLON
+ | FOR LEFT_PAREN for_init_statement for_rest_statement RIGHT_PAREN statement_no_new_scope
+ ;
+
+for_init_statement
+ : expression_statement
+ | declaration_statement
+ ;
+
+conditionopt
+ : condition
+ | /* empty */
+ ;
+
+for_rest_statement
+ : conditionopt SEMICOLON
+ | conditionopt SEMICOLON expression
+ ;
+
+jump_statement
+ : CONTINUE SEMICOLON
+ | BREAK SEMICOLON
+ | RETURN SEMICOLON
+ | RETURN expression SEMICOLON
+ | DISCARD SEMICOLON // Fragment shader only.
+ ;
+
+external_declaration
+ : function_definition
+ | declaration
+ ;
+
+function_definition
+ : function_prototype compound_statement_no_new_scope
+ ;
diff --git a/o3d/compiler/glsl_validator/shaders/ambient.frag b/o3d/compiler/glsl_validator/shaders/ambient.frag
new file mode 100644
index 0000000..1e46e4d
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/ambient.frag
@@ -0,0 +1,10 @@
+// Modified from shader at
+// http://nehe.gamedev.net/data/articles/article.asp?article=21
+
+uniform vec4 g_Color;
+
+void main()
+{
+ // Set each pixel to a constant color
+ gl_FragColor = g_Color;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/ambient.vert b/o3d/compiler/glsl_validator/shaders/ambient.vert
new file mode 100644
index 0000000..7d90a80
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/ambient.vert
@@ -0,0 +1,11 @@
+// Modified from shader at
+// http://nehe.gamedev.net/data/articles/article.asp?article=21
+
+uniform mat4 g_ModelViewProjectionMatrix;
+
+attribute vec3 g_Vertex;
+
+void main()
+{
+ gl_Position = g_ModelViewProjectionMatrix * g_Vertex;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/diffuse.frag b/o3d/compiler/glsl_validator/shaders/diffuse.frag
new file mode 100644
index 0000000..c3c91f9
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/diffuse.frag
@@ -0,0 +1,22 @@
+// Modified from shader at
+// http://nehe.gamedev.net/data/articles/article.asp?article=21
+
+varying vec3 normal;
+varying vec3 vertex_to_light_vector;
+
+void main()
+{
+ // Defining The Material Colors
+ const vec4 AMBIENT_COLOR = vec4(0.1, 0.0, 0.0, 1.0);
+ const vec4 DIFFUSE_COLOR = vec4(1.0, 0.0, 0.0, 1.0);
+
+ // Scaling The Input Vector To Length 1
+ vec3 normalized_normal = normalize(normal);
+ vec3 normalized_vertex_to_light_vector = normalize(vertex_to_light_vector);
+
+ // Calculating The Diffuse Term And Clamping It To [0;1]
+ float diffuseTerm = clamp(dot(normal, vertex_to_light_vector), 0.0, 1.0);
+
+ // Calculating The Final Color
+ gl_FragColor = AMBIENT_COLOR + DIFFUSE_COLOR * diffuseTerm;
+}
diff --git a/o3d/compiler/glsl_validator/shaders/diffuse.vert b/o3d/compiler/glsl_validator/shaders/diffuse.vert
new file mode 100644
index 0000000..a51b22a
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/diffuse.vert
@@ -0,0 +1,28 @@
+// Modified from shader at
+// http://nehe.gamedev.net/data/articles/article.asp?article=21
+
+uniform mat4 g_ModelViewProjectionMatrix;
+uniform mat4 g_ModelViewMatrix;
+uniform mat4 g_NormalMatrix;
+uniform vec4 g_LightSource0Position;
+
+attribute vec3 g_Vertex;
+attribute vec3 g_Normal;
+
+varying vec3 normal;
+varying vec3 vertex_to_light_vector;
+
+void main()
+{
+ // Transforming The Vertex
+ gl_Position = g_ModelViewProjectionMatrix * g_Vertex;
+
+ // Transforming The Normal To ModelView-Space
+ normal = g_NormalMatrix * g_Normal;
+
+ // Transforming The Vertex Position To ModelView-Space
+ vec4 vertex_in_modelview_space = g_ModelViewMatrix * g_Vertex;
+
+ // Calculating The Vector From The Vertex Position To The Light Position
+ vertex_to_light_vector = vec3(g_LightSource0Position - vertex_in_modelview_space);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/texture_mapping.frag b/o3d/compiler/glsl_validator/shaders/texture_mapping.frag
new file mode 100644
index 0000000..49cc9d0
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/texture_mapping.frag
@@ -0,0 +1,12 @@
+// Modified from shader at
+// http://nehe.gamedev.net/data/articles/article.asp?article=21
+
+uniform sampler2D my_color_texture;
+
+varying vec2 texture_coordinate;
+
+void main()
+{
+ // Sampling The Texture And Passing It To The Frame Buffer
+ gl_FragColor = texture2D(my_color_texture, texture_coordinate);
+}
diff --git a/o3d/compiler/glsl_validator/shaders/texture_mapping.vert b/o3d/compiler/glsl_validator/shaders/texture_mapping.vert
new file mode 100644
index 0000000..de653b4
--- /dev/null
+++ b/o3d/compiler/glsl_validator/shaders/texture_mapping.vert
@@ -0,0 +1,18 @@
+// Modified from shader at
+// http://nehe.gamedev.net/data/articles/article.asp?article=21
+
+uniform mat4 g_ModelViewProjectionMatrix;
+
+attribute vec3 g_Vertex;
+attribute vec4 g_MultiTexCoord0;
+
+varying vec2 texture_coordinate;
+
+void main()
+{
+ // Transforming The Vertex
+ gl_Position = g_ModelViewProjectionMatrix * g_Vertex;
+
+ // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader
+ texture_coordinate = vec2(g_MultiTexCoord0);
+}
diff --git a/o3d/compiler/glsl_validator/test/Main.java b/o3d/compiler/glsl_validator/test/Main.java
new file mode 100644
index 0000000..e462cba
--- /dev/null
+++ b/o3d/compiler/glsl_validator/test/Main.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package test;
+
+import java.io.*;
+import org.antlr.runtime.*;
+import glsl_es.*;
+
+public class Main {
+ public static void main(String[] args) {
+ for (String str : args) {
+ parseFile(str);
+ }
+ }
+
+ private static void parseFile(String f) {
+ try {
+ long startTime = System.currentTimeMillis();
+ GLSL_ESLexer lexer = new GLSL_ESLexer(new ANTLRFileStream(f, "iso8859-1"));
+ TokenRewriteStream tokens = new TokenRewriteStream(lexer);
+ tokens.LT(1);
+ // Create a parser that reads from the scanner
+ GLSL_ESParser parser = new GLSL_ESParser(tokens);
+ // Parse the translation unit
+ parser.translation_unit();
+ long endTime = System.currentTimeMillis();
+ System.out.println("Parsing " + f + " took " + (endTime - startTime) + " ms");
+ } catch (Exception e) {
+ System.out.println("While parsing " + f + ":");
+ e.printStackTrace();
+ }
+ }
+}