Ignore:
Timestamp:
Jul 8, 2012, 12:25:52 AM (9 years ago)
Author:
sam
Message:

core: start working on a higher level LolFx compiler based on the latest
GLSL grammar and some personal attempts at writing an HLSL grammar.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/gpu/lolfx-parser.y

    r1589 r1590  
    11%{
    2 #include <cstdio>
    3 #include <iostream>
    4 
    5 extern "C" int yylex();
    6 extern "C" int yyparse();
    7 extern "C" FILE *yyin;
    8 extern "C" int yylineno;
    9 
    10 void yyerror(const char *s);
     2//
     3// Lol Engine
     4//
     5// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
     6//   This program is free software; you can redistribute it and/or
     7//   modify it under the terms of the Do What The Fuck You Want To
     8//   Public License, Version 2, as published by Sam Hocevar. See
     9//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
     10//
     11
     12#if defined HAVE_CONFIG_H
     13#   include "config.h"
     14#endif
     15
     16#include "core.h"
     17
     18#include <string>
     19
    1120%}
     21
     22%require "2.3"
     23%debug
     24%defines
     25%skeleton "lalr1.cc"
     26%name-prefix="lol"
     27%define parser_class_name "LolFxParser"
     28%locations
     29%parse-param { class LolFxCompiler& mc }
     30%error-verbose
    1231
    1332/* The classic Bison union trick */
     
    2039}
    2140
    22 %type <sval> lolfx_shader_name
     41/* %type <sval> lolfx_shader_name */
    2342
    2443 /*
     
    181200%token PREPROCESSOR_REGION
    182201
     202%token PRAGMA_LOLFX
     203
    183204 /*
    184205  * HLSL reserved keywords
     
    208229
    209230 /*
     231  * Special tokens
     232  */
     233
     234%token T_END 0
     235%token T_ERROR
     236
     237 /*
    210238  * Our entry point
    211239  */
    212240
    213241%start lolfx_file
     242
     243%{
     244#include "gpu/lolfx-compiler.h"
     245
     246#undef yylex
     247#define yylex mc.m_lexer->lex
     248%}
    214249
    215250%%
     
    692727
    693728lolfx_technique:
    694     HT_TECHNIQUE IDENTIFIER '{' pass_list '}' { std::cout << "New tech" << std::endl; }
     729    HT_TECHNIQUE IDENTIFIER '{' pass_list '}' { std::cout << "New tech " << $2 << std::endl; }
    695730    ;
    696731
     
    705740
    706741pass:
    707     HT_PASS IDENTIFIER '{' pass_stmt_list '}' { std::cout << "New pass" << std::endl; }
     742    HT_PASS IDENTIFIER '{' pass_stmt_list '}' { std::cout << "New pass " << $2 << std::endl; }
    708743    ;
    709744
     
    737772
    738773lolfx_shader:
    739     lolfx_shader_region glsl_translation_unit
    740   | lolfx_shader_region
    741     ;
    742 
    743 lolfx_shader_region:
    744     PREPROCESSOR_REGION lolfx_shader_name { std::cout << "new shader " << $2 << std::endl; }
    745     ;
    746 
    747 lolfx_shader_name:
    748     IDENTIFIER                            { $$ = $1; }
    749   | lolfx_shader_name '.' IDENTIFIER      { $$ = $3; } /* FIXME: concatenate */
     774    lolfx_shader_declaration glsl_translation_unit
     775    ;
     776
     777lolfx_shader_declaration:
     778    PRAGMA_LOLFX lolfx_shader_type '(' lolfx_shader_description_list ')' { std::cout << "new shader" << std::endl; }
     779    ;
     780
     781lolfx_shader_type:
     782    HT_VERTEXSHADER
     783  | HT_PIXELSHADER
     784    ;
     785
     786lolfx_shader_description_list:
     787    lolfx_shader_description ',' lolfx_shader_description
     788  | lolfx_shader_description
     789    ;
     790
     791lolfx_shader_description:
     792    IDENTIFIER '=' IDENTIFIER FLOATCONSTANT
     793  | IDENTIFIER '=' IDENTIFIER
    750794    ;
    751795
     
    13091353%%
    13101354
    1311 main()
     1355void lol::LolFxParser::error(const LolFxParser::location_type& l,
     1356                             const std::string& m)
    13121357{
    1313     yyin = stdin;//fopen("test.lolfx", "r");
    1314     do
    1315     {
    1316         yyparse();
    1317     }
    1318     while (!feof(yyin));
    1319 
    1320     fclose(yyin);
     1358    mc.Error(l, m);
    13211359}
    13221360
    1323 void yyerror(const char *s)
    1324 {
    1325     std::cout << "Parse error line " << yylineno << ": " << s << std::endl;
    1326     exit(-1);
    1327 }
    1328 
Note: See TracChangeset for help on using the changeset viewer.