Changeset 1413


Ignore:
Timestamp:
May 24, 2012, 7:00:36 PM (8 years ago)
Author:
sam
Message:

test: more grammar improvements.

Location:
trunk/test/sandbox/lex
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/sandbox/lex/Makefile

    r1409 r1413  
    99        flex -d $^
    1010
     11clean:
     12        rm -f lex.yy.c lolfx.tab.c lolfx.tab.h parser
  • trunk/test/sandbox/lex/lolfx.l

    r1412 r1413  
    5757"usampler2dmsarray"          { return GT_USAMPLER2DMSARRAY; }
    5858
    59 "identifier"                 { return GT_IDENTIFIER; }
    60 "type_name"                  { return GT_TYPE_NAME; }
    61 "floatconstant"              { return GT_FLOATCONSTANT; }
    62 "intconstant"                { return GT_INTCONSTANT; }
    63 "uintconstant"               { return GT_UINTCONSTANT; }
    64 "boolconstant"               { return GT_BOOLCONSTANT; }
    65 
    66 "field_selection"            { return GT_FIELD_SELECTION; }
    67 "left_op"                    { return GT_LEFT_OP; }
    68 "right_op"                   { return GT_RIGHT_OP; }
    69 "and_op"                     { return GT_AND_OP; }
    70 "or_op"                      { return GT_OR_OP; }
    71 "xor_op"                     { return GT_XOR_OP; }
    72 "mul_assign"                 { return GT_MUL_ASSIGN; }
    73 "div_assign"                 { return GT_DIV_ASSIGN; }
    74 "add_assign"                 { return GT_ADD_ASSIGN; }
    75 "mod_assign"                 { return GT_MOD_ASSIGN; }
    76 "left_assign"                { return GT_LEFT_ASSIGN; }
    77 "right_assign"               { return GT_RIGHT_ASSIGN; }
    78 "and_assign"                 { return GT_AND_ASSIGN; }
    79 "xor_assign"                 { return GT_XOR_ASSIGN; }
    80 "or_assign"                  { return GT_OR_ASSIGN; }
    81 "sub_assign"                 { return GT_SUB_ASSIGN; }
    82 "left_paren"                 { return GT_LEFT_PAREN; }
    83 "right_paren"                { return GT_RIGHT_PAREN; }
    84 "left_bracket"               { return GT_LEFT_BRACKET; }
    85 "right_bracket"              { return GT_RIGHT_BRACKET; }
    86 "left_brace"                 { return GT_LEFT_BRACE; }
    87 "right_brace"                { return GT_RIGHT_BRACE; }
    88 "dot"                        { return GT_DOT; }
    89 "comma"                      { return GT_COMMA; }
    90 "colon"                      { return GT_COLON; }
    91 "equal"                      { return GT_EQUAL; }
    92 "semicolon"                  { return GT_SEMICOLON; }
    93 "bang"                       { return GT_BANG; }
    94 "dash"                       { return GT_DASH; }
    95 "tilde"                      { return GT_TILDE; }
    96 "plus"                       { return GT_PLUS; }
    97 "star"                       { return GT_STAR; }
    98 "slash"                      { return GT_SLASH; }
    99 "percent"                    { return GT_PERCENT; }
    100 "left_angle"                 { return GT_LEFT_ANGLE; }
    101 "right_angle"                { return GT_RIGHT_ANGLE; }
    102 "vertical_bar"               { return GT_VERTICAL_BAR; }
    103 "caret"                      { return GT_CARET; }
    104 "ampersand"                  { return GT_AMPERSAND; }
    105 "question"                   { return GT_QUESTION; }
     59"highp"                      { return GT_HIGHP; }
     60"mediump"                    { return GT_MEDIUMP; }
     61"lowp"                       { return GT_LOWP; }
     62"precision"                  { return GT_PRECISION; }
    10663"invariant"                  { return GT_INVARIANT; }
    107 "high_precision"             { return GT_HIGH_PRECISION; }
    108 "medium_precision"           { return GT_MEDIUM_PRECISION; }
    109 "low_precision"              { return GT_LOW_PRECISION; }
    110 "precision"                  { return GT_PRECISION; }
    11164
    11265 /*
     
    157110"dmat4x3"                    { return GT_DMAT4X3; }
    158111"dmat4x4"                    { return GT_DMAT4X4; }
     112
     113 /*
     114  * GLSL constant values
     115  */
     116
     117"true"                       { yylval.ival = 1; return BOOLCONSTANT; }
     118"false"                      { yylval.ival = 0; return BOOLCONSTANT; }
     119
     120[xyzw]{1,4}                  { return FIELDSELECTION; }
     121[rgba]{1,4}                  { return FIELDSELECTION; }
     122[stpq]{1,4}                  { return FIELDSELECTION; }
    159123
    160124 /*
     
    471435
    472436 /*
     437  * LolFx preprocessor directives
     438  */
     439
     440"#"[ \t]*"region"            { return PREPROCESSOR_REGION; }
     441
     442 /*
    473443  * HLSL reserved keywords
    474444  * Gathered from http://msdn.microsoft.com/en-us/library/windows/desktop/bb509569%28v=vs.85%29.aspx
     
    535505"|="                    { return T_OREQ; }
    536506
    537 [0-9]+\.[0-9]+ { yylval.fval = atof(yytext); return FLOAT; }
    538 [0-9]+         { yylval.ival = atoi(yytext); return INT; }
     507(0|[1-9][0-9]*)\.[0-9]+ { yylval.fval = atof(yytext); return FLOATCONSTANT; }
     508(0|[1-9][0-9]*)[uU]     { yylval.uval = atoi(yytext); return UINTCONSTANT; }
     509(0|[1-9][0-9]*)         { yylval.ival = atoi(yytext); return INTCONSTANT; }
     510
    539511[a-zA-Z][a-zA-Z0-9_]*   {
    540512    /* Copy token for now */
    541513    yylval.sval = strdup(yytext);
    542     return NAME;
     514    return IDENTIFIER;
    543515}
    544 [ \t\n]+       ;
    545 "{"|"}"|"("|")"|"["|"]" { return *yytext; }
     516[ \t\n]+                { /* ignore whitespace */ }
    546517.                       { return *yytext; }
    547518
  • trunk/test/sandbox/lex/lolfx.y

    r1412 r1413  
    1515{
    1616    int ival;
     17    unsigned uval;
    1718    float fval;
    1819    char *sval;
    1920}
    2021
     22%type <sval> lolfx_shader_name
     23
     24 /*
     25  * GLSL and HLSL generic tokens
     26  */
     27
     28%token <ival> BOOLCONSTANT
     29%token <ival> INTCONSTANT
     30%token <uval> UINTCONSTANT
     31%token <fval> FLOATCONSTANT
     32%token /* TODO */ FIELDSELECTION
     33%token <sval> IDENTIFIER
     34%token <sval> TYPENAME
     35
    2136 /*
    2237  * GLSL keywords
     
    2540
    2641%token GT_SUBROUTINE GT_PATCH GT_SAMPLE GT_FLAT GT_SMOOTH GT_LAYOUT
    27 %token GT_SAMPLER1DSHADOW GT_SAMPLER2DSHADOW GT_SAMPLERCUBESHADOW
    28 %token GT_SAMPLER1DARRAY GT_SAMPLER2DARRAY GT_SAMPLER1DARRAYSHADOW
    29 %token GT_SAMPLER2DARRAYSHADOW GT_ISAMPLER1D GT_ISAMPLER2D GT_ISAMPLER3D
    30 %token GT_ISAMPLERCUBE GT_ISAMPLER1DARRAY GT_ISAMPLER2DARRAY GT_USAMPLER1D
    31 %token GT_USAMPLER2D GT_USAMPLER3D GT_USAMPLERCUBE GT_USAMPLER1DARRAY
    32 %token GT_USAMPLER2DARRAY GT_SAMPLER2DRECT GT_SAMPLER2DRECTSHADOW
    33 %token GT_ISAMPLER2DRECT GT_USAMPLER2DRECT GT_SAMPLERBUFFER GT_ISAMPLERBUFFER
    34 %token GT_USAMPLERBUFFER GT_SAMPLERCUBEARRAY GT_SAMPLERCUBEARRAYSHADOW
    35 %token GT_ISAMPLERCUBEARRAY GT_USAMPLERCUBEARRAY GT_SAMPLER2DMS GT_ISAMPLER2DMS
    36 %token GT_USAMPLER2DMS GT_SAMPLER2DMSARRAY GT_ISAMPLER2DMSARRAY
    37 %token GT_USAMPLER2DMSARRAY GT_IDENTIFIER GT_TYPE_NAME GT_FLOATCONSTANT
    38 %token GT_INTCONSTANT GT_UINTCONSTANT GT_BOOLCONSTANT GT_FIELD_SELECTION
    39 %token GT_LEFT_OP GT_RIGHT_OP GT_INC_OP GT_DEC_OP GT_LE_OP GT_GE_OP GT_EQ_OP
    40 %token GT_NE_OP GT_AND_OP GT_OR_OP GT_XOR_OP GT_MUL_ASSIGN GT_DIV_ASSIGN
    41 %token GT_ADD_ASSIGN GT_MOD_ASSIGN GT_LEFT_ASSIGN GT_RIGHT_ASSIGN GT_AND_ASSIGN
    42 %token GT_XOR_ASSIGN GT_OR_ASSIGN GT_SUB_ASSIGN GT_LEFT_PAREN GT_RIGHT_PAREN
    43 %token GT_LEFT_BRACKET GT_RIGHT_BRACKET GT_LEFT_BRACE GT_RIGHT_BRACE GT_DOT
    44 %token GT_COMMA GT_COLON GT_EQUAL GT_SEMICOLON GT_BANG GT_DASH GT_TILDE GT_PLUS
    45 %token GT_STAR GT_SLASH GT_PERCENT GT_LEFT_ANGLE GT_RIGHT_ANGLE GT_VERTICAL_BAR
    46 %token GT_CARET GT_AMPERSAND GT_QUESTION GT_INVARIANT GT_HIGH_PRECISION
    47 %token GT_MEDIUM_PRECISION GT_LOW_PRECISION GT_PRECISION GT_BVEC2 GT_BVEC3
    48 %token GT_BVEC4 GT_IVEC2 GT_IVEC3 GT_IVEC4 GT_UVEC2 GT_UVEC3 GT_UVEC4 GT_VEC2
    49 %token GT_VEC3 GT_VEC4 GT_MAT2 GT_MAT2X2 GT_MAT2X3 GT_MAT2X4 GT_MAT3 GT_MAT3X2
    50 %token GT_MAT3X3 GT_MAT3X4 GT_MAT4 GT_MAT4X2 GT_MAT4X3 GT_MAT4X4 GT_DVEC2
    51 %token GT_DVEC3 GT_DVEC4 GT_DMAT2 GT_DMAT2X2 GT_DMAT2X3 GT_DMAT2X4 GT_DMAT3
    52 %token GT_DMAT3X2 GT_DMAT3X3 GT_DMAT3X4 GT_DMAT4 GT_DMAT4X2 GT_DMAT4X3
    53 %token GT_DMAT4X4
     42%token GT_INVARIANT GT_HIGHP GT_MEDIUMP GT_LOWP GT_PRECISION
     43
     44 /*
     45  * GLSL types
     46  */
     47
     48%token GT_VEC2 GT_VEC3 GT_VEC4
     49%token GT_BVEC2 GT_BVEC3 GT_BVEC4
     50%token GT_DVEC2 GT_DVEC3 GT_DVEC4
     51%token GT_IVEC2 GT_IVEC3 GT_IVEC4
     52%token GT_UVEC2 GT_UVEC3 GT_UVEC4
     53
     54%token GT_MAT2 GT_MAT2X2 GT_MAT2X3 GT_MAT2X4
     55%token GT_MAT3 GT_MAT3X2 GT_MAT3X3 GT_MAT3X4
     56%token GT_MAT4 GT_MAT4X2 GT_MAT4X3 GT_MAT4X4
     57%token GT_DMAT2 GT_DMAT2X2 GT_DMAT2X3 GT_DMAT2X4
     58%token GT_DMAT3 GT_DMAT3X2 GT_DMAT3X3 GT_DMAT3X4
     59%token GT_DMAT4 GT_DMAT4X2 GT_DMAT4X3 GT_DMAT4X4
     60
     61%token GT_SAMPLER1DSHADOW GT_SAMPLER1DARRAY GT_SAMPLER1DARRAYSHADOW
     62%token GT_SAMPLER2DSHADOW GT_SAMPLER2DARRAY GT_SAMPLER2DARRAYSHADOW
     63%token GT_SAMPLER2DRECT GT_SAMPLER2DRECTSHADOW
     64%token GT_SAMPLER2DMS GT_SAMPLER2DMSARRAY
     65%token GT_SAMPLERCUBESHADOW GT_SAMPLERCUBEARRAY GT_SAMPLERCUBEARRAYSHADOW
     66%token GT_SAMPLERBUFFER
     67
     68%token GT_ISAMPLER1D GT_ISAMPLER1DARRAY
     69%token GT_ISAMPLER2D GT_ISAMPLER2DARRAY
     70%token GT_ISAMPLER2DRECT
     71%token GT_ISAMPLER2DMS GT_ISAMPLER2DMSARRAY
     72%token GT_ISAMPLER3D
     73%token GT_ISAMPLERCUBE GT_ISAMPLERCUBEARRAY
     74%token GT_ISAMPLERBUFFER
     75
     76%token GT_USAMPLER1D GT_USAMPLER1DARRAY
     77%token GT_USAMPLER2D GT_USAMPLER2DARRAY
     78%token GT_USAMPLER2DRECT
     79%token GT_USAMPLER2DMS GT_USAMPLER2DMSARRAY
     80%token GT_USAMPLER3D
     81%token GT_USAMPLERCUBE GT_USAMPLERCUBEARRAY
     82%token GT_USAMPLERBUFFER
    5483
    5584 /*
     
    140169%token PREPROCESSOR_IFDEF PREPROCESSOR_IFNDEF PREPROCESSOR_INCLUDE
    141170%token PREPROCESSOR_LINE PREPROCESSOR_PRAGMA PREPROCESSOR_UNDEF
     171%token PREPROCESSOR_REGION
    142172
    143173 /*
     
    170200%%
    171201
    172 fx:
    173     section_list
    174     ;
    175 
    176 section_list:
    177     section
    178     | section_list section
    179     ;
    180 
    181 section:
    182     technique
    183     | shader
     202lolfx_file:
     203    lolfx_section_list
     204    ;
     205
     206lolfx_section_list:
     207    lolfx_section
     208    | lolfx_section_list lolfx_section
     209    ;
     210
     211lolfx_section:
     212    lolfx_technique
     213    | lolfx_shader
    184214    ;
    185215
     
    188218  */
    189219
    190 technique:
     220lolfx_technique:
    191221    HT_TECHNIQUE NAME '{' pass_list '}' { std::cout << "New tech" << std::endl; }
    192222    ;
     
    219249
    220250 /*
     251  * Grammar for shaders
     252  */
     253
     254lolfx_shader:
     255    lolfx_shader_region glsl_translation_unit
     256    | lolfx_shader_region
     257    ;
     258
     259lolfx_shader_region:
     260    PREPROCESSOR_REGION lolfx_shader_name { std::cout << "new shader " << $2 << std::endl; }
     261    ;
     262
     263lolfx_shader_name:
     264    IDENTIFIER                            { $$ = $1; }
     265    | lolfx_shader_name '.' IDENTIFIER    { $$ = $3; } /* FIXME: concatenate */
     266    ;
     267
     268 /*
    221269  * Grammar for GLSL
    222270  */
    223271
    224272glsl_variable_identifier:
    225     GLSL_IDENTIFIER
     273    IDENTIFIER
    226274    ;
    227275
     
    239287    | glsl_postfix_expression '[' glsl_integer_expression ']'
    240288    | glsl_function_call
    241     | glsl_postfix_expression '.' FIELD_SELECTION
     289    | glsl_postfix_expression '.' FIELDSELECTION
    242290    | glsl_postfix_expression T_INC
    243291    | glsl_postfix_expression T_DEC
     
    279327    glsl_type_specifier
    280328    | IDENTIFIER
    281     | FIELD_SELECTION
     329    | FIELDSELECTION
    282330    ;
    283331
     
    395443    glsl_function_prototype ';'
    396444    | glsl_init_declarator_list ';'
    397     | PRECISION glsl_precision_qualifier glsl_type_specifier_no_prec ';'
     445    | GT_PRECISION glsl_precision_qualifier glsl_type_specifier_no_prec ';'
    398446    | glsl_type_qualifier IDENTIFIER '{' glsl_struct_declaration_list '}' ';'
    399447    | glsl_type_qualifier IDENTIFIER '{' glsl_struct_declaration_list '}' IDENTIFIER ';'
     
    462510    | glsl_fully_specified_type IDENTIFIER '[' glsl_constant_expression ']' '=' glsl_initializer
    463511    | glsl_fully_specified_type IDENTIFIER '=' glsl_initializer
    464     | INVARIANT IDENTIFIER
     512    | GT_INVARIANT IDENTIFIER
    465513    ;
    466514
     
    471519
    472520glsl_invariant_qualifier:
    473     INVARIANT
     521    GT_INVARIANT
    474522    ;
    475523
     
    619667    | GT_USAMPLER2DMSARRAY
    620668    | glsl_struct_specifier
    621     | TYPE_NAME
     669    | TYPENAME
    622670    ;
    623671
    624672glsl_precision_qualifier:
    625     HIGH_PRECISION
    626     | MEDIUM_PRECISION
    627     | LOW_PRECISION
     673    GT_HIGHP
     674    | GT_MEDIUMP
     675    | GT_LOWP
    628676    ;
    629677
     
    761809glsl_translation_unit:
    762810    glsl_external_declaration
    763     glsl_translation_unit glsl_external_declaration
     811    | glsl_translation_unit glsl_external_declaration
    764812    ;
    765813
     
    771819glsl_function_definition:
    772820    glsl_function_prototype glsl_compound_statement_no_new_scope
    773     ;
    774 
    775  /*
    776   * Grammar for shaders
    777   */
    778 
    779 shader:
    780     shader_region shader_code
    781     | shader_region
    782     ;
    783 
    784 shader_region:
    785     '#' NAME shader_name { std::cout << "new shader " << $2 << std::endl; }
    786     ;
    787 
    788 shader_name:
    789     NAME
    790     | shader_name '.' NAME
    791     ;
    792 
    793 shader_code:
    794     INT shader_code      { std::cout << "int: " << $1 << std::endl; }
    795     | FLOAT shader_code  { std::cout << "float: " << $1 << std::endl; }
    796     | STRING shader_code { std::cout << "string: " << $1 << std::endl; }
    797     | INT            { std::cout << "int: " << $1 << std::endl; }
    798     | FLOAT          { std::cout << "float: " << $1 << std::endl; }
    799     | STRING         { std::cout << "string: " << $1 << std::endl; }
    800821    ;
    801822
Note: See TracChangeset for help on using the changeset viewer.