OpenCores
URL https://opencores.org/ocsvn/theia_gpu/theia_gpu/trunk

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [beta_2.0/] [compiler/] [src/] [cp_compiler/] [parser.y] - Blame information for rev 216

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 216 diegovalve
 
2
/**********************************************************************************
3
Theia, Ray Cast Programable graphic Processing Unit.
4
Copyright (C) 2012  Diego Valverde (diego.valverde.g@gmail.com)
5
 
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License
8
as published by the Free Software Foundation; either version 2
9
of the License, or (at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
 
20
***********************************************************************************/
21
 
22
 
23
%require "2.4.1"
24
%skeleton "lalr1.cc"
25
%defines
26
%error-verbose
27
%locations
28
%define namespace "Theia"
29
%define parser_class_name "Parser"
30
%parse-param { Theia::Scanner &scanner }
31
%parse-param { std::map  & mSymbolMap }
32
%parse-param { std::vector< CControlInstruction > &mInstructions }
33
%parse-param { bool &mGenerateFixedPointArithmetic }
34
%lex-param   { Theia::Scanner &scanner }
35
 
36
%code requires {
37
        #include 
38
        #include 
39
        #include 
40
        #include 
41
        #include 
42
        #include "Instruction.h"
43
        #include 
44
 
45
 
46
        // We want to return a string
47
        #define YYSTYPE std::string
48
 
49
 
50
                namespace Theia
51
                {
52
                        // Forward-declare the Scanner class; the Parser needs to be assigned a
53
                        // Scanner, but the Scanner can't be declared without the Parser
54
                        class Scanner;
55
 
56
                        // We use a map to store the INI data
57
                        typedef std::map > mapData;
58
 
59
 
60
 
61
 
62
 
63
                }
64
 
65
}
66
 
67
%code
68
{
69
        #include "Instruction.h"
70
        #include 
71
        CControlInstruction I;
72
        std::vector< unsigned int > gBranchStack;
73
        static int gInsertedInstructions = 0;
74
        static int gWhileLoopAddress = 0;
75
#define FUNCTION_PARAM_START_REGION 4
76
#define FUNCTION_PARAM_LAST_REGION  7
77
        std::map gVaribleMap;
78
 
79
#define AUTOVAR_START_REGION 9
80
#define TEMP_VAR_START_OFFSET 128
81
unsigned int gAutoVarIndex = AUTOVAR_START_REGION;
82
 
83
unsigned int gFunctionParameterIndex = FUNCTION_PARAM_START_REGION;
84
//----------------------------------------------------------
85
int GetCurrentLineNumber( const Theia::Parser::location_type &loc )
86
{
87
                int ret = -1;
88
                std::stringstream ss2;
89
                std::string where;
90
                ss2 << loc;
91
                ss2 >> where;
92
                where.erase(where.find_first_of("."));
93
                std::stringstream ss3;
94
                ss3 << where;
95
                ss3 >> ret;
96
                return ret;
97
}
98
//----------------------------------------------------------
99
unsigned int GetAddressFromIdentifier( std::string aIdentifier, Theia::Parser::location_type  yylloc )
100
{
101
        if (aIdentifier.find("R") != std::string::npos)
102
        {
103
                return atoi(aIdentifier.c_str()+1);
104
        }
105
        if (gVaribleMap.find(aIdentifier) == gVaribleMap.end())
106
        {
107
                        std::ostringstream ret;
108
                        ret << "Undefined variable '" << aIdentifier << "' at line " << yylloc << " \n";
109
                        throw ret.str();
110
        }
111
 
112
        return gVaribleMap[ aIdentifier ];
113
 
114
}
115
//----------------------------------------------------------
116
unsigned int gTempRegisterIndex = TEMP_VAR_START_OFFSET;
117
//----------------------------------------------------------
118
unsigned int GetFreeTempRegister( void )
119
{
120
 
121
        return gTempRegisterIndex++;
122
 
123
}
124
//----------------------------------------------------------
125
void ResetTempRegisterIndex( void )
126
{
127
 
128
        gTempRegisterIndex = TEMP_VAR_START_OFFSET;
129
}
130
//----------------------------------------------------------
131
unsigned int AllocateVariable( )
132
{
133
                gAutoVarIndex++;
134
                return gAutoVarIndex;
135
 
136
}
137
//----------------------------------------------------------
138
        // Prototype for the yylex function
139
        static int yylex(Theia::Parser::semantic_type * yylval,
140
                         Theia::Parser::location_type * yylloc,
141
                         Theia::Scanner &scanner);
142
}
143
 
144
%token SHL SHR SCALAR RETURN EXIT EQUAL NOT_EQUAL GREATER_THAN LESS_THAN LESS_OR_EQUAL_THAN GREATER_OR_EQUAL_THAN IF ELSE OPEN_ROUND_BRACE CLOSE_ROUND_BRACE OPEN_BRACE CLOSE_BRACE ASSIGN ADD DECCONST HEXCONST BINCONST EOS MINUS
145
%token IDENTIFIER  COMMA OPEN_SQUARE_BRACE CLOSE_SQUARE_BRACE WHILE START BITWISE_AND BITWISE_OR COPY_DATA_BLOCK COPY_CODE_BLOCK BLOCK_TRANSFER_IN_PROGRESS
146
%%
147
 
148
statement_list: //empty
149
        |
150
        statement_list statement
151
        |
152
        statement
153
        ;
154
 
155
statement
156
        :
157
        START LESS_THAN constant GREATER_THAN EOS
158
        {
159
 
160
                unsigned int ImmediateValue;
161
                std::string StringHex = $3;
162
                std::stringstream ss;
163
                ss << std::hex << StringHex;
164
                ss >> ImmediateValue;
165
 
166
 
167
                I.mComment = "Start";
168
                I.mSourceLine = GetCurrentLineNumber( yylloc );
169
                I.SetOperation(EOPERATION_DELIVERCOMMAND);
170
                I.SetDestinationAddress( ImmediateValue+1 );
171
                I.SetSrc1Address( VP_COMMAND_START_MAIN_THREAD );
172
                mInstructions.push_back(I);
173
                I.Clear();
174
        }
175
        |
176
        SCALAR scalar_list EOS
177
        |
178
        COPY_DATA_BLOCK LESS_THAN expression COMMA expression COMMA expression GREATER_THAN EOS
179
        {
180
 
181
                I.SetOperation( EOPERATION_ADD );
182
                I.mComment = "Setting destination ID SPR for Copy data block";
183
                I.SetDestinationAddress( BLOCK_DST_REG );
184
                I.SetSrc1Address( GetAddressFromIdentifier($3,yylloc));
185
                I.SetSrc0Address(0);
186
                mInstructions.push_back(I);
187
                I.Clear();
188
 
189
                std::cout << "COPY_DATA_BLOCK I(" << GetAddressFromIdentifier($3,yylloc) << ") " << GetAddressFromIdentifier($5,yylloc) << " " << GetAddressFromIdentifier($7,yylloc) << "\n";
190
                I.mComment = "Copy data block";
191
                I.mSourceLine = GetCurrentLineNumber( yylloc );
192
                I.SetOperation(EOPERATION_COPYBLOCK);
193
                //I.SetCopyDestinationId(ImmediateValue);
194
                I.SetCopyDestinationId(0);
195
                I.SetCopyDestinationAddress(GetAddressFromIdentifier($5,yylloc));
196
                I.SetCopySourceAddress(GetAddressFromIdentifier($7,yylloc));
197
                I.SetCopySize(GetAddressFromIdentifier($9,yylloc));
198
                mInstructions.push_back(I);
199
                I.Clear();
200
        }
201
        |
202
        EXIT EOS
203
        {
204
                //Insert a stupid NOP before the exit... is a bug but easier to just patch like this...
205
 
206
                I.mComment = "Exit";
207
                I.mSourceLine = GetCurrentLineNumber( yylloc );
208
                I.SetOperation(EOPERATION_EXIT);
209
                mInstructions.push_back(I);
210
                I.Clear();
211
        }
212
 
213
         |
214
         IDENTIFIER MINUS MINUS EOS
215
         {
216
 
217
                I.mComment = "Storing constant '1'";
218
                I.SetOperation( EOPERATION_SUB );
219
                unsigned int TmpReg  = GetFreeTempRegister();
220
                I.SetDestinationAddress( TmpReg );
221
                I.SetLiteral(1);
222
                mInstructions.push_back( I );
223
                I.Clear();
224
 
225
                I.mSourceLine = GetCurrentLineNumber( yylloc );
226
                I.SetOperation( EOPERATION_ADD );
227
                I.SetDestinationAddress( GetAddressFromIdentifier($1,yylloc) );
228
                I.SetSrc1Address( GetAddressFromIdentifier($3,yylloc));
229
                I.SetSrc0Address( TmpReg );
230
                mInstructions.push_back( I );
231
                I.Clear();
232
                gInsertedInstructions = 0;
233
                ResetTempRegisterIndex();
234
         }
235
         |
236
         IDENTIFIER ADD ADD EOS
237
         {
238
 
239
            I.mComment = "Storing constant '1'";
240
                I.SetOperation( EOPERATION_ADD );
241
                unsigned int TmpReg  = GetFreeTempRegister();
242
                I.SetDestinationAddress( TmpReg );
243
                I.SetLiteral(1);
244
                mInstructions.push_back( I );
245
                I.Clear();
246
 
247
                I.mSourceLine = GetCurrentLineNumber( yylloc );
248
                I.SetOperation( EOPERATION_ADD );
249
                I.SetDestinationAddress( GetAddressFromIdentifier($1,yylloc) );
250
                I.SetSrc1Address( GetAddressFromIdentifier($3,yylloc));
251
                I.SetSrc0Address( TmpReg );
252
                mInstructions.push_back( I );
253
                I.Clear();
254
                gInsertedInstructions = 0;
255
                ResetTempRegisterIndex();
256
 
257
         }
258
         |
259
         IDENTIFIER ASSIGN expression  EOS
260
        {
261
            mInstructions[mInstructions.size()-gInsertedInstructions].mSourceLine = GetCurrentLineNumber( yylloc );
262
                I.SetOperation( EOPERATION_ADD );
263
                I.SetDestinationAddress( GetAddressFromIdentifier($1,yylloc) );
264
                I.SetSrc1Address( GetAddressFromIdentifier($3,yylloc));
265
                I.SetSrc0Address(0);
266
                mInstructions.push_back( I );
267
                I.Clear();
268
                gInsertedInstructions = 0;
269
                ResetTempRegisterIndex();
270
        }
271
        |
272
        IDENTIFIER ADD ASSIGN expression EOS
273
        {
274
                mInstructions[mInstructions.size()-gInsertedInstructions].mSourceLine = GetCurrentLineNumber( yylloc );
275
                I.SetOperation( EOPERATION_ADD );
276
                I.SetDestinationAddress( GetAddressFromIdentifier($1,yylloc) );
277
                I.SetSrc1Address( GetAddressFromIdentifier($4,yylloc));
278
                I.SetSrc0Address( GetAddressFromIdentifier($1,yylloc) );
279
                mInstructions.push_back( I );
280
                I.Clear();
281
                gInsertedInstructions = 0;
282
        }
283
        |
284
        WHILE {gWhileLoopAddress = (mInstructions.size());} OPEN_ROUND_BRACE boolean_expression CLOSE_ROUND_BRACE OPEN_BRACE statement_list CLOSE_BRACE
285
        {
286
                mInstructions[gBranchStack.back()].SetDestinationAddress(mInstructions.size()+1);
287
                gBranchStack.pop_back();
288
                //Now I need to put a GOTO so that the while gets evaluated again...
289
                //jump out of the if
290
           I.Clear();
291
           I.SetOperation( EOPERATION_BRANCH );
292
           I.mComment = "while loop goto re-eval boolean";
293
           I.SetDestinationAddress( gWhileLoopAddress );
294
           mInstructions.push_back(I);
295
           I.Clear();
296
 
297
           I.SetOperation( EOPERATION_NOP );
298
           I.mComment = "branch delay";
299
           I.SetDestinationAddress( gWhileLoopAddress );
300
           mInstructions.push_back(I);
301
           I.Clear();
302
           gInsertedInstructions = 0;
303
        }
304
        |
305
        START IDENTIFIER EOS
306
        {
307
 
308
        }
309
        ;
310
 
311
 
312
 
313
expression
314
                :
315
                expression ADD term
316
                {
317
                        unsigned int TempRegIndex  = GetFreeTempRegister();
318
                        I.SetOperation( EOPERATION_ADD );
319
                        I.SetDestinationAddress( TempRegIndex );
320
                        I.SetSrc1Address(GetAddressFromIdentifier($1,yylloc));
321
                        I.SetSrc0Address(GetAddressFromIdentifier($3,yylloc));
322
                        mInstructions.push_back(I);
323
                        gInsertedInstructions++;
324
                        I.Clear();
325
                        std::stringstream ss;
326
                        ss << "R" << TempRegIndex;
327
                        $$ = ss.str();
328
 
329
                        //$$ = ss.str();
330
 
331
                }
332
                |
333
                expression BITWISE_OR term
334
                {
335
                        unsigned int TempRegIndex  = GetFreeTempRegister();
336
                        I.SetOperation( EOPERATION_OR );
337
                        I.SetDestinationAddress( TempRegIndex );
338
                        I.SetSrc1Address(GetAddressFromIdentifier($1,yylloc));
339
                        I.SetSrc0Address(GetAddressFromIdentifier($3,yylloc));
340
                        mInstructions.push_back(I);
341
                        gInsertedInstructions++;
342
                        I.Clear();
343
                        std::stringstream ss;
344
                        ss << "R" << TempRegIndex;
345
                        $$ = ss.str();
346
                }
347
                |
348
                expression MINUS term
349
                {
350
                        unsigned int TempRegIndex  = GetFreeTempRegister();
351
                        I.SetOperation( EOPERATION_SUB );
352
                        I.SetDestinationAddress( TempRegIndex );
353
                        I.SetSrc1Address(GetAddressFromIdentifier($1,yylloc));
354
                        I.SetSrc0Address(GetAddressFromIdentifier($3,yylloc));
355
                        mInstructions.push_back(I);
356
                        gInsertedInstructions++;
357
                        I.Clear();
358
                        std::stringstream ss;
359
                        ss << "R" << TempRegIndex;
360
                        $$ = ss.str();
361
                }
362
                |
363
                term
364
                {
365
                        $$ = $1;
366
                }
367
                ;
368
 
369
                term
370
                :
371
                factor SHL factor
372
                {
373
 
374
                        unsigned int TempRegIndex  = GetFreeTempRegister();
375
                        I.SetOperation( EOPERATION_SHL );
376
                        I.SetDestinationAddress( TempRegIndex );
377
                        I.SetSrc1Address(GetAddressFromIdentifier($1,yylloc));
378
                        I.SetSrc0Address(GetAddressFromIdentifier($3,yylloc));
379
                        mInstructions.push_back(I);
380
                        gInsertedInstructions++;
381
                        I.Clear();
382
                        std::stringstream ss;
383
                        ss << "R" << TempRegIndex;
384
                        $$ = ss.str();
385
                }
386
                |
387
                factor SHR factor
388
                {
389
                        unsigned int TempRegIndex  = GetFreeTempRegister();
390
                        I.SetOperation( EOPERATION_SHR );
391
                        I.SetDestinationAddress( TempRegIndex );
392
                        I.SetSrc1Address(GetAddressFromIdentifier($1,yylloc));
393
                        I.SetSrc0Address(GetAddressFromIdentifier($3,yylloc));
394
                        mInstructions.push_back(I);
395
                        gInsertedInstructions++;
396
                        I.Clear();
397
                        std::stringstream ss;
398
                        ss << "R" << TempRegIndex;
399
                        $$ = ss.str();
400
                }
401
                |
402
                factor BITWISE_AND factor
403
                {
404
                        unsigned int TempRegIndex  = GetFreeTempRegister();
405
                        I.SetOperation( EOPERATION_AND );
406
                        I.SetDestinationAddress( TempRegIndex );
407
                        I.SetSrc1Address(GetAddressFromIdentifier($1,yylloc));
408
                        I.SetSrc0Address(GetAddressFromIdentifier($3,yylloc));
409
                        mInstructions.push_back(I);
410
                        gInsertedInstructions++;
411
                        I.Clear();
412
                        std::stringstream ss;
413
                        ss << "R" << TempRegIndex;
414
                        $$ = ss.str();
415
                }
416
                |
417
                factor
418
                {
419
                        $$ = $1;
420
                }
421
                ;
422
 
423
                factor
424
                :
425
                IDENTIFIER
426
                {
427
                        $$ = $1;
428
                }
429
                |
430
                OPEN_ROUND_BRACE expression CLOSE_ROUND_BRACE
431
                {
432
                        $$ = $2;
433
                }
434
                |
435
                constant
436
                {
437
                        unsigned int ImmediateValue;
438
                        std::string StringHex = $1;
439
                        std::stringstream ss;
440
                        ss << std::hex << StringHex;
441
                        ss >> ImmediateValue;
442
                        unsigned int TempRegIndex  = GetFreeTempRegister();
443
                        I.SetOperation( EOPERATION_ASSIGN );
444
                //      I.mSourceLine = GetCurrentLineNumber( yylloc );
445
 
446
                        I.SetDestinationAddress( TempRegIndex );
447
 
448
                        I.SetLiteral(ImmediateValue);
449
 
450
                        mInstructions.push_back(I);
451
 
452
                        gInsertedInstructions++;
453
                        I.Clear();
454
                        std::stringstream ss2;
455
                        ss2 << "R" << TempRegIndex;
456
                        $$ = ss2.str();
457
                }
458
                ;
459
 
460
 
461
 
462
constant
463
        :
464
                DECCONST
465
                {
466
                        // Transform to HEX string
467
                        unsigned int Val;
468
                        std::string StringDec = $1;
469
                        std::stringstream ss;
470
                        ss << StringDec;
471
                        ss >> Val;
472
                        std::stringstream ss2;
473
                        ss2 << std::hex << Val;
474
                        $$ = ss2.str();
475
                }
476
                |
477
                HEXCONST
478
                {
479
                        std::string StringHex = $1;
480
                        // Get rid of the 0x
481
                        StringHex.erase(StringHex.begin(),StringHex.begin()+2);
482
                        std::stringstream ss;
483
                        ss << std::hex << StringHex;
484
 
485
                        $$ = ss.str();
486
                }
487
                |
488
                BINCONST
489
                {
490
                        // Transform to HEX string
491
                        std::string StringBin = $1;
492
                        // Get rid of the 0b
493
                        StringBin.erase(StringBin.begin(),StringBin.begin()+2);
494
                        std::bitset<32> Bitset( StringBin );
495
                        std::stringstream ss2;
496
                        ss2 << std::hex <<  Bitset;
497
                        $$ = ss2.str();
498
                }
499
        ;
500
 
501
boolean_expression
502
        :
503
        BLOCK_TRANSFER_IN_PROGRESS
504
        {
505
 
506
                        unsigned int ImmediateValue = 0x1;
507
                        unsigned int TempRegIndex0  = GetFreeTempRegister();
508
                        I.SetOperation( EOPERATION_ASSIGN );
509
                        I.SetDestinationAddress( TempRegIndex0 );
510
                        I.SetLiteral(ImmediateValue);
511
                        mInstructions.push_back(I);
512
                        gInsertedInstructions++;
513
 
514
 
515
                        I.SetOperation( EOPERATION_BEQ );
516
                        I.SetDestinationAddress( 0 );
517
                        I.SetSrc1Address( STATUS_REG );
518
                        I.SetSrc0Address(TempRegIndex0);
519
                        mInstructions.push_back(I);
520
                        gInsertedInstructions++;
521
                        gBranchStack.push_back(mInstructions.size() - 1);
522
                        I.Clear();
523
 
524
                        I.SetOperation( EOPERATION_NOP );
525
                        I.mComment = "branch delay";
526
                        I.SetDestinationAddress( gWhileLoopAddress );
527
                        mInstructions.push_back(I);
528
                        I.Clear();
529
 
530
 
531
 
532
        }
533
        |
534
        expression EQUAL expression
535
        {
536
 
537
                        I.SetOperation( EOPERATION_BNE );
538
                        I.SetDestinationAddress( 0 );
539
                        I.SetSrc1Address( GetAddressFromIdentifier($1,yylloc) );
540
                        I.SetSrc0Address( GetAddressFromIdentifier($3,yylloc));
541
                        mInstructions.push_back(I);
542
                        gInsertedInstructions++;
543
                        gBranchStack.push_back(mInstructions.size() - 1);
544
                        I.Clear();
545
 
546
                        I.SetOperation( EOPERATION_NOP );
547
                        I.mComment = "branch delay";
548
                        I.SetDestinationAddress( gWhileLoopAddress );
549
                        mInstructions.push_back(I);
550
                        I.Clear();
551
 
552
        }
553
        |
554
        expression LESS_OR_EQUAL_THAN expression
555
        {
556
 
557
                        I.SetOperation( EOPERATION_BLE );
558
                        I.SetDestinationAddress( 0 );
559
                        I.SetSrc1Address( GetAddressFromIdentifier($1,yylloc) );
560
                        I.SetSrc0Address( GetAddressFromIdentifier($3,yylloc));
561
                        mInstructions.push_back(I);
562
                        gInsertedInstructions++;
563
                        gBranchStack.push_back(mInstructions.size() - 1);
564
                        I.Clear();
565
 
566
                        I.SetOperation( EOPERATION_NOP );
567
                        I.mComment = "branch delay";
568
                        I.SetDestinationAddress( gWhileLoopAddress );
569
                        mInstructions.push_back(I);
570
                        I.Clear();
571
 
572
        }
573
;
574
scalar_list
575
                        :
576
                        IDENTIFIER COMMA scalar_list
577
                        {
578
                                if (gVaribleMap.find($1) != gVaribleMap.end())
579
                                {
580
                                        std::ostringstream ret;
581
                                        ret << "Duplicated symbol '" << $1 << "'\n";
582
                                        throw ret.str();
583
                                }
584
 
585
                                gVaribleMap[ $1 ] = AllocateVariable();
586
                        }
587
                        |
588
                        IDENTIFIER ASSIGN constant COMMA scalar_list
589
                        {
590
                                if (gVaribleMap.find($1) != gVaribleMap.end())
591
                                {
592
                                        std::ostringstream ret;
593
                                        ret << "Duplicated symbol '" << $1 << "'\n";
594
                                        throw ret.str();
595
                                }
596
 
597
                                gVaribleMap[ $1 ] = AllocateVariable();
598
                                I.mSourceLine = GetCurrentLineNumber( yylloc );
599
                                I.SetOperation( EOPERATION_ASSIGN );
600
                                I.SetDestinationAddress( gVaribleMap[ $1 ] );
601
                                I.SetLiteral( atoi($3.c_str() ) );
602
                                mInstructions.push_back( I );
603
                                I.Clear();
604
 
605
                        }
606
                        |
607
                        IDENTIFIER ASSIGN constant
608
                        {
609
                                if (gVaribleMap.find($1) != gVaribleMap.end())
610
                                {
611
                                        std::ostringstream ret;
612
                                        ret << "Duplicated symbol '" << $1 << "'\n";
613
                                        throw ret.str();
614
                                }
615
                                unsigned int ImmediateValue;
616
                                std::string StringHex = $3;
617
                                std::stringstream ss;
618
                                ss << std::hex << StringHex;
619
                                ss >> ImmediateValue;
620
                                gVaribleMap[ $1 ] = AllocateVariable();
621
                                I.mSourceLine = GetCurrentLineNumber( yylloc );
622
                                I.SetOperation( EOPERATION_ASSIGN );
623
                                I.SetDestinationAddress( gVaribleMap[ $1 ] );
624
                                I.SetLiteral( ImmediateValue );
625
                                mInstructions.push_back( I );
626
                                I.Clear();
627
                        }
628
                        |
629
                        IDENTIFIER
630
                        {
631
                                if (gVaribleMap.find($1) != gVaribleMap.end())
632
                                {
633
                                        std::ostringstream ret;
634
                                        ret << "Duplicated symbol '" << $1 << "'\n";
635
                                        throw ret.str();
636
                                }
637
 
638
                                gVaribleMap[ $1 ] = AllocateVariable();
639
                        }
640
                        ;
641
 
642
 
643
%%
644
 
645
 
646
 
647
// Error function throws an exception (std::string) with the location and error message
648
void Theia::Parser::error(const Theia::Parser::location_type &loc,
649
                                          const std::string &msg) {
650
        std::ostringstream ret;
651
        ret << "\ncp_compile -- Parser Error at " << loc << ": "  << msg;
652
        throw ret.str();
653
}
654
 
655
// Now that we have the Parser declared, we can declare the Scanner and implement
656
// the yylex function
657
#include "Scanner.h"
658
static int yylex(Theia::Parser::semantic_type * yylval,
659
                 Theia::Parser::location_type * yylloc,
660
                 Theia::Scanner &scanner) {
661
        return scanner.yylex(yylval, yylloc);
662
}
663
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.