summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/ifcompiler/initCompiler.lex
blob: 26574b6325607ff341ac69b5c6f10b26ee42a03a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/*  IBM_PROLOG_BEGIN_TAG
 *  This is an automatically generated prolog.
 *
 *  $Source: src/usr/hwpf/ifcompiler/initCompiler.lex $
 *
 *  IBM CONFIDENTIAL
 *
 *  COPYRIGHT International Business Machines Corp. 2010-2012
 *
 *  p1
 *
 *  Object Code Only (OCO) source materials
 *  Licensed Internal Code Source Materials
 *  IBM HostBoot Licensed Internal Code
 *
 *  The source code for this program is not published or other-
 *  wise divested of its trade secrets, irrespective of what has
 *  been deposited with the U.S. Copyright Office.
 *
 *  Origin: 30
 *
 *  IBM_PROLOG_END_TAG
 */
/* Change Log *************************************************************************************
//                                                                      
//  Flag Track    Userid   Date       Description                
//  ---- -------- -------- --------   -------------------------------------------------------------
//       D754106  dgilbert 06/14/10   Create
//  dg01 D766229  dgilbert 08/03/10   add check for hex/bin data > 64 bits
//  dg02 SW058986 dgilbert 02/28/11   More noticeable fail for missing col headers
//                andrewg  09/19/11   Updates based on review
//                camvanng 11/08/11   Added support for attribute enums
//                camvanng 11/16/11   Support system & target attributes
//                camvanng 12/12/11   Support multiple address ranges within a SCOM address
//                camvanng 01/20/12   Support for using a range of indexes for array attributes
//                camvanng 02/07/12   Ability to #include common scom initfile defines
//                camvanng 02/14/12   Support binary and hex scom addresses
//                                    Support for array at beginning of scom address
//                camvanng 04/12/12   Right justify SCOM data
//                                    Ability to specify search paths for include files
//                camvanng 04/16/12   Support defines for SCOM address
//                                    Support defines for bits, scom_data and attribute columns
//                camvanng 05/07/12   Support for associated target attributes
//                                    Save and restore line numbers for each include file
//                camvanng 05/22/12   Fix "OP" definition
//                camvanng 06/11/12   Fix shift/reduce warnings from yacc
// End Change Log *********************************************************************************/
/**
 * @file initCompiler.lex
 * @brief Contains the rules for the lex/flex  lexical scanner for scanning initfiles
 * 
 * This code runs as part of the build process to generate a
 * byte-coded representation of an initfile
 */
%{
#include <stdint.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <initRpn.H>
#include <y.tab.h>

uint64_t bits2int( const char * bitString);
uint64_t hexs2int(const char * hexString, int32_t size);
void pushBackScomBody();
void push_col(const char *s);
void lex_err(const char *s );
void add_define(const char *s);
void pushBackDefine(const char *s);

std::ostringstream oss;
std::ostringstream t_oss;

typedef std::vector<std::ostringstream *> OSS_LIST;
OSS_LIST g_colstream;

inline void clear_colstream() 
{ for( OSS_LIST::iterator i = g_colstream.begin(); i != g_colstream.end(); ++i) delete *i;
  g_colstream.clear();
}
uint32_t g_scomcol;
uint32_t g_coltype = 0;
uint32_t g_scomtype = 0;
uint32_t g_paren_level = 0;
bool g_equation = false;   // equation inside scomv col
std::string g_scomname;     // dg02
std::string g_scomdef_name;
std::map<std::string,std::string> g_defines; //container for all the defines
    //i.e. define def_A = (attrA > 1) => key = "DEF_A", value = "(attr_A > 1)"

std::string g_target;  //storage for current target

extern int yyline;
extern std::vector<std::string> yyincludepath;
extern std::map<std::string,std::string> yytarget; //container for all defined targets
    //i.e. define MBA0 = TGT1 => key = "TGT1", value = "MBA0"

#define MAX_INCLUDE_DEPTH 10
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
int yyline_stack[MAX_INCLUDE_DEPTH];
int include_stack_num = 0;

%}




NEWLINE  \n
FILENAME [A-Za-z][A-Za-z0-9_\.]*
ID      [A-Za-z][A-Za-z0-9_]*
ID2     [A-Za-z][A-Za-z0-9_]*(\[[0-9]+(..[0-9]+)?(,[0-9]+(..[0-9]+)?)*\]){0,4}
ID3      [0-9]+[A-Za-z_]+[0-9]*
DIGIT    [0-9]
COMMENT  #.*\n
OP      "="|"+"|"-"|"!"|"<"|">"|"*"|"/"|"%"
FLOAT   [0-9]+"."[0-9]*
BINARY  0[bB][0-1]+
SINGLE_BIN [0-1]
SCOM_DATA [ ]*[scom_data][ ]+
HEX     0[xX][A-Fa-f0-9]+
SINGLE_HEX [A-Fa-f0-9]
ATTRIBUTE [\[[A-Fa-f0-9]\]]
MULTI_DIGIT [0-9]+

%x      scomop 
%x      scomop_hex 
%x      scomop_hex_array
%x      scomop_hex_suffix
%x      scomop_bin
%x      scomop_bin_array
%x      scomop_bin_suffix
%x      scomdata
%x      when_kw
%x      when_expr
%x      scomcolname
%x      scomrow
%x      list
%x      enumcol
%x      fnames
%x      target
%x      attribute
%x      array
%x      incl
%x      scomdef
%x      scomdef_value


%%

{COMMENT}               ++yyline;    /* toss comments  - need first line */
\$Id:.*\n               ++yyline;    /* toss this - read by initCompiler.C */

 /* Special end-of-file character. */
<<EOF>>		        {
                        if (--include_stack_num < 0)
                        {
                            g_defines.clear();
                            return 0;
                        }
                        else
                        {
                            yy_delete_buffer(YY_CURRENT_BUFFER);
                            fclose(yyin);
                            yy_switch_to_buffer(include_stack[include_stack_num]);
                            yyline = yyline_stack[include_stack_num];
                        }
                    }

SyntaxVersion           return INIT_VERSION;

 /* The list of initfile versions is just copied into the *.if file
  * so just make it one chunk of string data */
Versions                BEGIN(fnames);
<fnames>[=]             oss.str("");
<fnames>{FLOAT}         oss << yytext;
<fnames>[:]             oss << yytext;
<fnames>[,]             oss << ", ";
<fnames>{FILENAME}      oss << yytext;
<fnames>{NEWLINE}       {   ++yyline;
                            yylval.str_ptr = new std::string(oss.str());
                            BEGIN(INITIAL);
                            return INIT_VERSIONS;
                        }

include                 { BEGIN(incl); }
<incl>[ \t]*            /* Eat up whitespace */
<incl>[^ \t\n]+         {   /* Got the include file name */
                            /*printf("lex: include file %s\n", yytext);*/
                            if ( include_stack_num >= MAX_INCLUDE_DEPTH )
                            {
                                lex_err("Includes nested too deeply");
                                exit( 1 );
                            }

                            /* Save current line number */
                            yyline_stack[include_stack_num] =
                                yyline;

                            /* Save current input buffer */
                            include_stack[include_stack_num++] =
                                YY_CURRENT_BUFFER;

                            /* Switch input buffer */
                            std::string filename = yytext;
                            yyin = fopen( filename.c_str(), "r" );
                            for (size_t i = 0; (i < yyincludepath.size()) && (NULL == yyin); i++)
                            {
                                filename = yyincludepath.at(i) + "/" + yytext;
                                yyin = fopen( filename.c_str(), "r" );
                            }
                            if (NULL == yyin)
                            {
                                oss.str("");
                                oss << "Cannot open file: " << yytext;
                                lex_err(oss.str().c_str());
                                exit(1);
                            }
                            printf("Include file %s\n", filename.c_str());
                            yyline = 1;  //set line number for new buffer
                            yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));

                            BEGIN(INITIAL);
                        }

                         /* Adding the ability to use defines for SCOM address and the different
                          * columns (bits, scom_data and attribute columns).
                          * Since the SCOM address and the different columns all have different
                          * parsing rules, it is complicated to handle this in both the scanner and parser.
                          * The simplest thing to do is to keep track of all the defines in the scanner
                          * then push the specific define value back into the input stream for scanning
                          * when it is used.
                          */

define                       { BEGIN(scomdef); }

<scomdef>{ID}                { g_scomdef_name = yytext; }
<scomdef>[ \t\r]*=[ \t\r]*   { BEGIN(scomdef_value); }
<scomdef_value>[^;\n#\{\}]+  { add_define(yytext); }
<scomdef_value>;             { g_scomdef_name = ""; BEGIN(INITIAL); }

scom              { BEGIN(scomop); oss.str("");  return INIT_SCOM; }

<scomop>{HEX} { /*printf("lex: hex string %s\n", yytext);*/
                yylval.str_ptr = new std::string(yytext);
                BEGIN(scomop_hex);
                return INIT_SCOM_ADDR; 
              }

<scomop>0[xX] { BEGIN(scomop_hex); }
<scomop>0[bB] { BEGIN(scomop_bin); }

<scomop_hex,scomop_hex_suffix>[\(] {
                    /*printf("lex: hex string %s\n", yytext);*/
                    BEGIN(scomop_hex_array);
                }

<scomop_hex_array>{SINGLE_HEX}+\.\.{SINGLE_HEX}+ {
                    /*printf("lex: hex string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_INT64_STR; 
                }

<scomop_hex_array>{SINGLE_HEX}+ {
                    /*printf("lex: hex string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_INT64_STR; 
                }

<scomop_hex_array>[\)] {
                    /*printf("lex: hex string %s\n", yytext);*/
                    BEGIN(scomop_hex_suffix);
                }

<scomop_hex,scomop_hex_suffix>{SINGLE_HEX}+ {
                    /*printf("lex: hex string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_SCOM_SUFFIX; 
                }

<scomop_hex,scomop_hex_suffix>\.0[bB] { BEGIN(scomop_bin); return yytext[0]; }

<scomop_bin>{SINGLE_BIN}+ {
                    /*printf("lex: bin string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_SCOM_ADDR_BIN;
                }

<scomop_bin,scomop_bin_suffix>[\(] {
                    /*printf("lex: bin string %s\n", yytext);*/
                    BEGIN(scomop_bin_array);
                }
<scomop_bin_array>{SINGLE_BIN}+\.\.{SINGLE_BIN}+ {
                    /*printf("lex: bin string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_BINARY_STR;
                }

<scomop_bin_array>{SINGLE_BIN}+ {
                    /*printf("lex: bin string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_BINARY_STR;
                }

<scomop_bin_array>[\)] {
                    /*printf("lex: bin string %s\n", yytext);*/
                    BEGIN(scomop_bin_suffix);
                }

<scomop_bin_suffix>{SINGLE_BIN}+ {
                    /*printf("lex: bin string %s\n", yytext);*/
                    yylval.str_ptr = new std::string(yytext);
                    return INIT_SCOM_SUFFIX_BIN;
                }

<scomop_bin,scomop_bin_suffix>\.(0[xX])? {
                    /*printf("lex: bin string %s\n", yytext);*/
                    BEGIN(scomop_hex); return yytext[0];
                }

<scomop_bin,scomop_bin_suffix>\.0[bB] {
                    /*printf("lex: bin string %s\n", yytext);*/
                }

<scomop_hex_array,scomop_bin_array>{ID}\.\.{ID} { pushBackDefine(yytext); }
<scomop_hex,scomop_hex_suffix,scomop_bin,scomop_bin_suffix>\.{ID} { pushBackDefine(yytext + 1); unput('.'); }
<scomop,scomop_hex_array,scomop_hex_suffix,scomop_bin_array,scomop_bin_suffix>{ID}  { pushBackDefine(yytext); }

<scomop>[:;\[]    { BEGIN(INITIAL); g_coltype = 0; return yytext[0]; }
<scomop>{NEWLINE} { BEGIN(INITIAL); ++yyline; }

<scomop_hex,scomop_hex_suffix,scomop_bin,scomop_bin_suffix>[\{]   {  
                                 oss.str("");
                                 BEGIN(scomcolname);
                                 return yytext[0];
                             }




                         /* The column & row format is really hard to handle in the parser,
                          * especially since each column can have different parsing rules.
                          * So fix it here in the scanner by converting the format to
                          * coltitle1 , row1, row2, ..., row n ;
                          * coltitle2 , row1, row2, ..., row n ;
                          * then push it all back into the input stream and scan the new format
                          */	

<scomcolname>{COMMENT}   ++yyline;
<scomcolname>\n          ++yyline;
<scomcolname>{ID2}        {
                            g_colstream.push_back(new std::ostringstream());
                            *(g_colstream.back()) << yytext;
                         }
<scomcolname>,           {}
<scomcolname>;           { BEGIN(scomrow); g_scomcol = 0; }

<scomrow>{COMMENT}       ++yyline;
<scomrow>{NEWLINE}       ++yyline;
<scomrow>([^,;\n#\{\}]+{ID2}*)+ push_col(yytext);
<scomrow>[,]             ++g_scomcol;
<scomrow>[;]             g_scomcol = 0;
<scomrow>[\}]            {
                            pushBackScomBody();  // create new format and put it back on yyin
                            BEGIN(INITIAL);
                         }


                        /* The scombody is the modified format - don't track yyline as it's already
                         * accounted for. Any errors in here will point back to the last line in the
                         * 'real' scombody 
                         */
              
bits                    { g_coltype = INIT_BITS;  return INIT_BITS;}
expr                    { g_coltype = INIT_EXPR;  return INIT_EXPR;}
scom_data               { g_coltype = INIT_SCOMD; return INIT_SCOMD;}

                        /*HEX and Binary numbers in the scombody can be up to 64bit, 
                        * decimal numbers will always fit in 32bit int */

{BINARY}                { yylval.uint64 = bits2int(yytext); return INIT_INT64; }

<*>;                    { g_coltype = 0; return ';'; }
                            
END_INITFILE            return INIT_ENDINITFILE;

<*>SYS\.                yymore(); //System attribute

<*>TGT{MULTI_DIGIT}\.   {
                            if (g_target.length())
                            {
                                std::string tgt(yytext);
                                tgt = tgt.substr(0, tgt.length() -1);
                                yytarget[tgt] = g_target;
                                g_target.clear();
                            }

                            yymore(); //Associated target attribute
                        }

                        /* All attribute enums start with "ENUM_ATTR_" */
<*>ENUM_ATTR_{ID}       {
                            yylval.str_ptr = new std::string(yytext); return ATTRIBUTE_ENUM;
                        } 

                        /* All attributes start with "ATTR_"; then there's "any". */
<*>ATTR_{ID}|"any"      {
                            yylval.str_ptr = new std::string(yytext); return INIT_ID; 
                        }

                        /* Anything else is a define.
                         * Removing any requirements that defines has to start with "def_" or "DEF_" */
<*>{ID}\.               {   // push back the define value for scanning
                            g_target = yytext;
                            g_target = g_target.substr(0, g_target.length() - 1);
                            //printf("lex: %s\n", g_target.c_str());
                            unput('.');
                            pushBackDefine(g_target.c_str());
                        }

<*>{ID}                 {   // push back the define value for scanning
                            pushBackDefine(yytext);
                        } 

<*>{DIGIT}+             {
                          sscanf(yytext, "%d", &yylval.integer); return INIT_INTEGER;
                        }

<*>{HEX}                {
                            // normal right-justified 64 bit hex integer
                            yylval.uint64 = hexs2int(yytext,yyleng);
                            return INIT_INT64;
                        }

<*>"&&"                 return INIT_LOGIC_AND;
<*>"||"                 return INIT_LOGIC_OR;
<*>"=="                 return INIT_EQ;
<*>"!="                 return INIT_NE;
<*>"<="                 return INIT_LE;
<*>">="                 return INIT_GE;
<*>">>"                 return INIT_SHIFT_RIGHT;
<*>"<<"                 return INIT_SHIFT_LEFT;

<*>{OP}                 { g_equation = true; return yytext[0]; }
<*>[\(]                 { ++g_paren_level; return yytext[0]; }
<*>[\)]                 { --g_paren_level; return yytext[0]; }

<*>\[({MULTI_DIGIT}[,.]*)+\]    { yylval.str_ptr = new std::string(yytext);  return ATTRIBUTE_INDEX; }

<*>[\[\]\{\},:]         {g_equation = false; return yytext[0]; }

<*>[ \t\r]+             /* Eat up whitespace */
[\n]                    { BEGIN(INITIAL);++yyline;}

<*>.                    lex_err(yytext);

%%

int yywrap() { return 1; }

void lex_err(const char *s )
{
    std::cerr << "\nERROR: lex: " << s << " -line " << yyline << std::endl;
}

// Convert left justified bitstring to right-justified 64 bit integer
uint64_t bits2int( const char * bitString)
{
    uint32_t idx = 0;
    uint64_t mask = 0x0000000000000001ull;
    uint64_t val = 0;
    do
    {
      if( (bitString[0] != '0') ||
          ((bitString[1] != 'b') && (bitString[1] != 'B')))
      {
          lex_err("Invalid bit string");
          break;
      }
      idx = 2;

      while( bitString[idx] != 0 )
      {
          val <<= 1;
          char c = bitString[idx];
          if( c == '1') val |= mask;
          else if(c != '0')
          {
              lex_err("Invalid bit string");
              break;
          }
          ++idx;
      }
      if(idx > 66) //dg01a  64bits + "0B" prefix
          lex_err("Bit string greater than 64 bits!");

     } while (0);
    return val;   
}

// Convert left justified hex string to 64 right-justified bit integer
uint64_t hexs2int(const char * hexString, int32_t size)
{
    uint64_t val = 0;
    std::string s(hexString);
    if(size > 18) //dg01a
    {
        lex_err("HEX literal greater than 64 bits");
        size = 18;
    }
    s.insert(2, 18-size,'0');  // 0x + 16 digits
    val = strtoull(s.c_str(),NULL,16);
    return val;
}

void pushBackScomBody()
{
    std::ostringstream ost;
    for(OSS_LIST::iterator i = g_colstream.begin(); i != g_colstream.end(); ++i)
    {
        ost << (*i)->str() << ';';
    }
    ost << '}';
    std::string t = ost.str();  // Was causing weird stuff if I didn't copy the string out first
    //std::cout << "<lex comment> Pushing:" << t << std::endl;
    //std::cout << "<lex comment> " << std::endl;

    for(std::string::reverse_iterator r = t.rbegin();
        r != t.rend();
        ++r)
    {
       //std::cout << *r;
        unput(*r);
    }
    //std::cout << std::endl;
    clear_colstream();
}


/// help collect column data
void push_col(const char * s)
{
    //dg02a begin
    while(g_scomcol >= g_colstream.size())  // more data cols than headers cols
    {
        // This will force an error in the parser where it can stop the compile.
        g_colstream.push_back(new std::ostringstream());
        *(g_colstream.back()) << "MISSING_COLUMN_HEADER";
        lex_err(g_scomname.c_str());
        lex_err("Invalid number of scom cols");
    }
    //dgxxa end
    //dgxxd remove if(g_colstream < g_colstream.size() 

    std::ostringstream & o = *(g_colstream[g_scomcol]);
    std::ostringstream token;
    std::istringstream iss(s);
    std::string t;
    //std::cout << "Pushing ";
    while(iss >> t) token << t; // get rid of white space
    if(token.str().size()) // don't add blank tokens
    {
        //std::cout << "Pushing ," << token.str() << std::endl;
        o << ',' << token.str();
    }
}


/// Save the define
void add_define(const char * s)
{
    if (g_defines.end() != g_defines.find(g_scomdef_name))
    {
        oss.str("");
        oss << g_scomdef_name << " already defined";
        lex_err(oss.str().c_str());
        exit(1);
    }

    //remove trailing white spaces
    std::string str(s);
    std::string whitespaces(" \t\r");
    size_t pos;
    pos=str.find_last_not_of(whitespaces);
    if (pos != std::string::npos)
    {
        str.erase(pos+1);
    }

    g_defines[g_scomdef_name] =  str;
    //std::cout << "g_defines[" << g_scomdef_name << "] = " << g_defines[g_scomdef_name] << std::endl;
}

// Push the define(s) back into the input stream for scanning
void pushBackDefine(const char *s)
{
    std::string key(s); //set key to input string
    std::string key2;
    std::string value;

    //std::cout << "lex: pushBackDefine input string: " << s << " key: " << key << std::endl;

    //Is this a range?
    size_t pos = key.find("..");
    if (pos != std::string::npos)
    {
        key2 = key.substr(pos+2); //2nd key in the range
        key = key.substr(0,pos);  //Reset 1st key in the range
    }

    //Exit if cannot find 1st key
    if (g_defines.end() == g_defines.find(key))
    {
        oss.str("");
        oss << "Cannot find define " << key;
        lex_err(oss.str().c_str());
        exit(1);
    }

    // Set value string
    value = g_defines[key];
    if (key2.size())
    {
        //Exit if cannot find 2nd key
        if (g_defines.end() == g_defines.find(key2))
        {
            oss.str("");
            oss << "Cannot find define " << key;
            lex_err(oss.str().c_str());
            exit(1);
        }

        //Get rid of spaces & append key2 value
        size_t pos = value.find(' ');
        if (pos != std::string::npos)
        {
            value = value.substr(0,pos);
        }
        value += ".." + g_defines[key2];
    }

    //std::cout << "lex: pushBackDefine: " << value << std::endl;

    //Push back the value into the input stream
    for(std::string::reverse_iterator r = value.rbegin();
        r != value.rend();
        ++r)
    {
        //std::cout << *r;
        unput(*r);
    }
    //std::cout << std::endl;
}
OpenPOWER on IntegriCloud