glsl.g 70.2 KB
Newer Older
1
2
3
4
---------------------------------------------------------------------------
--
-- This file is part of Qt Creator
--
con's avatar
con committed
5
-- Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
7
8
--
-- Contact: Nokia Corporation (qt-info@nokia.com)
--
Erik Verbruggen's avatar
Erik Verbruggen committed
9
-- No Commercial Usage
10
--
Erik Verbruggen's avatar
Erik Verbruggen committed
11
12
13
14
-- This file contains pre-release code and may not be distributed.
-- You may use this file in accordance with the terms and conditions
-- contained in the Technology Preview License Agreement accompanying
-- this package.
15
16
17
18
19
20
21
22
23
24
--
-- GNU Lesser General Public License Usage
--
-- Alternatively, this file may be used under the terms of the GNU Lesser
-- General Public License version 2.1 as published by the Free Software
-- Foundation and appearing in the file LICENSE.LGPL included in the
-- packaging of this file.  Please review the following information to
-- ensure the GNU Lesser General Public License version 2.1 requirements
-- will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
--
Erik Verbruggen's avatar
Erik Verbruggen committed
25
26
27
28
29
30
31
-- In addition, as a special exception, Nokia gives you certain additional
-- rights.  These rights are described in the Nokia Qt LGPL Exception
-- version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
--
-- If you have questions regarding the use of this file, please contact
-- Nokia at qt-info@nokia.com.
--
32
33
---------------------------------------------------------------------------

34
35
36
37
%decl glslparser.h
%impl glslparser.cpp
%parser GLSLParserTable
%token_prefix T_
Roberto Raggi's avatar
Roberto Raggi committed
38
%expect 1
39

40
41
42
%token FEED_GLSL "feed GLSL"
%token FEED_EXPRESSION "feed expression"

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
%token ADD_ASSIGN "+="
%token AMPERSAND "&"
%token AND_ASSIGN "&="
%token AND_OP "&&"
%token ATTRIBUTE "attribute"
%token BANG "!"
%token BOOL "bool"
%token BREAK "break"
%token BVEC2 "bvec2"
%token BVEC3 "bvec3"
%token BVEC4 "bvec4"
%token CARET "^"
%token CASE "case"
%token CENTROID "centroid"
%token COLON ":"
%token COMMA ","
%token CONST "const"
%token CONTINUE "continue"
%token DASH "-"
%token DEC_OP "--"
%token DEFAULT "default"
%token DISCARD "discard"
%token DIV_ASSIGN "/="
%token DMAT2 "dmat2"
%token DMAT2X2 "dmat2x2"
%token DMAT2X3 "dmat2x3"
%token DMAT2X4 "dmat2x4"
%token DMAT3 "dmat3"
%token DMAT3X2 "dmat3x2"
%token DMAT3X3 "dmat3x3"
%token DMAT3X4 "dmat3x4"
%token DMAT4 "dmat4"
%token DMAT4X2 "dmat4x2"
%token DMAT4X3 "dmat4x3"
%token DMAT4X4 "dmat4x4"
%token DO "do"
%token DOT "."
%token DOUBLE "double"
%token DVEC2 "dvec2"
%token DVEC3 "dvec3"
%token DVEC4 "dvec4"
%token ELSE "else"
%token EQUAL "="
%token EQ_OP "=="
%token FLAT "flat"
%token FLOAT "float"
%token FOR "for"
%token GE_OP ">="
%token HIGHP "highp"
%token IDENTIFIER "identifier"
%token IF "if"
%token IN "in"
%token INC_OP "++"
%token INOUT "inout"
%token INT "int"
%token INVARIANT "invariant"
%token ISAMPLER1D "isampler1D"
%token ISAMPLER1DARRAY "isampler1DArray"
%token ISAMPLER2D "isampler2D"
%token ISAMPLER2DARRAY "isampler2DArray"
%token ISAMPLER2DMS "isampler2DMS"
%token ISAMPLER2DMSARRAY "isampler2DMSArray"
%token ISAMPLER2DRECT "isampler2DRect"
%token ISAMPLER3D "isampler3D"
%token ISAMPLERBUFFER "isamplerBuffer"
%token ISAMPLERCUBE "isamplerCube"
%token ISAMPLERCUBEARRAY "isamplerCubeArray"
%token IVEC2 "ivec2"
%token IVEC3 "ivec3"
%token IVEC4 "ivec4"
%token LAYOUT "layout"
%token LEFT_ANGLE "<"
%token LEFT_ASSIGN "<<="
%token LEFT_BRACE "{"
%token LEFT_BRACKET "["
%token LEFT_OP "<<"
%token LEFT_PAREN "("
%token LE_OP "<="
%token LOWP "lowp"
%token MAT2 "mat2"
%token MAT2X2 "mat2x2"
%token MAT2X3 "mat2x3"
%token MAT2X4 "mat2x4"
%token MAT3 "mat3"
%token MAT3X2 "mat3x2"
%token MAT3X3 "mat3x3"
%token MAT3X4 "mat3x4"
%token MAT4 "mat4"
%token MAT4X2 "mat4x2"
%token MAT4X3 "mat4x3"
%token MAT4X4 "mat4x4"
%token MEDIUMP "mediump"
%token MOD_ASSIGN "%="
%token MUL_ASSIGN "*="
%token NE_OP "!="
%token NOPERSPECTIVE "noperspective"
%token NUMBER "number constant"
%token OR_ASSIGN "|="
%token OR_OP "||"
%token OUT "out"
%token PATCH "patch"
%token PERCENT "%"
%token PLUS "plus"
%token PRECISION "precision"
%token QUESTION "?"
%token RETURN "return"
%token RIGHT_ANGLE ">"
%token RIGHT_ASSIGN ">>="
%token RIGHT_BRACE "}"
%token RIGHT_BRACKET "]"
%token RIGHT_OP ">>"
%token RIGHT_PAREN ")"
%token SAMPLE "sample"
%token SAMPLER1D "sampler1D"
%token SAMPLER1DARRAY "sampler1DArray"
%token SAMPLER1DARRAYSHADOW "sampler1DArrayShadow"
%token SAMPLER1DSHADOW "sampler1DShadow"
%token SAMPLER2D "sampler2D"
%token SAMPLER2DARRAY "sampler2DArray"
%token SAMPLER2DARRAYSHADOW "sampler2DArrayShadow"
%token SAMPLER2DMS "sampler2DMS"
%token SAMPLER2DMSARRAY "sampler2DMSArray"
%token SAMPLER2DRECT "sampler2DRect"
%token SAMPLER2DRECTSHADOW "sampler2DRectShadow"
%token SAMPLER2DSHADOW "sampler2DShadow"
%token SAMPLER3D "sampler3D"
%token SAMPLERBUFFER "samplerBuffer"
%token SAMPLERCUBE "samplerCube"
%token SAMPLERCUBEARRAY "samplerCubeArray"
%token SAMPLERCUBEARRAYSHADOW "samplerCubeArrayShadow"
%token SAMPLERCUBESHADOW "samplerCubeShadow"
%token SEMICOLON ";"
%token SLASH "/"
%token SMOOTH "smooth"
%token STAR "*"
%token STRUCT "struct"
%token SUBROUTINE "subroutine"
%token SUB_ASSIGN "-="
%token SWITCH "switch"
%token TILDE "~"
%token TYPE_NAME "type_name"
%token UINT "uint"
%token UNIFORM "uniform"
%token USAMPLER1D "usampler1D"
%token USAMPLER1DARRAY "usampler1DArray"
%token USAMPLER2D "usampler2D"
%token USAMPLER2DARRAY "usampler2DArray"
%token USAMPLER2DMS "usampler2DMS"
%token USAMPLER2DMSARRAY "usampler2DMSarray"
%token USAMPLER2DRECT "usampler2DRect"
%token USAMPLER3D "usampler3D"
%token USAMPLERBUFFER "usamplerBuffer"
%token USAMPLERCUBE "usamplerCube"
%token USAMPLERCUBEARRAY "usamplerCubeArray"
%token UVEC2 "uvec2"
%token UVEC3 "uvec3"
%token UVEC4 "uvec4"
%token VARYING "varying"
%token VEC2 "vec2"
%token VEC3 "vec3"
%token VEC4 "vec4"
%token VERTICAL_BAR "|"
%token VOID "void"
%token WHILE "while"
%token XOR_ASSIGN "^="
Roberto Raggi's avatar
Roberto Raggi committed
208
%token XOR_OP "^^"
209
210
%token TRUE "true"
%token FALSE "false"
211
212
%token PREPROC "preprocessor directive"
%token COMMENT "comment"
213
%token ERROR "error"
214
%token RESERVED "reserved word"
215

216
%start toplevel
217
218

/:
219
220
221
222
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
223
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
224
225
226
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
con's avatar
con committed
227
** No Commercial Usage
228
**
con's avatar
con committed
229
230
231
232
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
233
234
235
236
237
238
239
240
241
242
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
con's avatar
con committed
243
244
245
246
247
248
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
249
250
251
**
**************************************************************************/

252
253
254
#include "$header"
#include "glsllexer.h"
#include "glslast.h"
255
#include "glslengine.h"
256
257
258
259
260
#include <vector>
#include <stack>

namespace GLSL {

261
class GLSL_EXPORT Parser: public $table
262
263
{
public:
264
265
    union Value {
        void *ptr;
266
        const QString *string;
267
268
        AST *ast;
        List<AST *> *ast_list;
269
270
271
272
273
274
275
276
277
278
279
        DeclarationAST *declaration;
        List<DeclarationAST *> *declaration_list;
        ExpressionAST *expression;
        List<ExpressionAST *> *expression_list;
        StatementAST *statement;
        List<StatementAST *> *statement_list;
        TypeAST *type;
        StructTypeAST::Field *field;
        List<StructTypeAST::Field *> *field_list;
        TranslationUnitAST *translation_unit;
        FunctionIdentifierAST *function_identifier;
280
        AST::Kind kind;
281
        TypeAST::Precision precision;
282
        struct {
283
284
            StatementAST *thenClause;
            StatementAST *elseClause;
285
286
        } ifstmt;
        struct {
287
288
            ExpressionAST *condition;
            ExpressionAST *increment;
289
290
        } forstmt;
        struct {
291
292
            FunctionIdentifierAST *id;
            List<ExpressionAST *> *arguments;
293
        } function;
294
295
296
297
298
299
300
        int qualifier;
        LayoutQualifier *layout;
        List<LayoutQualifier *> *layout_list;
        struct {
            int qualifier;
            List<LayoutQualifier *> *layout_list;
        } type_qualifier;
301
        struct {
302
            TypeAST *type;
303
            const QString *name;
304
        } param_declarator;
305
306
        ParameterDeclarationAST *param_declaration;
        FunctionDeclarationAST *function_declaration;
307
308
309
    };

    Parser(Engine *engine, const char *source, unsigned size, int variant);
310
311
    ~Parser();

312
313
314
315
316
317
318
319
320
321
322
323
324
    TranslationUnitAST *parse() {
        if (AST *u = parse(T_FEED_GLSL))
            return u->asTranslationUnit();
        return 0;
    }

    ExpressionAST *parseExpression() {
        if (AST *u = parse(T_FEED_EXPRESSION))
            return u->asExpression();
        return 0;
    }

    AST *parse(int startToken);
325
326

private:
327
    // 1-based
328
    int &location(int n) { return _locationStack[_tos + n - 1]; }
329
330
    Value &sym(int n) { return _symStack[_tos + n - 1]; }
    AST *&ast(int n) { return _symStack[_tos + n - 1].ast; }
331
    const QString *&string(int n) { return _symStack[_tos + n - 1].string; }
332
333
334
335
    ExpressionAST *&expression(int n) { return _symStack[_tos + n - 1].expression; }
    StatementAST *&statement(int n) { return _symStack[_tos + n - 1].statement; }
    TypeAST *&type(int n) { return _symStack[_tos + n - 1].type; }
    FunctionDeclarationAST *&function(int n) { return _symStack[_tos + n - 1].function_declaration; }
336

Roberto Raggi's avatar
Roberto Raggi committed
337
338
339
340
341
    inline int consumeToken() {
        if (_index < int(_tokens.size()))
            return _index++;
        return _tokens.size() - 1;
    }
342
343
344
345
346
347
348
349
350
351
    inline const Token &tokenAt(int index) const {
        if (index == 0)
            return _startToken;
        return _tokens.at(index);
    }
    inline int tokenKind(int index) const {
        if (index == 0)
            return _startToken.kind;
        return _tokens.at(index).kind;
    }
352
    void reduce(int ruleno);
353

Roberto Raggi's avatar
Roberto Raggi committed
354
355
    void warning(int line, const QString &message)
    {
356
        _engine->warning(line, message);
Roberto Raggi's avatar
Roberto Raggi committed
357
358
359
360
    }

    void error(int line, const QString &message)
    {
361
        _engine->error(line, message);
Roberto Raggi's avatar
Roberto Raggi committed
362
363
    }

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
    template <typename T>
    T *makeAstNode()
    {
        T *node = new (_engine->pool()) T ();
        node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
        return node;
    }

    template <typename T, typename A1>
    T *makeAstNode(A1 a1)
    {
        T *node = new (_engine->pool()) T (a1);
        node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
        return node;
    }

    template <typename T, typename A1, typename A2>
    T *makeAstNode(A1 a1, A2 a2)
    {
        T *node = new (_engine->pool()) T (a1, a2);
        node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
        return node;
    }

    template <typename T, typename A1, typename A2, typename A3>
    T *makeAstNode(A1 a1, A2 a2, A3 a3)
    {
        T *node = new (_engine->pool()) T (a1, a2, a3);
        node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
        return node;
    }

    template <typename T, typename A1, typename A2, typename A3, typename A4>
    T *makeAstNode(A1 a1, A2 a2, A3 a3, A4 a4)
    {
        T *node = new (_engine->pool()) T (a1, a2, a3, a4);
        node->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
        return node;
    }

404
    TypeAST *makeBasicType(int token)
405
    {
406
        TypeAST *type = new (_engine->pool()) BasicTypeAST(token, spell[token]);
407
408
409
410
        type->lineno = yyloc >= 0 ? (_tokens[yyloc].line + 1) : 0;
        return type;
    }

411
private:
412
    Engine *_engine;
413
414
    int _tos;
    int _index;
415
    int yyloc;
Roberto Raggi's avatar
Roberto Raggi committed
416
417
418
    int yytoken;
    int yyrecovering;
    bool _recovered;
419
    Token _startToken;
420
421
    std::vector<int> _stateStack;
    std::vector<int> _locationStack;
422
    std::vector<Value> _symStack;
423
424
425
    std::vector<Token> _tokens;
};

426
} // namespace GLSL
427
428
429
:/

/.
430
431
432
433
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
434
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
435
436
437
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
Erik Verbruggen's avatar
Erik Verbruggen committed
438
** No Commercial Usage
439
**
Erik Verbruggen's avatar
Erik Verbruggen committed
440
441
442
443
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
444
445
446
447
448
449
450
451
452
453
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
Erik Verbruggen's avatar
Erik Verbruggen committed
454
455
456
457
458
459
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
460
461
462
**
**************************************************************************/

463
#include "glslparser.h"
464
#include "glslengine.h"
465
#include <iostream>
466
#include <cstdio>
467
#include <cassert>
Roberto Raggi's avatar
Roberto Raggi committed
468
#include <QtCore/QDebug>
469
470
471

using namespace GLSL;

472
Parser::Parser(Engine *engine, const char *source, unsigned size, int variant)
Roberto Raggi's avatar
Roberto Raggi committed
473
    : _engine(engine), _tos(-1), _index(0), yyloc(-1), yytoken(-1), yyrecovering(0), _recovered(false)
474
475
476
477
478
{
    _tokens.reserve(1024);

    _stateStack.resize(128);
    _locationStack.resize(128);
479
    _symStack.resize(128);
480
481
482
483
484
485
486

    _tokens.push_back(Token()); // invalid token

    std::stack<int> parenStack;
    std::stack<int> bracketStack;
    std::stack<int> braceStack;

487
    Lexer lexer(engine, source, size);
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
    lexer.setVariant(variant);
    Token tk;
    do {
        lexer.yylex(&tk);

        switch (tk.kind) {
        case T_LEFT_PAREN:
            parenStack.push(_tokens.size());
            break;
        case T_LEFT_BRACKET:
            bracketStack.push(_tokens.size());
            break;
        case T_LEFT_BRACE:
            braceStack.push(_tokens.size());
            break;

        case T_RIGHT_PAREN:
            if (! parenStack.empty()) {
                _tokens[parenStack.top()].matchingBrace = _tokens.size();
                parenStack.pop();
            }
            break;
        case T_RIGHT_BRACKET:
            if (! bracketStack.empty()) {
                _tokens[bracketStack.top()].matchingBrace = _tokens.size();
                bracketStack.pop();
            }
            break;
        case T_RIGHT_BRACE:
            if (! braceStack.empty()) {
                _tokens[braceStack.top()].matchingBrace = _tokens.size();
                braceStack.pop();
            }
            break;
        default:
            break;
        }

        _tokens.push_back(tk);
    } while (tk.isNot(EOF_SYMBOL));

529
    _index = 0;
530
531
532
533
534
535
}

Parser::~Parser()
{
}

536
AST *Parser::parse(int startToken)
537
538
{
    int action = 0;
Roberto Raggi's avatar
Roberto Raggi committed
539
    yytoken = -1;
540
    yyloc = -1;
541
    void *yyval = 0; // value of the current token.
542

Roberto Raggi's avatar
Roberto Raggi committed
543
    _recovered = false;
544
    _tos = -1;
545
    _startToken.kind = startToken;
546
547

    do {
Roberto Raggi's avatar
Roberto Raggi committed
548
549
550
551
552
553
554
555
556
    again:
        if (unsigned(++_tos) == _stateStack.size()) {
            _stateStack.resize(_tos * 2);
            _locationStack.resize(_tos * 2);
            _symStack.resize(_tos * 2);
        }

        _stateStack[_tos] = action;

557
558
559
        if (yytoken == -1 && -TERMINAL_COUNT != action_index[action]) {
            yyloc = consumeToken();
            yytoken = tokenKind(yyloc);
Roberto Raggi's avatar
Roberto Raggi committed
560
561
            if (yyrecovering)
                --yyrecovering;
562
563
564
565
566
567
568
569
570
571
            if (yytoken == T_IDENTIFIER && t_action(action, T_TYPE_NAME) != 0) {
                const Token &la = tokenAt(_index);

                if (la.is(T_IDENTIFIER)) {
                    yytoken = T_TYPE_NAME;
                } else if (la.is(T_LEFT_BRACKET) && la.matchingBrace != 0 &&
                           tokenAt(la.matchingBrace + 1).is(T_IDENTIFIER)) {
                    yytoken = T_TYPE_NAME;
                }
            }
572
            yyval = _tokens.at(yyloc).ptr;
573
574
575
576
577
578
        }

        action = t_action(action, yytoken);
        if (action > 0) {
            if (action == ACCEPT_STATE) {
                --_tos;
579
                return _symStack[0].translation_unit;
580
            }
581
            _symStack[_tos].ptr = yyval;
582
583
584
585
586
587
            _locationStack[_tos] = yyloc;
            yytoken = -1;
        } else if (action < 0) {
            const int ruleno = -action - 1;
            const int N = rhs[ruleno];
            _tos -= N;
588
            reduce(ruleno);
589
            action = nt_action(_stateStack[_tos], lhs[ruleno] - TERMINAL_COUNT);
Roberto Raggi's avatar
Roberto Raggi committed
590
591
592
593
594
595
596
        } else if (action == 0) {
            const int line = _tokens[yyloc].line + 1;
            QString message = QLatin1String("Syntax error");
            if (yytoken != -1) {
                const QLatin1String s(spell[yytoken]);
                message = QString("Unexpected token `%1'").arg(s);
            }
597

Roberto Raggi's avatar
Roberto Raggi committed
598
599
600
601
602
603
604
605
            for (; _tos; --_tos) {
                const int state = _stateStack[_tos];

                static int tks[] = {
                    T_RIGHT_BRACE, T_RIGHT_PAREN, T_RIGHT_BRACKET,
                    T_SEMICOLON, T_COMMA, T_COLON,
                    T_NUMBER, T_TYPE_NAME, T_IDENTIFIER,
                    T_LEFT_BRACE, T_LEFT_PAREN, T_LEFT_BRACKET,
606
                    T_WHILE,
Roberto Raggi's avatar
Roberto Raggi committed
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
                    0
                };

                for (int *tptr = tks; *tptr; ++tptr) {
                    const int next = t_action(state, *tptr);
                    if (next > 0) {
                        if (! yyrecovering && ! _recovered) {
                            _recovered = true;
                            error(line, QString("Expected `%1'").arg(QLatin1String(spell[*tptr])));
                        }

                        yyrecovering = 3;
                        if (*tptr == T_IDENTIFIER)
                            yyval = (void *) _engine->identifier(QLatin1String("$identifier"));
                        else if (*tptr == T_NUMBER || *tptr == T_TYPE_NAME)
                            yyval = (void *) _engine->identifier(QLatin1String("$0"));
                        else
                            yyval = 0;

                        _symStack[_tos].ptr = yyval;
                        _locationStack[_tos] = yyloc;
                        yytoken = -1;

                        action = next;
                        goto again;
                    }
                }
            }
Roberto Raggi's avatar
Roberto Raggi committed
635

Roberto Raggi's avatar
Roberto Raggi committed
636
637
638
639
640
            if (! _recovered) {
                _recovered = true;
                error(line, message);
            }
        }
Roberto Raggi's avatar
Roberto Raggi committed
641

Roberto Raggi's avatar
Roberto Raggi committed
642
    } while (action);
643

644
    return 0;
645
646
}
./
647
648
649
650
651
652
653
654
655
656
657



/.
void Parser::reduce(int ruleno)
{
switch(ruleno) {
./



658
variable_identifier ::= IDENTIFIER ;
659
660
/.
case $rule_number: {
661
    ast(1) = makeAstNode<IdentifierExpressionAST>(string(1));
662
663
664
}   break;
./

665
primary_expression ::= NUMBER ;
666
667
/.
case $rule_number: {
668
    ast(1) = makeAstNode<LiteralExpressionAST>(string(1));
669
670
671
}   break;
./

672
primary_expression ::= TRUE ;
673
674
/.
case $rule_number: {
675
    ast(1) = makeAstNode<LiteralExpressionAST>(_engine->identifier("true", 4));
676
677
678
}   break;
./

679
primary_expression ::= FALSE ;
680
681
/.
case $rule_number: {
682
    ast(1) = makeAstNode<LiteralExpressionAST>(_engine->identifier("false", 5));
683
684
685
}   break;
./

686
primary_expression ::= variable_identifier ;
687
688
/.
case $rule_number: {
689
    // nothing to do.
690
691
692
}   break;
./

693
primary_expression ::= LEFT_PAREN expression RIGHT_PAREN ;
694
695
/.
case $rule_number: {
696
    ast(1) = ast(2);
697
698
699
}   break;
./

700
postfix_expression ::= primary_expression ;
701
702
/.
case $rule_number: {
703
    // nothing to do.
704
705
706
}   break;
./

707
postfix_expression ::= postfix_expression LEFT_BRACKET integer_expression RIGHT_BRACKET ;
708
709
/.
case $rule_number: {
710
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_ArrayAccess, expression(1), expression(3));
711
712
713
}   break;
./

714
postfix_expression ::= function_call ;
715
716
/.
case $rule_number: {
717
    // nothing to do.
718
719
720
}   break;
./

721
postfix_expression ::= postfix_expression DOT IDENTIFIER ;
722
723
/.
case $rule_number: {
724
    ast(1) = makeAstNode<MemberAccessExpressionAST>(expression(1), string(3));
725
726
727
}   break;
./

728
postfix_expression ::= postfix_expression INC_OP ;
729
730
/.
case $rule_number: {
731
    ast(1) = makeAstNode<UnaryExpressionAST>(AST::Kind_PostIncrement, expression(1));
732
733
734
}   break;
./

735
postfix_expression ::= postfix_expression DEC_OP ;
736
737
/.
case $rule_number: {
738
    ast(1) = makeAstNode<UnaryExpressionAST>(AST::Kind_PostDecrement, expression(1));
739
740
741
}   break;
./

742
integer_expression ::= expression ;
743
744
/.
case $rule_number: {
745
    // nothing to do.
746
747
748
}   break;
./

749
function_call ::= function_call_or_method ;
750
751
/.
case $rule_number: {
752
    // nothing to do.
753
754
755
}   break;
./

756
function_call_or_method ::= function_call_generic ;
757
758
/.
case $rule_number: {
759
    ast(1) = makeAstNode<FunctionCallExpressionAST>
760
        (sym(1).function.id, sym(1).function.arguments);
761
762
763
}   break;
./

764
function_call_or_method ::= postfix_expression DOT function_call_generic ;
765
766
/.
case $rule_number: {
767
    ast(1) = makeAstNode<FunctionCallExpressionAST>
768
        (expression(1), sym(3).function.id, sym(3).function.arguments);
769
770
771
}   break;
./

772
function_call_generic ::= function_call_header_with_parameters RIGHT_PAREN ;
773
774
/.
case $rule_number: {
775
    // nothing to do.
776
777
778
}   break;
./

779
function_call_generic ::= function_call_header_no_parameters RIGHT_PAREN ;
780
781
/.
case $rule_number: {
782
    // nothing to do.
783
784
785
}   break;
./

786
function_call_header_no_parameters ::= function_call_header VOID ;
787
788
/.
case $rule_number: {
789
790
    sym(1).function.id = sym(1).function_identifier;
    sym(1).function.arguments = 0;
791
792
793
}   break;
./

794
function_call_header_no_parameters ::= function_call_header ;
795
796
/.
case $rule_number: {
797
798
    sym(1).function.id = sym(1).function_identifier;
    sym(1).function.arguments = 0;
799
800
801
}   break;
./

802
function_call_header_with_parameters ::= function_call_header assignment_expression ;
803
804
/.
case $rule_number: {
805
806
    sym(1).function.id = sym(1).function_identifier;
    sym(1).function.arguments =
807
        makeAstNode< List<ExpressionAST *> >(expression(2));
808
809
810
}   break;
./

811
function_call_header_with_parameters ::= function_call_header_with_parameters COMMA assignment_expression ;
812
813
/.
case $rule_number: {
814
    sym(1).function.arguments =
815
        makeAstNode< List<ExpressionAST *> >
816
            (sym(1).function.arguments, expression(3));
817
818
819
}   break;
./

820
function_call_header ::= function_identifier LEFT_PAREN ;
821
822
/.
case $rule_number: {
823
    // nothing to do.
824
825
826
}   break;
./

827
function_identifier ::= type_specifier ;
828
829
/.
case $rule_number: {
830
    ast(1) = makeAstNode<FunctionIdentifierAST>(type(1));
831
832
833
}   break;
./

834
function_identifier ::= IDENTIFIER ;
835
836
/.
case $rule_number: {
837
    ast(1) = makeAstNode<FunctionIdentifierAST>(string(1));
838
839
840
}   break;
./

841
unary_expression ::= postfix_expression ;
842
843
/.
case $rule_number: {
844
    // nothing to do.
845
846
847
}   break;
./

848
unary_expression ::= INC_OP unary_expression ;
849
850
/.
case $rule_number: {
851
    ast(1) = makeAstNode<UnaryExpressionAST>(AST::Kind_PreIncrement, expression(2));
852
853
854
}   break;
./

855
unary_expression ::= DEC_OP unary_expression ;
856
857
/.
case $rule_number: {
858
    ast(1) = makeAstNode<UnaryExpressionAST>(AST::Kind_PreDecrement, expression(2));
859
860
861
}   break;
./

862
unary_expression ::= unary_operator unary_expression ;
863
864
/.
case $rule_number: {
865
    ast(1) = makeAstNode<UnaryExpressionAST>(sym(1).kind, expression(2));
866
867
868
}   break;
./

869
unary_operator ::= PLUS ;
870
871
/.
case $rule_number: {
872
    sym(1).kind = AST::Kind_UnaryPlus;
873
874
875
}   break;
./

876
unary_operator ::= DASH ;
877
878
/.
case $rule_number: {
879
    sym(1).kind = AST::Kind_UnaryMinus;
880
881
882
}   break;
./

883
unary_operator ::= BANG ;
884
885
/.
case $rule_number: {
886
    sym(1).kind = AST::Kind_LogicalNot;
887
888
889
}   break;
./

890
unary_operator ::= TILDE ;
891
892
/.
case $rule_number: {
893
    sym(1).kind = AST::Kind_BitwiseNot;
894
895
896
}   break;
./

897
multiplicative_expression ::= unary_expression ;
898
899
/.
case $rule_number: {
900
    // nothing to do.
901
902
903
}   break;
./

904
multiplicative_expression ::= multiplicative_expression STAR unary_expression ;
905
906
/.
case $rule_number: {
907
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_Multiply, expression(1), expression(3));
908
909
910
}   break;
./

911
multiplicative_expression ::= multiplicative_expression SLASH unary_expression ;
912
913
/.
case $rule_number: {
914
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_Divide, expression(1), expression(3));
915
916
917
}   break;
./

918
multiplicative_expression ::= multiplicative_expression PERCENT unary_expression ;
919
920
/.
case $rule_number: {
921
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_Modulus, expression(1), expression(3));
922
923
924
}   break;
./

925
additive_expression ::= multiplicative_expression ;
926
927
/.
case $rule_number: {
928
    // nothing to do.
929
930
931
}   break;
./

932
additive_expression ::= additive_expression PLUS multiplicative_expression ;
933
934
/.
case $rule_number: {
935
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_Plus, expression(1), expression(3));
936
937
938
}   break;
./

939
additive_expression ::= additive_expression DASH multiplicative_expression ;
940
941
/.
case $rule_number: {
942
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_Minus, expression(1), expression(3));
943
944
945
}   break;
./

946
shift_expression ::= additive_expression ;
947
948
/.
case $rule_number: {
949
    // nothing to do.
950
951
952
}   break;
./

953
shift_expression ::= shift_expression LEFT_OP additive_expression ;
954
955
/.
case $rule_number: {
956
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_ShiftLeft, expression(1), expression(3));
957
958
959
}   break;
./

960
shift_expression ::= shift_expression RIGHT_OP additive_expression ;
961
962
/.
case $rule_number: {
963
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_ShiftRight, expression(1), expression(3));
964
965
966
}   break;
./

967
relational_expression ::= shift_expression ;
968
969
/.
case $rule_number: {
970
    // nothing to do.
971
972
973
}   break;
./

974
relational_expression ::= relational_expression LEFT_ANGLE shift_expression ;
975
976
/.
case $rule_number: {
977
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_LessThan, expression(1), expression(3));
978
979
980
}   break;
./

981
relational_expression ::= relational_expression RIGHT_ANGLE shift_expression ;
982
983
/.
case $rule_number: {
984
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_GreaterThan, expression(1), expression(3));
985
986
987
}   break;
./

988
relational_expression ::= relational_expression LE_OP shift_expression ;
989
990
/.
case $rule_number: {
991
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_LessEqual, expression(1), expression(3));
992
993
994
}   break;
./

995
relational_expression ::= relational_expression GE_OP shift_expression ;
996
997
/.
case $rule_number: {
998
    ast(1) = makeAstNode<BinaryExpressionAST>(AST::Kind_GreaterEqual, expression(1), expression(3));
999
1000
}   break;
./
For faster browsing, not all history is shown. View entire blame