Changeset 6774 for branches


Ignore:
Timestamp:
Sep 20, 2001, 4:08:10 PM (24 years ago)
Author:
bird
Message:

Merged in more the rest of the SDS fixes.

Location:
branches/stage2/tools/database/occ
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/stage2/tools/database/occ/parse.cpp

    r6768 r6774  
    3434
    3535#if defined(_PARSE_VCC)
    36 #define _MSC_VER        1100
     36#define _MSC_VER        1100
    3737#endif
    3838
     
    4848{
    4949    if(where != nil){
    50         Ptree* head = where->Ca_ar();
    51         if(head != nil)
    52             ShowMessageHead(head->GetPosition());
     50        Ptree* head = where->Ca_ar();
     51        if(head != nil)
     52            ShowMessageHead(head->GetPosition());
    5353    }
    5454
    5555    cerr << msg;
    5656    if(name != nil)
    57         name->Write(cerr);
     57        name->Write(cerr);
    5858
    5959    cerr << '\n';
     
    6464{
    6565    if(where != nil){
    66         Ptree* head = where->Ca_ar();
    67         if(head != nil)
    68             ShowMessageHead(head->GetPosition());
     66        Ptree* head = where->Ca_ar();
     67        if(head != nil)
     68            ShowMessageHead(head->GetPosition());
    6969    }
    7070
    7171    cerr << "warning: " << msg;
    7272    if(name != nil)
    73         name->Write(cerr);
     73        name->Write(cerr);
    7474
    7575    cerr << '\n';
     
    8787    cerr << "parse error before `";
    8888    if(t.kind != '\0')
    89         for(i = 0; i < t.len; ++i)
    90             cerr << t.ptr[i];
     89        for(i = 0; i < t.len; ++i)
     90            cerr << t.ptr[i];
    9191
    9292    if(t2.kind != '\0'){
    93         cerr << ' ';
    94         for(i = 0; i < t2.len; ++i)
    95             cerr << t2.ptr[i];
     93        cerr << ' ';
     94        for(i = 0; i < t2.len; ++i)
     95            cerr << t2.ptr[i];
    9696    }
    9797
     
    100100}
    101101
     102#ifdef SDS
    102103uint Parser::LineNumber(char* pos, char*& fname, int& fname_len)
    103104{
     105   int col_num, abs_len;
     106
     107   return LineNumber(pos, fname, fname_len, col_num, abs_len);
     108}
     109#endif
     110
     111#ifdef SDS
     112uint Parser::LineNumber(char* pos, char*& fname, int& fname_len, int& col_num, int& abs_len)
     113#else
     114uint Parser::LineNumber(char* pos, char*& fname, int& fname_len)
     115#endif
     116{
     117    #ifdef SDS
     118    uint line_number = lex->LineNumber(pos, fname, fname_len, col_num, abs_len);
     119    #else
    104120    uint line_number = lex->LineNumber(pos, fname, fname_len);
     121    #endif
    105122    if(fname_len > 1){
    106         if(fname[0] == '"') {
    107             ++fname;
    108             --fname_len;
    109         }
    110 
    111         if(fname[fname_len - 1] == '"')
    112             --fname_len;
     123        if(fname[0] == '"') {
     124            ++fname;
     125            --fname_len;
     126        }
     127
     128        if(fname[fname_len - 1] == '"')
     129            --fname_len;
    113130    }
    114131
     
    124141    int i = 0;
    125142    while(i < fname_len)
    126         cerr << fname[i++];
     143        cerr << fname[i++];
    127144
    128145#if defined(_MSC_VER)
     
    136153{
    137154    while(lex->LookAhead(0) != '\0')
    138         if(rDefinition(def))
    139             return TRUE;
    140         else{
    141             Token tk;
    142             if(!SyntaxError())
    143                 return FALSE;           // too many errors
    144 
    145             SkipTo(';');
    146             lex->GetToken(tk);  // ignore ';'
    147         }
     155        if(rDefinition(def))
     156            return TRUE;
     157        else{
     158            Token tk;
     159            if(!SyntaxError())
     160                return FALSE;           // too many errors
     161
     162            SkipTo(';');
     163            lex->GetToken(tk);  // ignore ';'
     164        }
    148165
    149166    return FALSE;
     
    167184    int t = lex->LookAhead(0);
    168185    if(t == ';')
    169         res = rNullDeclaration(p);
     186        res = rNullDeclaration(p);
    170187    else if(t == TYPEDEF)
    171         res = rTypedef(p);
     188        res = rTypedef(p);
    172189    else if(t == TEMPLATE)
    173         res = rTemplateDecl(p);
     190        res = rTemplateDecl(p);
    174191    else if(t == METACLASS)
    175         res = rMetaclassDecl(p);
     192        res = rMetaclassDecl(p);
    176193    else if(t == EXTERN && lex->LookAhead(1) == StringL)
    177         res = rLinkageSpec(p);
     194        res = rLinkageSpec(p);
    178195    else if(t == EXTERN && lex->LookAhead(1) == TEMPLATE)
    179         res = rExternTemplateDecl(p);
     196        res = rExternTemplateDecl(p);
    180197    else if(t == NAMESPACE)
    181         res = rNamespaceSpec(p);
     198        res = rNamespaceSpec(p);
    182199    else if(t == USING)
    183         res = rUsing(p);
     200        res = rUsing(p);
    184201    else {
    185         Ptree* c = lex->GetComments2();
    186         if (res = rDeclaration(p))
    187             Walker::SetDeclaratorComments(p, c);
     202        Ptree* c = lex->GetComments2();
     203        if (res = rDeclaration(p))
     204            Walker::SetDeclaratorComments(p, c);
    188205    }
    189206
     
    197214
    198215    if(lex->GetToken(tk) != ';')
    199         return FALSE;
     216        return FALSE;
    200217
    201218    decl = new PtreeDeclaration(nil, Ptree::List(nil, new Leaf(tk)));
     
    214231
    215232    if(lex->GetToken(tk) != TYPEDEF)
    216         return FALSE;
     233        return FALSE;
    217234
    218235    def = new PtreeTypedef(new LeafReserved(tk));
    219236    if(!rTypeSpecifier(type_name, FALSE, type_encode))
    220         return FALSE;
     237        return FALSE;
    221238
    222239    def = Ptree::Snoc(def, type_name);
    223240    if(!rDeclarators(decl, type_encode, TRUE))
    224         return FALSE;
     241        return FALSE;
    225242
    226243    if(lex->GetToken(tk) != ';')
    227         return FALSE;
     244        return FALSE;
    228245
    229246    def = Ptree::Nconc(def, Ptree::List(decl, new Leaf(tk)));
     
    240257
    241258    if(!optCvQualify(cv_q) || !optIntegralTypeOrClassSpec(tspec, encode))
    242         return FALSE;
     259        return FALSE;
    243260
    244261    if(tspec == nil){
    245         if(check){
    246             Token tk;
    247             lex->LookAhead(0, tk);
    248             if(!MaybeTypeNameOrClassTemplate(tk))
    249                 return FALSE;
    250         }
    251 
    252         if(!rName(tspec, encode))
    253             return FALSE;
     262        if(check){
     263            Token tk;
     264            lex->LookAhead(0, tk);
     265            if(!MaybeTypeNameOrClassTemplate(tk))
     266                return FALSE;
     267        }
     268
     269        if(!rName(tspec, encode))
     270            return FALSE;
    254271    }
    255272
    256273    if(!optCvQualify(cv_q2))
    257         return FALSE;
     274        return FALSE;
    258275
    259276    if(cv_q != nil){
    260         tspec = Ptree::Snoc(cv_q, tspec);
    261         if(cv_q2 != nil)
    262             tspec = Ptree::Nconc(tspec, cv_q2);
     277        tspec = Ptree::Snoc(cv_q, tspec);
     278        if(cv_q2 != nil)
     279            tspec = Ptree::Nconc(tspec, cv_q2);
    263280    }
    264281    else if(cv_q2 != nil)
    265         tspec = Ptree::Cons(tspec, cv_q2);
     282        tspec = Ptree::Cons(tspec, cv_q2);
    266283
    267284    encode.CvQualify(cv_q, cv_q2);
     
    284301#endif
    285302       )
    286         return TRUE;
     303        return TRUE;
    287304    else
    288         return FALSE;
     305        return FALSE;
    289306}
    290307
     
    297314  metaclass <metaclass> <class>(...);
    298315  metaclass <metaclass>;
    299   metaclass <class> : <metaclass>(...);         // for backward compatibility
     316  metaclass <class> : <metaclass>(...);         // for backward compatibility
    300317*/
    301318bool Parser::rMetaclassDecl(Ptree*& decl)
     
    306323
    307324    if(lex->GetToken(tk1) != METACLASS)
    308         return FALSE;
     325        return FALSE;
    309326
    310327    if(lex->GetToken(tk2) != Identifier)
    311         return FALSE;
     328        return FALSE;
    312329
    313330    t = lex->GetToken(tk3);
    314331    if(t == Identifier){
    315         metaclass_name = new Leaf(tk2);
    316         decl = new PtreeMetaclassDecl(new LeafReserved(tk1),
    317                                       Ptree::List(metaclass_name,
    318                                                   new Leaf(tk3)));
     332        metaclass_name = new Leaf(tk2);
     333        decl = new PtreeMetaclassDecl(new LeafReserved(tk1),
     334                                      Ptree::List(metaclass_name,
     335                                                  new Leaf(tk3)));
    319336    }
    320337    else if(t == ':'){
    321         if(lex->GetToken(tk4) != Identifier)
    322             return FALSE;
    323 
    324         metaclass_name = new Leaf(tk4);
    325         decl = new PtreeMetaclassDecl(new LeafReserved(tk1),
    326                                       Ptree::List(metaclass_name,
    327                                                   new Leaf(tk2)));
     338        if(lex->GetToken(tk4) != Identifier)
     339            return FALSE;
     340
     341        metaclass_name = new Leaf(tk4);
     342        decl = new PtreeMetaclassDecl(new LeafReserved(tk1),
     343                                      Ptree::List(metaclass_name,
     344                                                  new Leaf(tk2)));
    328345    }
    329346    else if(t == ';'){
    330         metaclass_name = new Leaf(tk2);
    331         decl = new PtreeMetaclassDecl(new LeafReserved(tk1),
    332                                       Ptree::List(metaclass_name, nil,
    333                                                   new Leaf(tk3)));
    334         Metaclass::Load(metaclass_name);
    335         return TRUE;
     347        metaclass_name = new Leaf(tk2);
     348        decl = new PtreeMetaclassDecl(new LeafReserved(tk1),
     349                                      Ptree::List(metaclass_name, nil,
     350                                                  new Leaf(tk3)));
     351        Metaclass::Load(metaclass_name);
     352        return TRUE;
    336353    }
    337354    else
    338         return FALSE;
     355        return FALSE;
    339356
    340357    t = lex->GetToken(tk1);
    341358    if(t == '('){
    342         Ptree* args;
    343         if(!rMetaArguments(args))
    344             return FALSE;
    345 
    346         if(lex->GetToken(tk2) != ')')
    347             return FALSE;
    348 
    349         decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1), args,
    350                                               new Leaf(tk2)));
    351         t = lex->GetToken(tk1);
     359        Ptree* args;
     360        if(!rMetaArguments(args))
     361            return FALSE;
     362
     363        if(lex->GetToken(tk2) != ')')
     364            return FALSE;
     365
     366        decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1), args,
     367                                              new Leaf(tk2)));
     368        t = lex->GetToken(tk1);
    352369    }
    353370
    354371    if(t == ';'){
    355         decl = Ptree::Snoc(decl, new Leaf(tk1));
    356         Metaclass::Load(metaclass_name);
    357         return TRUE;
     372        decl = Ptree::Snoc(decl, new Leaf(tk1));
     373        Metaclass::Load(metaclass_name);
     374        return TRUE;
    358375    }
    359376    else
    360         return FALSE;
     377        return FALSE;
    361378}
    362379
     
    372389    args = nil;
    373390    for(;;){
    374         t = lex->LookAhead(0);
    375         if(t == '\0')
    376             return FALSE;
    377         else if(t == '(')
    378             ++n;
    379         else if(t == ')')
    380             if(--n <= 0)
    381                 return TRUE;
    382 
    383         lex->GetToken(tk);
    384         args = Ptree::Snoc(args, new Leaf(tk));
     391        t = lex->LookAhead(0);
     392        if(t == '\0')
     393            return FALSE;
     394        else if(t == '(')
     395            ++n;
     396        else if(t == ')')
     397            if(--n <= 0)
     398                return TRUE;
     399
     400        lex->GetToken(tk);
     401        args = Ptree::Snoc(args, new Leaf(tk));
    385402    }
    386403}
     
    397414
    398415    if(lex->GetToken(tk1) != EXTERN)
    399         return FALSE;
     416        return FALSE;
    400417
    401418    if(lex->GetToken(tk2) != StringL)
    402         return FALSE;
     419        return FALSE;
    403420
    404421    spec = new PtreeLinkageSpec(new LeafEXTERN(tk1),
    405                                 Ptree::List(new Leaf(tk2)));
     422                                Ptree::List(new Leaf(tk2)));
    406423    if(lex->LookAhead(0) == '{'){
    407         if(!rLinkageBody(body))
    408             return FALSE;
     424        if(!rLinkageBody(body))
     425            return FALSE;
    409426    }
    410427    else
    411         if(!rDefinition(body))
    412             return FALSE;
     428        if(!rDefinition(body))
     429            return FALSE;
    413430
    414431    spec = Ptree::Snoc(spec, body);
     
    428445
    429446    if(lex->GetToken(tk1) != NAMESPACE)
    430         return FALSE;
     447        return FALSE;
    431448
    432449    if(lex->LookAhead(0) == '{')
    433         name = nil;
     450        name = nil;
    434451    else
    435         if(lex->GetToken(tk2) == Identifier)
    436             name = new Leaf(tk2);
    437         else
    438             return FALSE;
     452        if(lex->GetToken(tk2) == Identifier)
     453            name = new Leaf(tk2);
     454        else
     455            return FALSE;
    439456
    440457    if(lex->LookAhead(0) == '{'){
    441         if(!rLinkageBody(body))
    442             return FALSE;
     458        if(!rLinkageBody(body))
     459            return FALSE;
    443460    }
    444461    else
    445         if(!rDefinition(body))
    446             return FALSE;
     462        if(!rDefinition(body))
     463            return FALSE;
    447464
    448465    spec = new PtreeNamespaceSpec(new LeafNAMESPACE(tk1),
    449                                   Ptree::List(name, body));
     466                                  Ptree::List(name, body));
    450467    return TRUE;
    451468}
     
    462479
    463480    if(lex->GetToken(tk) != USING)
    464         return FALSE;
     481        return FALSE;
    465482
    466483    Ptree* using0 = new LeafUSING(tk);
    467484    Ptree* using1;
    468485    if (lex->LookAhead(0) != NAMESPACE)
    469         using1 = nil;
     486        using1 = nil;
    470487    else {
    471         lex->GetToken(tk);
    472         using1 = new LeafNAMESPACE(tk);
     488        lex->GetToken(tk);
     489        using1 = new LeafNAMESPACE(tk);
    473490    }
    474491
    475492    if (!rName(name, encode))
    476         return FALSE;
     493        return FALSE;
    477494
    478495    if (lex->GetToken(tk) != ';')
    479         return FALSE;
     496        return FALSE;
    480497
    481498    decl = new PtreeUsing(using0, using1, name, encode, new Leaf(tk));
     
    495512
    496513    if(lex->GetToken(op) != '{')
    497         return FALSE;
     514        return FALSE;
    498515
    499516    body = nil;
    500517    while(lex->LookAhead(0) != '}'){
    501         if(!rDefinition(def)){
    502             if(!SyntaxError())
    503                 return FALSE;           // too many errors
    504 
    505             SkipTo('}');
    506             lex->GetToken(cp);
    507             body = Ptree::List(new Leaf(op), nil, new Leaf(cp));
    508             return TRUE;                // error recovery
    509         }
    510 
    511         body = Ptree::Snoc(body, def);
     518        if(!rDefinition(def)){
     519            if(!SyntaxError())
     520                return FALSE;           // too many errors
     521
     522            SkipTo('}');
     523            lex->GetToken(cp);
     524            body = Ptree::List(new Leaf(op), nil, new Leaf(cp));
     525            return TRUE;                // error recovery
     526        }
     527
     528        body = Ptree::Snoc(body, def);
    512529    }
    513530
     
    541558
    542559    if(!rTemplateDecl2(decl, kind))
    543         return FALSE;
     560        return FALSE;
    544561
    545562    if(!rDeclaration(body))
    546         return FALSE;
     563        return FALSE;
    547564
    548565    // Repackage the decl and body depending upon what kind of template
     
    550567    switch (kind) {
    551568    case tdk_instantiation:
    552         // Repackage the decl as a PtreeTemplateInstantiation
    553         decl = body;
    554         // assumes that decl has the form: [nil [class ...] ;]
    555         if (Ptree::Length(decl) != 3)
    556             return FALSE;
    557 
    558         if (Ptree::First(decl) != nil)
    559             return FALSE;
    560 
    561         if (Ptree::Second(decl)->What() != ntClassSpec)
    562             return FALSE;
    563 
    564         if (!Ptree::Eq(Ptree::Third(decl), ';'))
    565             return FALSE;
    566 
    567         decl = new PtreeTemplateInstantiation(Ptree::Second(decl));
    568         break;
     569        // Repackage the decl as a PtreeTemplateInstantiation
     570        decl = body;
     571        // assumes that decl has the form: [nil [class ...] ;]
     572        if (Ptree::Length(decl) != 3)
     573            return FALSE;
     574
     575        if (Ptree::First(decl) != nil)
     576            return FALSE;
     577
     578        if (Ptree::Second(decl)->What() != ntClassSpec)
     579            return FALSE;
     580
     581        if (!Ptree::Eq(Ptree::Third(decl), ';'))
     582            return FALSE;
     583
     584        decl = new PtreeTemplateInstantiation(Ptree::Second(decl));
     585        break;
    569586    case tdk_decl:
    570587    case tdk_specialization:
    571         decl = Ptree::Snoc(decl, body);
    572         break;
     588        decl = Ptree::Snoc(decl, body);
     589        break;
    573590    default:
    574         MopErrorMessage("rTemplateDecl()", "fatal");
    575         break;
     591        MopErrorMessage("rTemplateDecl()", "fatal");
     592        break;
    576593    }
    577594
     
    585602
    586603    if(lex->GetToken(tk) != TEMPLATE)
    587         return FALSE;
     604        return FALSE;
    588605
    589606    if(lex->LookAhead(0) != '<') {
    590         // template instantiation
    591         decl = nil;
    592         kind = tdk_instantiation;
    593         return TRUE;    // ignore TEMPLATE
     607        // template instantiation
     608        decl = nil;
     609        kind = tdk_instantiation;
     610        return TRUE;    // ignore TEMPLATE
    594611    }
    595612
    596613    decl = new PtreeTemplateDecl(new LeafReserved(tk));
    597614    if(lex->GetToken(tk) != '<')
    598         return FALSE;
     615        return FALSE;
    599616
    600617    decl = Ptree::Snoc(decl, new Leaf(tk));
    601618    if(!rTempArgList(args))
    602         return FALSE;
     619        return FALSE;
    603620
    604621    if(lex->GetToken(tk) != '>')
    605         return FALSE;
     622        return FALSE;
    606623
    607624    decl = Ptree::Nconc(decl, Ptree::List(args, new Leaf(tk)));
     
    609626    // ignore nested TEMPLATE
    610627    while (lex->LookAhead(0) == TEMPLATE) {
    611         lex->GetToken(tk);
    612         if(lex->LookAhead(0) != '<')
    613             break;
    614 
    615         lex->GetToken(tk);
    616         if(!rTempArgList(args))
    617             return FALSE;
    618 
    619         if(lex->GetToken(tk) != '>')
    620             return FALSE;
     628        lex->GetToken(tk);
     629        if(lex->LookAhead(0) != '<')
     630            break;
     631
     632        lex->GetToken(tk);
     633        if(!rTempArgList(args))
     634            return FALSE;
     635
     636        if(lex->GetToken(tk) != '>')
     637            return FALSE;
    621638    }
    622639
    623640    if (args == nil)
    624         // template < > declaration
    625         kind = tdk_specialization;
     641        // template < > declaration
     642        kind = tdk_specialization;
    626643    else
    627         // template < ... > declaration
    628         kind = tdk_decl;
     644        // template < ... > declaration
     645        kind = tdk_decl;
    629646
    630647    return TRUE;
     
    642659
    643660    if(lex->LookAhead(0) == '>'){
    644         args = nil;
    645         return TRUE;
     661        args = nil;
     662        return TRUE;
    646663    }
    647664
    648665    if(!rTempArgDeclaration(a))
    649         return FALSE;
     666        return FALSE;
    650667
    651668    args = Ptree::List(a);
    652669    while(lex->LookAhead(0) == ','){
    653         lex->GetToken(tk);
    654         args = Ptree::Snoc(args, new Leaf(tk));
    655         if(!rTempArgDeclaration(a))
    656             return FALSE;
    657 
    658         args = Ptree::Snoc(args, a);
     670        lex->GetToken(tk);
     671        args = Ptree::Snoc(args, new Leaf(tk));
     672        if(!rTempArgDeclaration(a))
     673            return FALSE;
     674
     675        args = Ptree::Snoc(args, a);
    659676    }
    660677
     
    674691    int t0 = lex->LookAhead(0);
    675692    if(t0 == CLASS && lex->LookAhead(1) == Identifier){
    676         lex->GetToken(tk1);
    677         lex->GetToken(tk2);
    678         Ptree* name = new Leaf(tk2);
    679         decl = Ptree::List(new Leaf(tk1), name);
    680 
    681         if(lex->LookAhead(0) == '='){
    682             Ptree* default_type;
    683 
    684             lex->GetToken(tk1);
    685             if(!rTypeName(default_type))
    686                 return FALSE;
    687 
    688             decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1),
    689                                                   default_type));
    690         }
     693        lex->GetToken(tk1);
     694        lex->GetToken(tk2);
     695        Ptree* name = new Leaf(tk2);
     696        decl = Ptree::List(new Leaf(tk1), name);
     697
     698        if(lex->LookAhead(0) == '='){
     699            Ptree* default_type;
     700
     701            lex->GetToken(tk1);
     702            if(!rTypeName(default_type))
     703                return FALSE;
     704
     705            decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1),
     706                                                  default_type));
     707        }
    691708    }
    692709    else if (t0 == TEMPLATE) {
    693         TemplateDeclKind kind;
    694         if(!rTemplateDecl2(decl, kind))
    695             return FALSE;
    696 
    697         if (lex->GetToken(tk1) != CLASS || lex->GetToken(tk2) != Identifier)
    698             return FALSE;
    699 
    700         Ptree* cspec = new PtreeClassSpec(new LeafReserved(tk1),
    701                                           Ptree::Cons(new Leaf(tk2),nil),
    702                                           nil);
    703         decl = Ptree::Snoc(decl, cspec);
    704         if(lex->LookAhead(0) == '='){
     710        TemplateDeclKind kind;
     711        if(!rTemplateDecl2(decl, kind))
     712            return FALSE;
     713
     714        if (lex->GetToken(tk1) != CLASS || lex->GetToken(tk2) != Identifier)
     715            return FALSE;
     716
     717        Ptree* cspec = new PtreeClassSpec(new LeafReserved(tk1),
     718                                          Ptree::Cons(new Leaf(tk2),nil),
     719                                          nil);
     720        decl = Ptree::Snoc(decl, cspec);
     721        if(lex->LookAhead(0) == '='){
    705722            Ptree* default_type;
    706             lex->GetToken(tk1);
    707             if(!rTypeName(default_type))
    708                 return FALSE;
    709 
    710             decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1),
    711                                                   default_type));
    712         }
     723            lex->GetToken(tk1);
     724            if(!rTypeName(default_type))
     725                return FALSE;
     726
     727            decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1),
     728                                                  default_type));
     729        }
    713730    }
    714731    else{
    715         Ptree *type_name, *arg;
    716         Encoding type_encode, name_encode;
    717         if(!rTypeSpecifier(type_name, TRUE, type_encode))
    718             return FALSE;
    719 
    720         if(!rDeclarator(arg, kArgDeclarator, FALSE, type_encode, name_encode,
    721                         TRUE))
    722             return FALSE;
    723 
    724         decl = Ptree::List(type_name, arg);
    725         if(lex->LookAhead(0) == '='){
    726             Ptree* exp;
    727             lex->GetToken(tk1);
    728             if(!rAdditiveExpr(exp))
    729                 return FALSE;
    730 
    731             decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1), exp));
    732         }
     732        Ptree *type_name, *arg;
     733        Encoding type_encode, name_encode;
     734        if(!rTypeSpecifier(type_name, TRUE, type_encode))
     735            return FALSE;
     736
     737        if(!rDeclarator(arg, kArgDeclarator, FALSE, type_encode, name_encode,
     738                        TRUE))
     739            return FALSE;
     740
     741        decl = Ptree::List(type_name, arg);
     742        if(lex->LookAhead(0) == '='){
     743            Ptree* exp;
     744            lex->GetToken(tk1);
     745            if(!rAdditiveExpr(exp))
     746                return FALSE;
     747
     748            decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk1), exp));
     749        }
    733750    }
    734751
     
    746763
    747764    if(lex->GetToken(tk1) != EXTERN)
    748         return FALSE;
     765        return FALSE;
    749766
    750767    if(lex->GetToken(tk2) != TEMPLATE)
    751         return FALSE;
     768        return FALSE;
    752769
    753770    if(!rDeclaration(body))
    754         return FALSE;
     771        return FALSE;
    755772
    756773    decl = new PtreeExternTemplate(new Leaf(tk1),
    757                                    Ptree::List(new Leaf(tk2), body));
     774                                   Ptree::List(new Leaf(tk2), body));
    758775    return TRUE;
    759776}
     
    794811
    795812    if(!optMemberSpec(mem_s) || !optStorageSpec(storage_s))
    796         return FALSE;
     813        return FALSE;
    797814
    798815    if(mem_s == nil)
    799         head = nil;
     816        head = nil;
    800817    else
    801         head = mem_s;   // mem_s is a list.
     818        head = mem_s;   // mem_s is a list.
    802819
    803820    if(storage_s != nil)
    804         head = Ptree::Snoc(head, storage_s);
     821        head = Ptree::Snoc(head, storage_s);
    805822
    806823    if(mem_s == nil)
    807         if(optMemberSpec(mem_s))
    808             head = Ptree::Nconc(head, mem_s);
    809         else
    810             return FALSE;
     824        if(optMemberSpec(mem_s))
     825            head = Ptree::Nconc(head, mem_s);
     826        else
     827            return FALSE;
    811828
    812829    if(!optCvQualify(cv_q)
    813830       || !optIntegralTypeOrClassSpec(integral, type_encode))
    814         return FALSE;
     831        return FALSE;
    815832
    816833    if(integral != nil)
    817         return rIntegralDeclaration(statement, type_encode,
    818                                     head, integral, cv_q);
     834        return rIntegralDeclaration(statement, type_encode,
     835                                    head, integral, cv_q);
    819836    else{
    820         type_encode.Clear();
    821         int t = lex->LookAhead(0);
    822         if(cv_q != nil && ((t == Identifier && lex->LookAhead(1) == '=')
    823                            || t == '*'))
    824             return rConstDeclaration(statement, type_encode, head, cv_q);
    825         else
    826             return rOtherDeclaration(statement, type_encode,
    827                                      mem_s, cv_q, head);
     837        type_encode.Clear();
     838        int t = lex->LookAhead(0);
     839        if(cv_q != nil && ((t == Identifier && lex->LookAhead(1) == '=')
     840                           || t == '*'))
     841            return rConstDeclaration(statement, type_encode, head, cv_q);
     842        else
     843            return rOtherDeclaration(statement, type_encode,
     844                                     mem_s, cv_q, head);
    828845    }
    829846}
    830847
    831848bool Parser::rIntegralDeclaration(Ptree*& statement, Encoding& type_encode,
    832                                   Ptree* head, Ptree* integral, Ptree* cv_q)
     849                                  Ptree* head, Ptree* integral, Ptree* cv_q)
    833850{
    834851    Token tk;
     
    836853
    837854    if(!optCvQualify(cv_q2))
    838         return FALSE;
     855        return FALSE;
    839856
    840857    if(cv_q != nil)
    841         if(cv_q2 == nil)
    842             integral = Ptree::Snoc(cv_q, integral);
    843         else
    844             integral = Ptree::Nconc(cv_q, Ptree::Cons(integral, cv_q2));
     858        if(cv_q2 == nil)
     859            integral = Ptree::Snoc(cv_q, integral);
     860        else
     861            integral = Ptree::Nconc(cv_q, Ptree::Cons(integral, cv_q2));
    845862    else if(cv_q2 != nil)
    846         integral = Ptree::Cons(integral, cv_q2);
     863        integral = Ptree::Cons(integral, cv_q2);
    847864
    848865    type_encode.CvQualify(cv_q, cv_q2);
    849866    switch(lex->LookAhead(0)){
    850867    case ';' :
    851         lex->GetToken(tk);
    852         statement = new PtreeDeclaration(head, Ptree::List(integral,
    853                                                            new Leaf(tk)));
    854         return TRUE;
    855     case ':' :  // bit field
    856         lex->GetToken(tk);
    857         if(!rExpression(decl))
    858             return FALSE;
    859 
    860         decl = Ptree::List(Ptree::List(new Leaf(tk), decl));
    861         if(lex->GetToken(tk) != ';')
    862             return FALSE;
    863 
    864         statement = new PtreeDeclaration(head, Ptree::List(integral, decl,
    865                                                            new Leaf(tk)));
    866         return TRUE;
     868        lex->GetToken(tk);
     869        statement = new PtreeDeclaration(head, Ptree::List(integral,
     870                                                           new Leaf(tk)));
     871        return TRUE;
     872    case ':' :  // bit field
     873        lex->GetToken(tk);
     874        if(!rExpression(decl))
     875            return FALSE;
     876
     877        decl = Ptree::List(Ptree::List(new Leaf(tk), decl));
     878        if(lex->GetToken(tk) != ';')
     879            return FALSE;
     880
     881        statement = new PtreeDeclaration(head, Ptree::List(integral, decl,
     882                                                           new Leaf(tk)));
     883        return TRUE;
    867884    default :
    868         if(!rDeclarators(decl, type_encode, TRUE))
    869             return FALSE;
    870 
    871         if(lex->LookAhead(0) == ';'){
    872             lex->GetToken(tk);
    873             statement = new PtreeDeclaration(head, Ptree::List(integral, decl,
    874                                                                new Leaf(tk)));
    875             return TRUE;
    876         }
    877         else{
    878             Ptree* body;
    879             if(!rFunctionBody(body))
    880                 return FALSE;
    881 
    882             if(Ptree::Length(decl) != 1)
    883                 return FALSE;
    884 
    885             statement = new PtreeDeclaration(head,
    886                                              Ptree::List(integral,
    887                                                         decl->Car(), body));
    888             return TRUE;
    889         }
     885        if(!rDeclarators(decl, type_encode, TRUE))
     886            return FALSE;
     887
     888        if(lex->LookAhead(0) == ';'){
     889            lex->GetToken(tk);
     890            statement = new PtreeDeclaration(head, Ptree::List(integral, decl,
     891                                                               new Leaf(tk)));
     892            return TRUE;
     893        }
     894        else{
     895            Ptree* body;
     896            if(!rFunctionBody(body))
     897                return FALSE;
     898
     899            if(Ptree::Length(decl) != 1)
     900                return FALSE;
     901
     902            statement = new PtreeDeclaration(head,
     903                                             Ptree::List(integral,
     904                                                        decl->Car(), body));
     905            return TRUE;
     906        }
    890907    }
    891908}
    892909
    893910bool Parser::rConstDeclaration(Ptree*& statement, Encoding&,
    894                                Ptree* head, Ptree* cv_q)
     911                               Ptree* head, Ptree* cv_q)
    895912{
    896913    Ptree* decl;
     
    900917    type_encode.SimpleConst();
    901918    if(!rDeclarators(decl, type_encode, FALSE))
    902         return FALSE;
     919        return FALSE;
    903920
    904921    if(lex->LookAhead(0) != ';')
    905         return FALSE;
     922        return FALSE;
    906923
    907924    lex->GetToken(tk);
    908925    statement = new PtreeDeclaration(head, Ptree::List(cv_q, decl,
    909                                                        new Leaf(tk)));
     926                                                       new Leaf(tk)));
    910927    return TRUE;
    911928}
    912929
    913930bool Parser::rOtherDeclaration(Ptree*& statement, Encoding& type_encode,
    914                                Ptree* mem_s, Ptree* cv_q, Ptree* head)
     931                               Ptree* mem_s, Ptree* cv_q, Ptree* head)
    915932{
    916933    Ptree *type_name, *decl, *cv_q2;
     
    918935
    919936    if(!rName(type_name, type_encode))
    920         return FALSE;
     937        return FALSE;
    921938
    922939    if(cv_q == nil && isConstructorDecl()){
    923         Encoding ftype_encode;
    924         if(!rConstructorDecl(decl, ftype_encode))
    925             return FALSE;
    926 
    927         decl = Ptree::List(new PtreeDeclarator(type_name, decl,
    928                                                ftype_encode, type_encode,
    929                                                type_name));
    930         type_name = nil;
     940        Encoding ftype_encode;
     941        if(!rConstructorDecl(decl, ftype_encode))
     942            return FALSE;
     943
     944        decl = Ptree::List(new PtreeDeclarator(type_name, decl,
     945                                               ftype_encode, type_encode,
     946                                               type_name));
     947        type_name = nil;
    931948    }
    932949    else if(mem_s != nil && lex->LookAhead(0) == ';'){
    933         // FRIEND name ';'
    934         if(Ptree::Length(mem_s) == 1 && mem_s->Car()->What() == FRIEND){
    935             lex->GetToken(tk);
    936             statement = new PtreeDeclaration(head, Ptree::List(type_name,
    937                                                                new Leaf(tk)));
    938             return TRUE;
    939         }
    940         else
    941             return FALSE;
     950        // FRIEND name ';'
     951        if(Ptree::Length(mem_s) == 1 && mem_s->Car()->What() == FRIEND){
     952            lex->GetToken(tk);
     953            statement = new PtreeDeclaration(head, Ptree::List(type_name,
     954                                                               new Leaf(tk)));
     955            return TRUE;
     956        }
     957        else
     958            return FALSE;
    942959    }
    943960    else{
    944         if(!optCvQualify(cv_q2))
    945             return FALSE;
    946 
    947         if(cv_q != nil)
    948             if(cv_q2 == nil)
    949                 type_name = Ptree::Snoc(cv_q, type_name);
    950             else
    951                 type_name = Ptree::Nconc(cv_q, Ptree::Cons(type_name, cv_q2));
    952         else if(cv_q2 != nil)
    953             type_name = Ptree::Cons(type_name, cv_q2);
    954 
    955         type_encode.CvQualify(cv_q, cv_q2);
    956         if(!rDeclarators(decl, type_encode, FALSE))
    957             return FALSE;
     961        if(!optCvQualify(cv_q2))
     962            return FALSE;
     963
     964        if(cv_q != nil)
     965            if(cv_q2 == nil)
     966                type_name = Ptree::Snoc(cv_q, type_name);
     967            else
     968                type_name = Ptree::Nconc(cv_q, Ptree::Cons(type_name, cv_q2));
     969        else if(cv_q2 != nil)
     970            type_name = Ptree::Cons(type_name, cv_q2);
     971
     972        type_encode.CvQualify(cv_q, cv_q2);
     973        if(!rDeclarators(decl, type_encode, FALSE))
     974            return FALSE;
    958975    }
    959976
    960977    if(lex->LookAhead(0) == ';'){
    961         lex->GetToken(tk);
    962         statement = new PtreeDeclaration(head, Ptree::List(type_name, decl,
    963                                                            new Leaf(tk)));
     978        lex->GetToken(tk);
     979        statement = new PtreeDeclaration(head, Ptree::List(type_name, decl,
     980                                                           new Leaf(tk)));
    964981    }
    965982    else{
    966         Ptree* body;
    967         if(!rFunctionBody(body))
    968             return FALSE;
    969 
    970         if(Ptree::Length(decl) != 1)
    971             return FALSE;
    972 
    973         statement = new PtreeDeclaration(head, Ptree::List(type_name,
    974                                                            decl->Car(), body));
     983        Ptree* body;
     984        if(!rFunctionBody(body))
     985            return FALSE;
     986
     987        if(Ptree::Length(decl) != 1)
     988            return FALSE;
     989
     990        statement = new PtreeDeclaration(head, Ptree::List(type_name,
     991                                                           decl->Car(), body));
    975992    }
    976993
     
    980997/*
    981998  This returns TRUE for an declaration like:
    982         T (a);
     999        T (a);
    9831000  even if a is not a type name.  This is a bug according to the ANSI
    9841001  specification, but I believe none says "T (a);" for a variable
     
    9881005{
    9891006    if(lex->LookAhead(0) != '(')
    990         return FALSE;
     1007        return FALSE;
    9911008    else{
    992         int t = lex->LookAhead(1);
    993         if(t == '*' || t == '&' || t == '(')
    994             return FALSE;       // declarator
    995         else if(t == CONST || t == VOLATILE)
    996             return TRUE;        // constructor or declarator
    997         else if(isPtrToMember(1))
    998             return FALSE;       // declarator (::*)
    999         else
    1000             return TRUE;        // maybe constructor
     1009        int t = lex->LookAhead(1);
     1010        if(t == '*' || t == '&' || t == '(')
     1011            return FALSE;       // declarator
     1012        else if(t == CONST || t == VOLATILE)
     1013            return TRUE;        // constructor or declarator
     1014        else if(isPtrToMember(1))
     1015            return FALSE;       // declarator (::*)
     1016        else
     1017            return TRUE;        // maybe constructor
    10011018    }
    10021019}
     
    10111028
    10121029    if(t0 == Scope)
    1013         t0 = lex->LookAhead(i++);
     1030        t0 = lex->LookAhead(i++);
    10141031
    10151032    while(t0 == Identifier){
    1016         int t = lex->LookAhead(i++);
    1017         if(t == '<'){
    1018             int n = 1;
    1019             while(n > 0){
    1020                 int u = lex->LookAhead(i++);
    1021                 if(u == '<')
    1022                     ++n;
    1023                 else if(u == '>')
    1024                     --n;
    1025                 else if(u == '('){
    1026                     int m = 1;
    1027                     while(m > 0){
    1028                         int v = lex->LookAhead(i++);
    1029                         if(v == '(')
    1030                             ++m;
    1031                         else if(v == ')')
    1032                             --m;
    1033                         else if(v == '\0' || v == ';' || v == '}')
    1034                             return FALSE;
    1035                     }
    1036                 }
    1037                 else if(u == '\0' || u == ';' || u == '}')
    1038                     return FALSE;
    1039             }
    1040 
    1041             t = lex->LookAhead(i++);
    1042         }
    1043 
    1044         if(t != Scope)
    1045             return FALSE;
    1046 
    1047         t0 = lex->LookAhead(i++);
    1048         if(t0 == '*')
    1049             return TRUE;
     1033        int t = lex->LookAhead(i++);
     1034        if(t == '<'){
     1035            int n = 1;
     1036            while(n > 0){
     1037                int u = lex->LookAhead(i++);
     1038                if(u == '<')
     1039                    ++n;
     1040                else if(u == '>')
     1041                    --n;
     1042                else if(u == '('){
     1043                    int m = 1;
     1044                    while(m > 0){
     1045                        int v = lex->LookAhead(i++);
     1046                        if(v == '(')
     1047                            ++m;
     1048                        else if(v == ')')
     1049                            --m;
     1050                        else if(v == '\0' || v == ';' || v == '}')
     1051                            return FALSE;
     1052                    }
     1053                }
     1054                else if(u == '\0' || u == ';' || u == '}')
     1055                    return FALSE;
     1056            }
     1057
     1058            t = lex->LookAhead(i++);
     1059        }
     1060
     1061        if(t != Scope)
     1062            return FALSE;
     1063
     1064        t0 = lex->LookAhead(i++);
     1065        if(t0 == '*')
     1066            return TRUE;
    10501067    }
    10511068
     
    10651082    p = nil;
    10661083    while(t == FRIEND || t == INLINE || t == VIRTUAL || t == UserKeyword5){
    1067         if(t == UserKeyword5){
    1068             if(!rUserdefKeyword(lf))
    1069                 return FALSE;
    1070         }
    1071         else{
    1072             lex->GetToken(tk);
    1073             if(t == INLINE)
    1074                 lf = new LeafINLINE(tk);
    1075             else if(t == VIRTUAL)
    1076                 lf = new LeafVIRTUAL(tk);
    1077             else
    1078                 lf = new LeafFRIEND(tk);
    1079         }
    1080 
    1081         p = Ptree::Snoc(p, lf);
    1082         t = lex->LookAhead(0);
     1084        if(t == UserKeyword5){
     1085            if(!rUserdefKeyword(lf))
     1086                return FALSE;
     1087        }
     1088        else{
     1089            lex->GetToken(tk);
     1090            if(t == INLINE)
     1091                lf = new LeafINLINE(tk);
     1092            else if(t == VIRTUAL)
     1093                lf = new LeafVIRTUAL(tk);
     1094            else
     1095                lf = new LeafFRIEND(tk);
     1096        }
     1097
     1098        p = Ptree::Snoc(p, lf);
     1099        t = lex->LookAhead(0);
    10831100    }
    10841101
     
    10941111    if(t == STATIC || t == EXTERN || t == AUTO || t == REGISTER
    10951112       || t == MUTABLE){
    1096         Token tk;
    1097         lex->GetToken(tk);
    1098         switch(t){
    1099         case STATIC :
    1100             p = new LeafSTATIC(tk);
    1101             break;
    1102         case EXTERN :
    1103             p = new LeafEXTERN(tk);
    1104             break;
    1105         case AUTO :
    1106             p = new LeafAUTO(tk);
    1107             break;
    1108         case REGISTER :
    1109             p = new LeafREGISTER(tk);
    1110             break;
    1111         case MUTABLE :
    1112             p = new LeafMUTABLE(tk);
    1113             break;
    1114         default :
    1115             MopErrorMessage("optStorageSpec()", "fatal");
    1116             break;
    1117         }
     1113        Token tk;
     1114        lex->GetToken(tk);
     1115        switch(t){
     1116        case STATIC :
     1117            p = new LeafSTATIC(tk);
     1118            break;
     1119        case EXTERN :
     1120            p = new LeafEXTERN(tk);
     1121            break;
     1122        case AUTO :
     1123            p = new LeafAUTO(tk);
     1124            break;
     1125        case REGISTER :
     1126            p = new LeafREGISTER(tk);
     1127            break;
     1128        case MUTABLE :
     1129            p = new LeafMUTABLE(tk);
     1130            break;
     1131        default :
     1132            MopErrorMessage("optStorageSpec()", "fatal");
     1133            break;
     1134        }
    11181135    }
    11191136    else
    1120         p = nil;        // no storage specifier
     1137        p = nil;        // no storage specifier
    11211138
    11221139    return TRUE;
     
    11301147    Ptree* p = nil;
    11311148    for(;;){
    1132         int t = lex->LookAhead(0);
    1133         if(t == CONST || t == VOLATILE){
    1134             Token tk;
    1135             lex->GetToken(tk);
    1136             switch(t){
    1137             case CONST :
    1138                 p = Ptree::Snoc(p, new LeafCONST(tk));
    1139                 break;
    1140             case VOLATILE :
    1141                 p = Ptree::Snoc(p, new LeafVOLATILE(tk));
    1142                 break;
    1143             default :
    1144                 MopErrorMessage("optCvQualify()", "fatal");
    1145                 break;
    1146             }
    1147         }
    1148         else
    1149             break;
     1149        int t = lex->LookAhead(0);
     1150        if(t == CONST || t == VOLATILE){
     1151            Token tk;
     1152            lex->GetToken(tk);
     1153            switch(t){
     1154            case CONST :
     1155                p = Ptree::Snoc(p, new LeafCONST(tk));
     1156                break;
     1157            case VOLATILE :
     1158                p = Ptree::Snoc(p, new LeafVOLATILE(tk));
     1159                break;
     1160            default :
     1161                MopErrorMessage("optCvQualify()", "fatal");
     1162                break;
     1163            }
     1164        }
     1165        else
     1166            break;
    11501167    }
    11511168
     
    11721189    p = nil;
    11731190    for(;;){
    1174         t = lex->LookAhead(0);
    1175         if(t == CHAR || t == INT || t == SHORT || t == LONG || t == SIGNED
    1176            || t == UNSIGNED || t == FLOAT || t == DOUBLE || t == VOID
    1177            || t == BOOLEAN
     1191        t = lex->LookAhead(0);
     1192        if(t == CHAR || t == INT || t == SHORT || t == LONG || t == SIGNED
     1193           || t == UNSIGNED || t == FLOAT || t == DOUBLE || t == VOID
     1194           || t == BOOLEAN
    11781195#if defined(_MSC_VER)
    1179            || t == INT64
     1196           || t == INT64
    11801197#endif
    1181            ){
    1182             Token tk;
    1183             Ptree* kw;
    1184             lex->GetToken(tk);
    1185             switch(t){
    1186             case CHAR :
    1187                 type = 'c';
    1188                 kw = new LeafCHAR(tk);
    1189                 break;
    1190             case INT :
     1198           ){
     1199            Token tk;
     1200            Ptree* kw;
     1201            lex->GetToken(tk);
     1202            switch(t){
     1203            case CHAR :
     1204                type = 'c';
     1205                kw = new LeafCHAR(tk);
     1206                break;
     1207            case INT :
    11911208#if defined(_MSC_VER)
    11921209            case INT64 : // an int64 is *NOT* an int but...
    11931210#endif
    1194                 if(type != 's' && type != 'l' && type != 'j' && type != 'r')
    1195                     type = 'i';
    1196 
    1197                 kw = new LeafINT(tk);
    1198                 break;
    1199             case SHORT :
    1200                 type = 's';
    1201                 kw = new LeafSHORT(tk);
    1202                 break;
    1203             case LONG :
    1204                 if(type == 'l')
    1205                     type = 'j';         // long long
    1206                 else if(type == 'd')
    1207                     type = 'r';         // double long
    1208                 else
    1209                     type = 'l';
    1210 
    1211                 kw = new LeafLONG(tk);
    1212                 break;
    1213             case SIGNED :
    1214                 flag = 'S';
    1215                 kw = new LeafSIGNED(tk);
    1216                 break;
    1217             case UNSIGNED :
    1218                 flag = 'U';
    1219                 kw = new LeafUNSIGNED(tk);
    1220                 break;
    1221             case FLOAT :
    1222                 type = 'f';
    1223                 kw = new LeafFLOAT(tk);
    1224                 break;
    1225             case DOUBLE :
    1226                 if(type == 'l')
    1227                     type = 'r';         // long double
    1228                 else
    1229                     type = 'd';
    1230 
    1231                 kw = new LeafDOUBLE(tk);
    1232                 break;
    1233             case VOID :
    1234                 type = 'v';
    1235                 kw = new LeafVOID(tk);
    1236                 break;
    1237             case BOOLEAN :
    1238                 type = 'b';
    1239                 kw = new LeafBOOLEAN(tk);
    1240                 break;
    1241             default :
    1242                 MopErrorMessage("optIntegralTypeOrClassSpec()", "fatal");
    1243                 kw = nil;
    1244                 break;
    1245             }
    1246 
    1247             p = Ptree::Snoc(p, kw);
    1248             is_integral = TRUE;
    1249         }
    1250         else
    1251             break;
     1211                if(type != 's' && type != 'l' && type != 'j' && type != 'r')
     1212                    type = 'i';
     1213
     1214                kw = new LeafINT(tk);
     1215                break;
     1216            case SHORT :
     1217                type = 's';
     1218                kw = new LeafSHORT(tk);
     1219                break;
     1220            case LONG :
     1221                if(type == 'l')
     1222                    type = 'j';         // long long
     1223                else if(type == 'd')
     1224                    type = 'r';         // double long
     1225                else
     1226                    type = 'l';
     1227
     1228                kw = new LeafLONG(tk);
     1229                break;
     1230            case SIGNED :
     1231                flag = 'S';
     1232                kw = new LeafSIGNED(tk);
     1233                break;
     1234            case UNSIGNED :
     1235                flag = 'U';
     1236                kw = new LeafUNSIGNED(tk);
     1237                break;
     1238            case FLOAT :
     1239                type = 'f';
     1240                kw = new LeafFLOAT(tk);
     1241                break;
     1242            case DOUBLE :
     1243                if(type == 'l')
     1244                    type = 'r';         // long double
     1245                else
     1246                    type = 'd';
     1247
     1248                kw = new LeafDOUBLE(tk);
     1249                break;
     1250            case VOID :
     1251                type = 'v';
     1252                kw = new LeafVOID(tk);
     1253                break;
     1254            case BOOLEAN :
     1255                type = 'b';
     1256                kw = new LeafBOOLEAN(tk);
     1257                break;
     1258            default :
     1259                MopErrorMessage("optIntegralTypeOrClassSpec()", "fatal");
     1260                kw = nil;
     1261                break;
     1262            }
     1263
     1264            p = Ptree::Snoc(p, kw);
     1265            is_integral = TRUE;
     1266        }
     1267        else
     1268            break;
    12521269    }
    12531270
    12541271    if(is_integral){
    1255         if(flag == 'S' && type != 'c')
    1256             flag = ' ';
    1257 
    1258         if(flag != ' ')
    1259             encode.Append(flag);
    1260 
    1261         if(type == ' ')
    1262             type = 'i';         // signed, unsigned
    1263 
    1264         encode.Append(type);
    1265         return TRUE;
     1272        if(flag == 'S' && type != 'c')
     1273            flag = ' ';
     1274
     1275        if(flag != ' ')
     1276            encode.Append(flag);
     1277
     1278        if(type == ' ')
     1279            type = 'i';         // signed, unsigned
     1280
     1281        encode.Append(type);
     1282        return TRUE;
    12661283    }
    12671284
    12681285    if(t == CLASS || t == STRUCT || t == UNION || t == UserKeyword)
    1269         return rClassSpec(p, encode);
     1286        return rClassSpec(p, encode);
    12701287    else if(t == ENUM)
    1271         return rEnumSpec(p, encode);
     1288        return rEnumSpec(p, encode);
    12721289    else{
    1273         p = nil;
    1274         return TRUE;
     1290        p = nil;
     1291        return TRUE;
    12751292    }
    12761293}
     
    12871304
    12881305    if(lex->GetToken(op) != '(')
    1289         return FALSE;
     1306        return FALSE;
    12901307
    12911308    if(lex->LookAhead(0) == ')'){
    1292         args = nil;
    1293         encode.StartFuncArgs();
    1294         encode.Void();
    1295         encode.EndFuncArgs();
     1309        args = nil;
     1310        encode.StartFuncArgs();
     1311        encode.Void();
     1312        encode.EndFuncArgs();
    12961313    }
    12971314    else
    1298         if(!rArgDeclList(args, encode))
    1299             return FALSE;
     1315        if(!rArgDeclList(args, encode))
     1316            return FALSE;
    13001317
    13011318    lex->GetToken(cp);
     
    13031320    optCvQualify(cv);
    13041321    if(cv != nil){
    1305         encode.CvQualify(cv);
    1306         constructor = Ptree::Nconc(constructor, cv);
    1307     }
    1308 
    1309     optThrowDecl(throw_decl);   // ignore in this version
     1322        encode.CvQualify(cv);
     1323        constructor = Ptree::Nconc(constructor, cv);
     1324    }
     1325
     1326    optThrowDecl(throw_decl);   // ignore in this version
    13101327
    13111328    if(lex->LookAhead(0) == ':')
    1312         if(rMemberInitializers(mi))
    1313             constructor = Ptree::Snoc(constructor, mi);
    1314         else
    1315             return FALSE;
     1329        if(rMemberInitializers(mi))
     1330            constructor = Ptree::Snoc(constructor, mi);
     1331        else
     1332            return FALSE;
    13161333
    13171334    if(lex->LookAhead(0) == '='){
    1318         Token eq, zero;
    1319         lex->GetToken(eq);
    1320         if(lex->GetToken(zero) != Constant)
    1321             return FALSE;
    1322 
    1323         constructor = Ptree::Nconc(constructor,
    1324                                    Ptree::List(new Leaf(eq), new Leaf(zero)));
     1335        Token eq, zero;
     1336        lex->GetToken(eq);
     1337        if(lex->GetToken(zero) != Constant)
     1338            return FALSE;
     1339
     1340        constructor = Ptree::Nconc(constructor,
     1341                                   Ptree::List(new Leaf(eq), new Leaf(zero)));
    13251342    }
    13261343
     
    13391356
    13401357    if(lex->LookAhead(0) == THROW){
    1341         lex->GetToken(tk);
    1342         p = Ptree::Snoc(p, new LeafReserved(tk));
    1343 
    1344         if(lex->GetToken(tk) != '(')
    1345             return FALSE;
    1346 
    1347         p = Ptree::Snoc(p, new Leaf(tk));
    1348 
    1349         for(;;){
    1350             Ptree* q;
    1351             Encoding encode;
    1352             t = lex->LookAhead(0);
    1353             if(t == '\0')
    1354                 return FALSE;
    1355             else if(t == ')')
    1356                 break;
    1357             else if(rName(q, encode))
    1358                 p = Ptree::Snoc(p, q);
    1359             else
    1360                 return FALSE;
    1361 
    1362             if(lex->LookAhead(0) == ','){
    1363                 lex->GetToken(tk);
    1364                 p = Ptree::Snoc(p, new Leaf(tk));
    1365             }
    1366             else
    1367                 break;
    1368         }
    1369 
    1370         if(lex->GetToken(tk) != ')')
    1371             return FALSE;
    1372 
    1373         p = Ptree::Snoc(p, new Leaf(tk));
     1358        lex->GetToken(tk);
     1359        p = Ptree::Snoc(p, new LeafReserved(tk));
     1360
     1361        if(lex->GetToken(tk) != '(')
     1362            return FALSE;
     1363
     1364        p = Ptree::Snoc(p, new Leaf(tk));
     1365
     1366        for(;;){
     1367            Ptree* q;
     1368            Encoding encode;
     1369            t = lex->LookAhead(0);
     1370            if(t == '\0')
     1371                return FALSE;
     1372            else if(t == ')')
     1373                break;
     1374            else if(rName(q, encode))
     1375                p = Ptree::Snoc(p, q);
     1376            else
     1377                return FALSE;
     1378
     1379            if(lex->LookAhead(0) == ','){
     1380                lex->GetToken(tk);
     1381                p = Ptree::Snoc(p, new Leaf(tk));
     1382            }
     1383            else
     1384                break;
     1385        }
     1386
     1387        if(lex->GetToken(tk) != ')')
     1388            return FALSE;
     1389
     1390        p = Ptree::Snoc(p, new Leaf(tk));
    13741391    }
    13751392
     
    13841401*/
    13851402bool Parser::rDeclarators(Ptree*& decls, Encoding& type_encode,
    1386                           bool should_be_declarator, bool is_statement)
     1403                          bool should_be_declarator, bool is_statement)
    13871404{
    13881405    Ptree* d;
     
    13921409    decls = nil;
    13931410    for(;;){
    1394         encode.Reset(type_encode);
    1395         if(!rDeclaratorWithInit(d, encode, should_be_declarator, is_statement))
    1396             return FALSE;
    1397 
    1398         decls = Ptree::Snoc(decls, d);
    1399         if(lex->LookAhead(0) == ','){
    1400             lex->GetToken(tk);
    1401             decls = Ptree::Snoc(decls, new Leaf(tk));
    1402         }
    1403         else
    1404             return TRUE;
     1411        encode.Reset(type_encode);
     1412        if(!rDeclaratorWithInit(d, encode, should_be_declarator, is_statement))
     1413            return FALSE;
     1414
     1415        decls = Ptree::Snoc(decls, d);
     1416        if(lex->LookAhead(0) == ','){
     1417            lex->GetToken(tk);
     1418            decls = Ptree::Snoc(decls, new Leaf(tk));
     1419        }
     1420        else
     1421            return TRUE;
    14051422    };
    14061423}
     
    14121429*/
    14131430bool Parser::rDeclaratorWithInit(Ptree*& dw, Encoding& type_encode,
    1414                                 bool should_be_declarator,
    1415                                 bool is_statement)
     1431                                bool should_be_declarator,
     1432                                bool is_statement)
    14161433{
    14171434    Ptree *d, *e;
     
    14191436    Encoding name_encode;
    14201437
    1421     if(lex->LookAhead(0) == ':'){       // bit field
    1422         lex->GetToken(tk);
    1423         if(!rExpression(e))
    1424             return FALSE;
    1425 
    1426         dw = Ptree::List(new Leaf(tk), e);
    1427         return TRUE;
     1438    if(lex->LookAhead(0) == ':'){       // bit field
     1439        lex->GetToken(tk);
     1440        if(!rExpression(e))
     1441            return FALSE;
     1442
     1443        dw = Ptree::List(new Leaf(tk), e);
     1444        return TRUE;
    14281445    }
    14291446    else{
    1430         if(!rDeclarator(d, kDeclarator, FALSE, type_encode, name_encode,
    1431                         should_be_declarator, is_statement))
    1432             return FALSE;
    1433 
    1434         int t = lex->LookAhead(0);
    1435         if(t == '='){
    1436             lex->GetToken(tk);
    1437             if(!rInitializeExpr(e))
    1438                 return FALSE;
    1439 
    1440             dw = Ptree::Nconc(d, Ptree::List(new Leaf(tk), e));
    1441             return TRUE;
    1442         }
    1443         else if(t == ':'){              // bit field
    1444             lex->GetToken(tk);
    1445             if(!rExpression(e))
    1446                 return FALSE;
    1447 
    1448             dw = Ptree::Nconc(d, Ptree::List(new Leaf(tk), e));
    1449             return TRUE;
    1450         }
    1451         else{
    1452             dw = d;
    1453             return TRUE;
    1454         }
     1447        if(!rDeclarator(d, kDeclarator, FALSE, type_encode, name_encode,
     1448                        should_be_declarator, is_statement))
     1449            return FALSE;
     1450
     1451        int t = lex->LookAhead(0);
     1452        if(t == '='){
     1453            lex->GetToken(tk);
     1454            if(!rInitializeExpr(e))
     1455                return FALSE;
     1456
     1457            dw = Ptree::Nconc(d, Ptree::List(new Leaf(tk), e));
     1458            return TRUE;
     1459        }
     1460        else if(t == ':'){              // bit field
     1461            lex->GetToken(tk);
     1462            if(!rExpression(e))
     1463                return FALSE;
     1464
     1465            dw = Ptree::Nconc(d, Ptree::List(new Leaf(tk), e));
     1466            return TRUE;
     1467        }
     1468        else{
     1469            dw = d;
     1470            return TRUE;
     1471        }
    14551472    }
    14561473}
     
    14591476  declarator
    14601477  : (ptr.operator)* (name | '(' declarator ')')
    1461         ('[' comma.expression ']')* {func.args.or.init}
     1478        ('[' comma.expression ']')* {func.args.or.init}
    14621479
    14631480  func.args.or.init
     
    14661483
    14671484  Note: We assume that '(' declarator ')' is followed by '(' or '['.
    1468         This is to avoid accepting a function call F(x) as a pair of
    1469         a type F and a declarator x.  This assumption is ignored
    1470         if should_be_declarator is true.
     1485        This is to avoid accepting a function call F(x) as a pair of
     1486        a type F and a declarator x.  This assumption is ignored
     1487        if should_be_declarator is true.
    14711488
    14721489  Note: An argument declaration list and a function-style initializer
    1473         take a different Ptree structure.
    1474         e.g.
    1475             int f(char) ==> .. [f ( [[[char] nil]] )]
    1476             Point f(1)  ==> .. [f [( [1] )]]
     1490        take a different Ptree structure.
     1491        e.g.
     1492            int f(char) ==> .. [f ( [[[char] nil]] )]
     1493            Point f(1)  ==> .. [f [( [1] )]]
    14771494
    14781495  Note: is_statement changes the behavior of rArgDeclListOrInit().
    14791496*/
    14801497bool Parser::rDeclarator(Ptree*& decl, DeclKind kind, bool recursive,
    1481                         Encoding& type_encode, Encoding& name_encode,
    1482                         bool should_be_declarator, bool is_statement)
     1498                        Encoding& type_encode, Encoding& name_encode,
     1499                        bool should_be_declarator, bool is_statement)
    14831500{
    14841501    return rDeclarator2(decl, kind, recursive, type_encode, name_encode,
    1485                         should_be_declarator, is_statement, nil);
     1502                        should_be_declarator, is_statement, nil);
    14861503}
    14871504
    14881505bool Parser::rDeclarator2(Ptree*& decl, DeclKind kind, bool recursive,
    1489                           Encoding& type_encode, Encoding& name_encode,
    1490                           bool should_be_declarator, bool is_statement,
    1491                           Ptree** declared_name)
     1506                          Encoding& type_encode, Encoding& name_encode,
     1507                          bool should_be_declarator, bool is_statement,
     1508                          Ptree** declared_name)
    14921509{
    14931510    Encoding recursive_encode;
     
    14981515
    14991516    if(declared_name == nil)
    1500         declared_name = &declared_name0;
     1517        declared_name = &declared_name0;
    15011518
    15021519    if(!optPtrOperator(d, type_encode))
    1503         return FALSE;
     1520        return FALSE;
    15041521
    15051522    t = lex->LookAhead(0);
    15061523    if(t == '('){
    1507         Token op, cp;
    1508         Ptree* decl2;
    1509         lex->GetToken(op);
    1510         recursive_decl = TRUE;
    1511         if(!rDeclarator2(decl2, kind, TRUE, recursive_encode, name_encode,
    1512                         TRUE, FALSE, declared_name))
    1513             return FALSE;
    1514 
    1515         if(lex->GetToken(cp) != ')')
    1516             return FALSE;
    1517 
    1518         if(!should_be_declarator)
    1519             if(kind == kDeclarator && d == nil){
    1520                 t = lex->LookAhead(0);
    1521                 if(t != '[' && t != '(')
    1522                     return FALSE;
    1523             }
    1524 
    1525         d = Ptree::Snoc(d, Ptree::List(new Leaf(op), decl2, new Leaf(cp)));
     1524        Token op, cp;
     1525        Ptree* decl2;
     1526        lex->GetToken(op);
     1527        recursive_decl = TRUE;
     1528        if(!rDeclarator2(decl2, kind, TRUE, recursive_encode, name_encode,
     1529                        TRUE, FALSE, declared_name))
     1530            return FALSE;
     1531
     1532        if(lex->GetToken(cp) != ')')
     1533            return FALSE;
     1534
     1535        if(!should_be_declarator)
     1536            if(kind == kDeclarator && d == nil){
     1537                t = lex->LookAhead(0);
     1538                if(t != '[' && t != '(')
     1539                    return FALSE;
     1540            }
     1541
     1542        d = Ptree::Snoc(d, Ptree::List(new Leaf(op), decl2, new Leaf(cp)));
    15261543    }
    15271544    else if(kind != kCastDeclarator
    1528            && (kind == kDeclarator || t == Identifier || t == Scope)){
    1529         // if this is an argument declarator, "int (*)()" is valid.
    1530         Ptree* name;
    1531         if(rName(name, name_encode))
    1532             d = Ptree::Snoc(d, name);
    1533         else
    1534             return FALSE;
    1535 
    1536         *declared_name = name;
     1545           && (kind == kDeclarator || t == Identifier || t == Scope)){
     1546        // if this is an argument declarator, "int (*)()" is valid.
     1547        Ptree* name;
     1548        if(rName(name, name_encode))
     1549            d = Ptree::Snoc(d, name);
     1550        else
     1551            return FALSE;
     1552
     1553        *declared_name = name;
    15371554    }
    15381555    else
    1539         name_encode.Clear();    // empty
     1556        name_encode.Clear();    // empty
    15401557
    15411558    for(;;){
    1542         t = lex->LookAhead(0);
    1543         if(t == '('){           // function
    1544             Encoding args_encode;
    1545             Token op, cp;
    1546             Ptree *args, *cv, *throw_decl, *mi;
    1547             bool is_args = TRUE;
    1548 
    1549             lex->GetToken(op);
    1550             if(lex->LookAhead(0) == ')'){
    1551                 args = nil;
    1552                 args_encode.StartFuncArgs();
    1553                 args_encode.Void();
    1554                 args_encode.EndFuncArgs();
    1555             }
    1556             else
    1557                 if(!rArgDeclListOrInit(args, is_args, args_encode,
    1558                                        is_statement))
    1559                     return FALSE;
    1560 
    1561             if(lex->GetToken(cp) != ')')
    1562                 return FALSE;
    1563 
    1564             if(is_args){
    1565                 d = Ptree::Nconc(d, Ptree::List(new Leaf(op), args,
    1566                                                 new Leaf(cp)));
    1567                 optCvQualify(cv);
    1568                 if(cv != nil){
    1569                     args_encode.CvQualify(cv);
    1570                     d = Ptree::Nconc(d, cv);
    1571                 }
    1572             }
    1573             else
    1574                 d = Ptree::Snoc(d, Ptree::List(new Leaf(op), args,
    1575                                                new Leaf(cp)));
    1576 
    1577             if(!args_encode.IsEmpty())
    1578                 type_encode.Function(args_encode);
    1579 
    1580             optThrowDecl(throw_decl);   // ignore in this version
    1581 
    1582             if(lex->LookAhead(0) == ':')
    1583                 if(rMemberInitializers(mi))
    1584                     d = Ptree::Snoc(d, mi);
    1585                 else
    1586                     return FALSE;
    1587 
    1588             break;              // "T f(int)(char)" is invalid.
    1589         }
    1590         else if(t == '['){      // array
    1591             Token ob, cb;
    1592             Ptree* expr;
    1593             lex->GetToken(ob);
    1594             if(lex->LookAhead(0) == ']')
    1595                 expr = nil;
    1596             else
    1597                 if(!rCommaExpression(expr))
    1598                     return FALSE;
    1599 
    1600             if(lex->GetToken(cb) != ']')
    1601                 return FALSE;
    1602 
    1603             type_encode.Array();
    1604             d = Ptree::Nconc(d, Ptree::List(new Leaf(ob), expr,
    1605                                             new Leaf(cb)));
    1606         }
    1607         else
    1608             break;
     1559        t = lex->LookAhead(0);
     1560        if(t == '('){           // function
     1561            Encoding args_encode;
     1562            Token op, cp;
     1563            Ptree *args, *cv, *throw_decl, *mi;
     1564            bool is_args = TRUE;
     1565
     1566            lex->GetToken(op);
     1567            if(lex->LookAhead(0) == ')'){
     1568                args = nil;
     1569                args_encode.StartFuncArgs();
     1570                args_encode.Void();
     1571                args_encode.EndFuncArgs();
     1572            }
     1573            else
     1574                if(!rArgDeclListOrInit(args, is_args, args_encode,
     1575                                       is_statement))
     1576                    return FALSE;
     1577
     1578            if(lex->GetToken(cp) != ')')
     1579                return FALSE;
     1580
     1581            if(is_args){
     1582                d = Ptree::Nconc(d, Ptree::List(new Leaf(op), args,
     1583                                                new Leaf(cp)));
     1584                optCvQualify(cv);
     1585                if(cv != nil){
     1586                    args_encode.CvQualify(cv);
     1587                    d = Ptree::Nconc(d, cv);
     1588                }
     1589            }
     1590            else
     1591                d = Ptree::Snoc(d, Ptree::List(new Leaf(op), args,
     1592                                               new Leaf(cp)));
     1593
     1594            if(!args_encode.IsEmpty())
     1595                type_encode.Function(args_encode);
     1596
     1597            optThrowDecl(throw_decl);   // ignore in this version
     1598
     1599            if(lex->LookAhead(0) == ':')
     1600                if(rMemberInitializers(mi))
     1601                    d = Ptree::Snoc(d, mi);
     1602                else
     1603                    return FALSE;
     1604
     1605            break;              // "T f(int)(char)" is invalid.
     1606        }
     1607        else if(t == '['){      // array
     1608            Token ob, cb;
     1609            Ptree* expr;
     1610            lex->GetToken(ob);
     1611            if(lex->LookAhead(0) == ']')
     1612                expr = nil;
     1613            else
     1614                if(!rCommaExpression(expr))
     1615                    return FALSE;
     1616
     1617            if(lex->GetToken(cb) != ']')
     1618                return FALSE;
     1619
     1620            type_encode.Array();
     1621            d = Ptree::Nconc(d, Ptree::List(new Leaf(ob), expr,
     1622                                            new Leaf(cb)));
     1623        }
     1624        else
     1625            break;
    16091626    }
    16101627
    16111628    if(recursive_decl)
    1612         type_encode.Recursion(recursive_encode);
     1629        type_encode.Recursion(recursive_encode);
    16131630
    16141631    if(recursive)
    1615         decl = d;
     1632        decl = d;
    16161633    else
    1617         if(d == nil)
    1618             decl = new PtreeDeclarator(type_encode, name_encode,
    1619                                        *declared_name);
    1620         else
    1621             decl = new PtreeDeclarator(d, type_encode, name_encode,
    1622                                        *declared_name);
     1634        if(d == nil)
     1635            decl = new PtreeDeclarator(type_encode, name_encode,
     1636                                       *declared_name);
     1637        else
     1638            decl = new PtreeDeclarator(d, type_encode, name_encode,
     1639                                       *declared_name);
    16231640
    16241641    return TRUE;
     
    16331650    ptrs = nil;
    16341651    for(;;){
    1635         int t = lex->LookAhead(0);
    1636         if(t != '*' && t != '&' && !isPtrToMember(0))
    1637             break;
    1638         else{
    1639             Ptree *op, *cv;
    1640             if(t == '*' || t == '&'){
    1641                 Token tk;
    1642                 lex->GetToken(tk);
    1643                 op = new Leaf(tk);
    1644                 encode.PtrOperator(t);
    1645             }
    1646             else
    1647                 if(!rPtrToMember(op, encode))
    1648                     return FALSE;
    1649 
    1650             ptrs = Ptree::Snoc(ptrs, op);
    1651             optCvQualify(cv);
    1652             if(cv != nil){
    1653                 ptrs = Ptree::Nconc(ptrs, cv);
    1654                 encode.CvQualify(cv);
    1655             }
    1656         }
     1652        int t = lex->LookAhead(0);
     1653        if(t != '*' && t != '&' && !isPtrToMember(0))
     1654            break;
     1655        else{
     1656            Ptree *op, *cv;
     1657            if(t == '*' || t == '&'){
     1658                Token tk;
     1659                lex->GetToken(tk);
     1660                op = new Leaf(tk);
     1661                encode.PtrOperator(t);
     1662            }
     1663            else
     1664                if(!rPtrToMember(op, encode))
     1665                    return FALSE;
     1666
     1667            ptrs = Ptree::Snoc(ptrs, op);
     1668            optCvQualify(cv);
     1669            if(cv != nil){
     1670                ptrs = Ptree::Nconc(ptrs, cv);
     1671                encode.CvQualify(cv);
     1672            }
     1673        }
    16571674    }
    16581675
     
    16701687
    16711688    if(lex->GetToken(tk) != ':')
    1672         return FALSE;
     1689        return FALSE;
    16731690
    16741691    init = Ptree::List(new Leaf(tk));
    16751692    if(!rMemberInit(m))
    1676         return FALSE;
     1693        return FALSE;
    16771694
    16781695    init = Ptree::Snoc(init, m);
    16791696    while(lex->LookAhead(0) == ','){
    1680         lex->GetToken(tk);
    1681         init = Ptree::Snoc(init, new Leaf(tk));
    1682         if(!rMemberInit(m))
    1683             return FALSE;
    1684 
    1685         init = Ptree::Snoc(init, m);
     1697        lex->GetToken(tk);
     1698        init = Ptree::Snoc(init, new Leaf(tk));
     1699        if(!rMemberInit(m))
     1700            return FALSE;
     1701
     1702        init = Ptree::Snoc(init, m);
    16861703    }
    16871704
     
    17001717
    17011718    if(!rName(name, encode))
    1702         return FALSE;
     1719        return FALSE;
    17031720
    17041721    if(!name->IsLeaf())
    1705         name = new PtreeName(name, encode);
     1722        name = new PtreeName(name, encode);
    17061723
    17071724    if(lex->GetToken(tk1) != '(')
    1708         return FALSE;
     1725        return FALSE;
    17091726
    17101727    if(!rFunctionArguments(args))
    1711         return FALSE;
     1728        return FALSE;
    17121729
    17131730    if(lex->GetToken(tk2) != ')')
    1714         return FALSE;
     1731        return FALSE;
    17151732
    17161733    init = Ptree::List(name, new Leaf(tk1), args, new Leaf(tk2));
     
    17361753
    17371754    if(lex->LookAhead(0) == Scope){
    1738         lex->GetToken(tk);
    1739         name = Ptree::List(new Leaf(tk));
    1740         encode.GlobalScope();
    1741         ++length;
     1755        lex->GetToken(tk);
     1756        name = Ptree::List(new Leaf(tk));
     1757        encode.GlobalScope();
     1758        ++length;
    17421759    }
    17431760    else
    1744         name = nil;
     1761        name = nil;
    17451762
    17461763    for(;;){
    1747         t = lex->GetToken(tk);
    1748         if(t == Identifier){
    1749             Ptree* n = new Leaf(tk);
    1750             t = lex->LookAhead(0);
    1751             if(t == '<'){
    1752                 Ptree* args;
    1753                 Encoding args_encode;
    1754                 if(!rTemplateArgs(args, args_encode))
    1755                     return FALSE;
    1756 
    1757                 encode.Template(n, args_encode);
    1758                 ++length;
    1759                 n = Ptree::List(n, args);
    1760                 t = lex->LookAhead(0);
    1761             }
    1762             else{
    1763                 encode.SimpleName(n);
    1764                 ++length;
    1765             }
    1766 
    1767             if(t == Scope){
    1768                 lex->GetToken(tk);
    1769                 name = Ptree::Nconc(name, Ptree::List(n, new Leaf(tk)));
    1770             }
    1771             else{
    1772                 if(name == nil)
    1773                     name = n;
    1774                 else
    1775                     name = Ptree::Snoc(name, n);
    1776 
    1777                 if(length > 1)
    1778                     encode.Qualified(length);
    1779 
    1780                 return TRUE;
    1781             }
    1782         }
    1783         else if(t == '~'){
    1784             if(lex->LookAhead(0) != Identifier)
    1785                 return FALSE;
    1786 
    1787             lex->GetToken(tk2);
    1788             Ptree* class_name = new Leaf(tk2);
    1789             Ptree* dt = Ptree::List(new Leaf(tk), class_name);
    1790             if(name == nil)
    1791                 name = dt;
    1792             else
    1793                 name = Ptree::Snoc(name, dt);
    1794 
    1795             encode.Destructor(class_name);
    1796             if(length > 0)
    1797                 encode.Qualified(length + 1);
    1798 
    1799             return TRUE;
    1800         }
    1801         else if(t == OPERATOR){
    1802             Ptree* op;
    1803             Ptree* opf;
    1804             if(!rOperatorName(op, encode))
    1805                 return FALSE;
    1806 
    1807             t = lex->LookAhead(0);
    1808             if(t != '<')
    1809                 opf = Ptree::List(new LeafReserved(tk), op);
    1810             else {
    1811                 Ptree* args;
    1812                 Encoding args_encode;
    1813                 if(!rTemplateArgs(args, args_encode))
    1814                     return FALSE;
    1815 
    1816                 // here, I must merge args_encode into encode.
    1817                 // I'll do it in future. :p
    1818 
    1819                 opf = Ptree::List(new LeafReserved(tk), op, args);
    1820             }
    1821 
    1822             if(name == nil)
    1823                 name = opf;
    1824             else
    1825                 name = Ptree::Snoc(name, opf);
    1826 
    1827             if(length > 0)
    1828                 encode.Qualified(length + 1);
    1829 
    1830             return TRUE;
    1831         }
    1832         else
    1833             return FALSE;
     1764        t = lex->GetToken(tk);
     1765        if(t == Identifier){
     1766            Ptree* n = new Leaf(tk);
     1767            t = lex->LookAhead(0);
     1768            if(t == '<'){
     1769                Ptree* args;
     1770                Encoding args_encode;
     1771                if(!rTemplateArgs(args, args_encode))
     1772                    return FALSE;
     1773
     1774                encode.Template(n, args_encode);
     1775                ++length;
     1776                n = Ptree::List(n, args);
     1777                t = lex->LookAhead(0);
     1778            }
     1779            else{
     1780                encode.SimpleName(n);
     1781                ++length;
     1782            }
     1783
     1784            if(t == Scope){
     1785                lex->GetToken(tk);
     1786                name = Ptree::Nconc(name, Ptree::List(n, new Leaf(tk)));
     1787            }
     1788            else{
     1789                if(name == nil)
     1790                    name = n;
     1791                else
     1792                    name = Ptree::Snoc(name, n);
     1793
     1794                if(length > 1)
     1795                    encode.Qualified(length);
     1796
     1797                return TRUE;
     1798            }
     1799        }
     1800        else if(t == '~'){
     1801            if(lex->LookAhead(0) != Identifier)
     1802                return FALSE;
     1803
     1804            lex->GetToken(tk2);
     1805            Ptree* class_name = new Leaf(tk2);
     1806            Ptree* dt = Ptree::List(new Leaf(tk), class_name);
     1807            if(name == nil)
     1808                name = dt;
     1809            else
     1810                name = Ptree::Snoc(name, dt);
     1811
     1812            encode.Destructor(class_name);
     1813            if(length > 0)
     1814                encode.Qualified(length + 1);
     1815
     1816            return TRUE;
     1817        }
     1818        else if(t == OPERATOR){
     1819            Ptree* op;
     1820            Ptree* opf;
     1821            if(!rOperatorName(op, encode))
     1822                return FALSE;
     1823
     1824            t = lex->LookAhead(0);
     1825            if(t != '<')
     1826                opf = Ptree::List(new LeafReserved(tk), op);
     1827            else {
     1828                Ptree* args;
     1829                Encoding args_encode;
     1830                if(!rTemplateArgs(args, args_encode))
     1831                    return FALSE;
     1832
     1833                // here, I must merge args_encode into encode.
     1834                // I'll do it in future. :p
     1835
     1836                opf = Ptree::List(new LeafReserved(tk), op, args);
     1837            }
     1838
     1839            if(name == nil)
     1840                name = opf;
     1841            else
     1842                name = Ptree::Snoc(name, opf);
     1843
     1844            if(length > 0)
     1845                encode.Qualified(length + 1);
     1846
     1847            return TRUE;
     1848        }
     1849        else
     1850            return FALSE;
    18341851    }
    18351852}
     
    18561873       || t == RelOp || t == LogAndOp || t == LogOrOp || t == IncOp
    18571874       || t == ',' || t == PmOp || t == ArrowOp){
    1858         lex->GetToken(tk);
    1859         name = new Leaf(tk);
    1860         encode.SimpleName(name);
    1861         return TRUE;
     1875        lex->GetToken(tk);
     1876        name = new Leaf(tk);
     1877        encode.SimpleName(name);
     1878        return TRUE;
    18621879    }
    18631880    else if(t == NEW || t == DELETE){
    1864         lex->GetToken(tk);
    1865         if(lex->LookAhead(0) != '['){
    1866             name = new LeafReserved(tk);
    1867             encode.SimpleName(name);
    1868             return TRUE;
    1869         }
    1870         else{
    1871             name = Ptree::List(new LeafReserved(tk));
    1872             lex->GetToken(tk);
    1873             name = Ptree::Snoc(name, new Leaf(tk));
    1874             if(lex->GetToken(tk) != ']')
    1875                 return FALSE;
    1876 
    1877             name = Ptree::Snoc(name, new Leaf(tk));
    1878             if(t == NEW)
    1879                 encode.AppendWithLen("new[]", 5);
    1880             else
    1881                 encode.AppendWithLen("delete[]", 8);
    1882 
    1883             return TRUE;
    1884         }
     1881        lex->GetToken(tk);
     1882        if(lex->LookAhead(0) != '['){
     1883            name = new LeafReserved(tk);
     1884            encode.SimpleName(name);
     1885            return TRUE;
     1886        }
     1887        else{
     1888            name = Ptree::List(new LeafReserved(tk));
     1889            lex->GetToken(tk);
     1890            name = Ptree::Snoc(name, new Leaf(tk));
     1891            if(lex->GetToken(tk) != ']')
     1892                return FALSE;
     1893
     1894            name = Ptree::Snoc(name, new Leaf(tk));
     1895            if(t == NEW)
     1896                encode.AppendWithLen("new[]", 5);
     1897            else
     1898                encode.AppendWithLen("delete[]", 8);
     1899
     1900            return TRUE;
     1901        }
    18851902    }
    18861903    else if(t == '('){
    1887         lex->GetToken(tk);
    1888         name = Ptree::List(new Leaf(tk));
    1889         if(lex->GetToken(tk) != ')')
    1890             return FALSE;
    1891 
    1892         encode.AppendWithLen("()", 2);
    1893         name = Ptree::Snoc(name, new Leaf(tk));
    1894         return TRUE;
     1904        lex->GetToken(tk);
     1905        name = Ptree::List(new Leaf(tk));
     1906        if(lex->GetToken(tk) != ')')
     1907            return FALSE;
     1908
     1909        encode.AppendWithLen("()", 2);
     1910        name = Ptree::Snoc(name, new Leaf(tk));
     1911        return TRUE;
    18951912    }
    18961913    else if(t == '['){
    1897         lex->GetToken(tk);
    1898         name = Ptree::List(new Leaf(tk));
    1899         if(lex->GetToken(tk) != ']')
    1900             return FALSE;
    1901 
    1902         encode.AppendWithLen("[]", 2);
    1903         name = Ptree::Snoc(name, new Leaf(tk));
    1904         return TRUE;
     1914        lex->GetToken(tk);
     1915        name = Ptree::List(new Leaf(tk));
     1916        if(lex->GetToken(tk) != ']')
     1917            return FALSE;
     1918
     1919        encode.AppendWithLen("[]", 2);
     1920        name = Ptree::Snoc(name, new Leaf(tk));
     1921        return TRUE;
    19051922    }
    19061923    else
    1907         return rCastOperatorName(name, encode);
     1924        return rCastOperatorName(name, encode);
    19081925}
    19091926
     
    19191936
    19201937    if(!optCvQualify(cv1))
    1921         return FALSE;
     1938        return FALSE;
    19221939
    19231940    if(!optIntegralTypeOrClassSpec(type_name, type_encode))
    1924         return FALSE;
     1941        return FALSE;
    19251942
    19261943    if(type_name == nil){
    1927         type_encode.Clear();
    1928         if(!rName(type_name, type_encode))
    1929             return FALSE;
     1944        type_encode.Clear();
     1945        if(!rName(type_name, type_encode))
     1946            return FALSE;
    19301947    }
    19311948
    19321949    if(!optCvQualify(cv2))
    1933         return FALSE;
     1950        return FALSE;
    19341951
    19351952    if(cv1 != nil)
    1936         if(cv2 == nil)
    1937             type_name = Ptree::Snoc(cv1, type_name);
    1938         else
    1939             type_name = Ptree::Nconc(cv1, Ptree::Cons(type_name, cv2));
     1953        if(cv2 == nil)
     1954            type_name = Ptree::Snoc(cv1, type_name);
     1955        else
     1956            type_name = Ptree::Nconc(cv1, Ptree::Cons(type_name, cv2));
    19401957    else if(cv2 != nil)
    1941         type_name = Ptree::Cons(type_name, cv2);
     1958        type_name = Ptree::Cons(type_name, cv2);
    19421959
    19431960    type_encode.CvQualify(cv1, cv2);
    19441961
    19451962    if(!optPtrOperator(ptr, type_encode))
    1946         return FALSE;
     1963        return FALSE;
    19471964
    19481965    encode.CastOperator(type_encode);
    19491966    if(ptr == nil){
    1950         name = type_name;
    1951         return TRUE;
     1967        name = type_name;
     1968        return TRUE;
    19521969    }
    19531970    else{
    1954         name = Ptree::List(type_name, ptr);
    1955         return TRUE;
     1971        name = Ptree::List(type_name, ptr);
     1972        return TRUE;
    19561973    }
    19571974}
     
    19691986
    19701987    if(lex->LookAhead(0) == Scope){
    1971         lex->GetToken(tk);
    1972         p = Ptree::List(new Leaf(tk));
    1973         pm_encode.GlobalScope();
    1974         ++length;
     1988        lex->GetToken(tk);
     1989        p = Ptree::List(new Leaf(tk));
     1990        pm_encode.GlobalScope();
     1991        ++length;
    19751992    }
    19761993    else
    1977         p = nil;
     1994        p = nil;
    19781995
    19791996    for(;;){
    1980         if(lex->GetToken(tk) == Identifier)
    1981             n = new Leaf(tk);
    1982         else
    1983             return FALSE;
    1984 
    1985         int t = lex->LookAhead(0);
    1986         if(t == '<'){
    1987             Ptree* args;
    1988             Encoding args_encode;
    1989             if(!rTemplateArgs(args, args_encode))
    1990                 return FALSE;
    1991 
    1992             pm_encode.Template(n, args_encode);
    1993             ++length;
    1994             n = Ptree::List(n, args);
    1995             t = lex->LookAhead(0);
    1996         }
    1997         else{
    1998             pm_encode.SimpleName(n);
    1999             ++length;
    2000         }
    2001 
    2002         if(lex->GetToken(tk) != Scope)
    2003             return FALSE;
    2004 
    2005         p = Ptree::Nconc(p, Ptree::List(n, new Leaf(tk)));
    2006         if(lex->LookAhead(0) == '*'){
    2007             lex->GetToken(tk);
    2008             p = Ptree::Snoc(p, new Leaf(tk));
    2009             break;
    2010         }
     1997        if(lex->GetToken(tk) == Identifier)
     1998            n = new Leaf(tk);
     1999        else
     2000            return FALSE;
     2001
     2002        int t = lex->LookAhead(0);
     2003        if(t == '<'){
     2004            Ptree* args;
     2005            Encoding args_encode;
     2006            if(!rTemplateArgs(args, args_encode))
     2007                return FALSE;
     2008
     2009            pm_encode.Template(n, args_encode);
     2010            ++length;
     2011            n = Ptree::List(n, args);
     2012            t = lex->LookAhead(0);
     2013        }
     2014        else{
     2015            pm_encode.SimpleName(n);
     2016            ++length;
     2017        }
     2018
     2019        if(lex->GetToken(tk) != Scope)
     2020            return FALSE;
     2021
     2022        p = Ptree::Nconc(p, Ptree::List(n, new Leaf(tk)));
     2023        if(lex->LookAhead(0) == '*'){
     2024            lex->GetToken(tk);
     2025            p = Ptree::Snoc(p, new Leaf(tk));
     2026            break;
     2027        }
    20112028    }
    20122029
     
    20312048
    20322049    if(lex->GetToken(tk1) != '<')
    2033         return FALSE;
     2050        return FALSE;
    20342051
    20352052    // in case of Foo<>
    20362053    if(lex->LookAhead(0) == '>') {
    2037         lex->GetToken(tk2);
    2038         temp_args = Ptree::List(new Leaf(tk1), new Leaf(tk2));
    2039         return TRUE;
     2054        lex->GetToken(tk2);
     2055        temp_args = Ptree::List(new Leaf(tk1), new Leaf(tk2));
     2056        return TRUE;
    20402057    }
    20412058
    20422059    Ptree* args = nil;
    20432060    for(;;){
    2044         Ptree* a;
    2045         char* pos = lex->Save();
    2046         type_encode.Clear();
    2047         if(rTypeName(a, type_encode))
    2048             encode.Append(type_encode);
    2049         else{
    2050             lex->Restore(pos); 
    2051             if(!rLogicalOrExpr(a, TRUE))
    2052                 return FALSE;
    2053 
    2054             encode.ValueTempParam();
    2055         }
    2056 
    2057         args = Ptree::Snoc(args, a);
    2058         switch(lex->GetToken(tk2)){
    2059         case '>' :
    2060             temp_args = Ptree::List(new Leaf(tk1), args, new Leaf(tk2));
    2061             return TRUE;
    2062         case ',' :
    2063             args = Ptree::Snoc(args, new Leaf(tk2));
    2064             break;
    2065         case ShiftOp :
    2066             if(*tk2.ptr == '>'){
    2067                 lex->GetOnlyClosingBracket(tk2);
    2068                 temp_args = Ptree::List(new Leaf(tk1), args,
    2069                                         new Leaf(tk2.ptr, 1));
    2070                 return TRUE;
    2071             }
    2072 
    2073         default :
    2074             return FALSE;
    2075         }
     2061        Ptree* a;
     2062        char* pos = lex->Save();
     2063        type_encode.Clear();
     2064        if(rTypeName(a, type_encode))
     2065            encode.Append(type_encode);
     2066        else{
     2067            lex->Restore(pos);
     2068            if(!rLogicalOrExpr(a, TRUE))
     2069                return FALSE;
     2070
     2071            encode.ValueTempParam();
     2072        }
     2073
     2074        args = Ptree::Snoc(args, a);
     2075        switch(lex->GetToken(tk2)){
     2076        case '>' :
     2077            temp_args = Ptree::List(new Leaf(tk1), args, new Leaf(tk2));
     2078            return TRUE;
     2079        case ',' :
     2080            args = Ptree::Snoc(args, new Leaf(tk2));
     2081            break;
     2082        case ShiftOp :
     2083            if(*tk2.ptr == '>'){
     2084                lex->GetOnlyClosingBracket(tk2);
     2085                temp_args = Ptree::List(new Leaf(tk1), args,
     2086                                        new Leaf(tk2.ptr, 1));
     2087                return TRUE;
     2088            }
     2089
     2090        default :
     2091            return FALSE;
     2092        }
    20762093    }
    20772094}
     
    20832100
    20842101  This rule accepts function.arguments to parse declarations like:
    2085         Point p(1, 3);
     2102        Point p(1, 3);
    20862103  "(1, 3)" is arg.decl.list.or.init.
    20872104
    20882105  If maybe_init is true, we first examine whether tokens construct
    20892106  function.arguments.  This ordering is significant if tokens are
    2090         Point p(s, t);
     2107        Point p(s, t);
    20912108  s and t can be type names or variable names.
    20922109*/
    20932110bool Parser::rArgDeclListOrInit(Ptree*& arglist, bool& is_args,
    2094                                 Encoding& encode, bool maybe_init)
     2111                                Encoding& encode, bool maybe_init)
    20952112{
    20962113    char* pos = lex->Save();
    20972114    if(maybe_init) {
    2098         if(rFunctionArguments(arglist))
    2099             if(lex->LookAhead(0) == ')') {
    2100                 is_args = FALSE;
    2101                 encode.Clear();
    2102                 return TRUE;
    2103             }
    2104 
    2105         lex->Restore(pos);
    2106         return(is_args = rArgDeclList(arglist, encode));
     2115        if(rFunctionArguments(arglist))
     2116            if(lex->LookAhead(0) == ')') {
     2117                is_args = FALSE;
     2118                encode.Clear();
     2119                return TRUE;
     2120            }
     2121
     2122        lex->Restore(pos);
     2123        return(is_args = rArgDeclList(arglist, encode));
    21072124    }
    21082125    else
    2109         if(is_args = rArgDeclList(arglist, encode))
    2110             return TRUE;
    2111         else{
    2112             lex->Restore(pos);
    2113             encode.Clear();
    2114             return rFunctionArguments(arglist);
    2115         }
     2126        if(is_args = rArgDeclList(arglist, encode))
     2127            return TRUE;
     2128        else{
     2129            lex->Restore(pos);
     2130            encode.Clear();
     2131            return rFunctionArguments(arglist);
     2132        }
    21162133}
    21172134
     
    21322149    list = nil;
    21332150    for(;;){
    2134         arg_encode.Clear();
    2135         t = lex->LookAhead(0);
    2136         if(t == ')'){
    2137             if(list == nil)
    2138                 encode.Void();
    2139 
    2140             arglist = list;
    2141             break;
    2142         }
    2143         else if(t == Ellipsis){
    2144             lex->GetToken(tk);
    2145             encode.EllipsisArg();
    2146             arglist = Ptree::Snoc(list, new Leaf(tk));
    2147             break;
    2148         }
    2149         else if(rArgDeclaration(d, arg_encode)){
    2150             encode.Append(arg_encode);
    2151             list = Ptree::Snoc(list, d);
    2152             t = lex->LookAhead(0);
    2153             if(t == ','){
    2154                 lex->GetToken(tk);
    2155                 list = Ptree::Snoc(list, new Leaf(tk));
    2156             }
    2157             else if(t != ')' && t != Ellipsis)
    2158                 return FALSE;
    2159         }
    2160         else{
    2161             arglist = nil;
    2162             return FALSE;
    2163         }
     2151        arg_encode.Clear();
     2152        t = lex->LookAhead(0);
     2153        if(t == ')'){
     2154            if(list == nil)
     2155                encode.Void();
     2156
     2157            arglist = list;
     2158            break;
     2159        }
     2160        else if(t == Ellipsis){
     2161            lex->GetToken(tk);
     2162            encode.EllipsisArg();
     2163            arglist = Ptree::Snoc(list, new Leaf(tk));
     2164            break;
     2165        }
     2166        else if(rArgDeclaration(d, arg_encode)){
     2167            encode.Append(arg_encode);
     2168            list = Ptree::Snoc(list, d);
     2169            t = lex->LookAhead(0);
     2170            if(t == ','){
     2171                lex->GetToken(tk);
     2172                list = Ptree::Snoc(list, new Leaf(tk));
     2173            }
     2174            else if(t != ')' && t != Ellipsis)
     2175                return FALSE;
     2176        }
     2177        else{
     2178            arglist = nil;
     2179            return FALSE;
     2180        }
    21642181    }
    21652182
     
    21812198    switch(lex->LookAhead(0)){
    21822199    case REGISTER :
    2183         lex->GetToken(tk);
    2184         header = new LeafREGISTER(tk);
    2185         break;
     2200        lex->GetToken(tk);
     2201        header = new LeafREGISTER(tk);
     2202        break;
    21862203    case UserKeyword :
    2187         if(!rUserdefKeyword(header))
    2188             return FALSE;
     2204        if(!rUserdefKeyword(header))
     2205            return FALSE;
    21892206        break;
    21902207    default :
    2191         header = nil;
     2208        header = nil;
    21922209        break;
    21932210    }
    21942211
    21952212    if(!rTypeSpecifier(type_name, TRUE, encode))
    2196         return FALSE;
     2213        return FALSE;
    21972214
    21982215    if(!rDeclarator(arg, kArgDeclarator, FALSE, encode, name_encode, TRUE))
    2199         return FALSE;
     2216        return FALSE;
    22002217
    22012218    if(header == nil)
    2202         decl = Ptree::List(type_name, arg);
     2219        decl = Ptree::List(type_name, arg);
    22032220    else
    2204         decl = Ptree::List(header, type_name, arg);
     2221        decl = Ptree::List(header, type_name, arg);
    22052222
    22062223    int t = lex->LookAhead(0);
    22072224    if(t == '='){
    2208         lex->GetToken(tk);
    2209         if(!rInitializeExpr(e))
    2210             return FALSE;
    2211 
    2212         decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk), e));
     2225        lex->GetToken(tk);
     2226        if(!rInitializeExpr(e))
     2227            return FALSE;
     2228
     2229        decl = Ptree::Nconc(decl, Ptree::List(new Leaf(tk), e));
    22132230    }
    22142231
     
    22272244
    22282245    if(lex->LookAhead(0) != '{')
    2229         return rExpression(exp);
     2246        return rExpression(exp);
    22302247    else{
    2231         lex->GetToken(tk);
    2232         Ptree* ob = new Leaf(tk);
    2233         elist = nil;
    2234         int t = lex->LookAhead(0);
    2235         while(t != '}'){
    2236             if(!rInitializeExpr(e)){
    2237                 if(!SyntaxError())
    2238                     return FALSE;       // too many errors
    2239 
    2240                 SkipTo('}');
    2241                 lex->GetToken(tk);
    2242                 exp = Ptree::List(ob, nil, new Leaf(tk));
    2243                 return TRUE;            // error recovery
    2244             }
    2245 
    2246             elist = Ptree::Snoc(elist, e);
    2247             t = lex->LookAhead(0);
    2248             if(t == '}')
    2249                 break;
    2250             else if(t == ','){
    2251                 lex->GetToken(tk);
    2252                 elist = Ptree::Snoc(elist, new Leaf(tk));
    2253                 t = lex->LookAhead(0);
    2254             }
    2255             else{
    2256                 if(!SyntaxError())
    2257                     return FALSE;       // too many errors
    2258 
    2259                 SkipTo('}');
    2260                 lex->GetToken(tk);
    2261                 exp = Ptree::List(ob, nil, new Leaf(tk));
    2262                 return TRUE;            // error recovery
    2263             }
    2264         }
    2265 
    2266         lex->GetToken(tk);
    2267         exp = new PtreeBrace(ob, elist, new Leaf(tk));
    2268         return TRUE;
     2248        lex->GetToken(tk);
     2249        Ptree* ob = new Leaf(tk);
     2250        elist = nil;
     2251        int t = lex->LookAhead(0);
     2252        while(t != '}'){
     2253            if(!rInitializeExpr(e)){
     2254                if(!SyntaxError())
     2255                    return FALSE;       // too many errors
     2256
     2257                SkipTo('}');
     2258                lex->GetToken(tk);
     2259                exp = Ptree::List(ob, nil, new Leaf(tk));
     2260                return TRUE;            // error recovery
     2261            }
     2262
     2263            elist = Ptree::Snoc(elist, e);
     2264            t = lex->LookAhead(0);
     2265            if(t == '}')
     2266                break;
     2267            else if(t == ','){
     2268                lex->GetToken(tk);
     2269                elist = Ptree::Snoc(elist, new Leaf(tk));
     2270                t = lex->LookAhead(0);
     2271            }
     2272            else{
     2273                if(!SyntaxError())
     2274                    return FALSE;       // too many errors
     2275
     2276                SkipTo('}');
     2277                lex->GetToken(tk);
     2278                exp = Ptree::List(ob, nil, new Leaf(tk));
     2279                return TRUE;            // error recovery
     2280            }
     2281        }
     2282
     2283        lex->GetToken(tk);
     2284        exp = new PtreeBrace(ob, elist, new Leaf(tk));
     2285        return TRUE;
    22692286    }
    22702287}
     
    22842301    args = nil;
    22852302    if(lex->LookAhead(0) == ')')
    2286         return TRUE;
     2303        return TRUE;
    22872304
    22882305    for(;;){
    2289         if(!rExpression(exp))
    2290             return FALSE;
    2291 
    2292         args = Ptree::Snoc(args, exp);
    2293         if(lex->LookAhead(0) != ',')
    2294             return TRUE;
    2295         else{
    2296             lex->GetToken(tk);
    2297             args = Ptree::Snoc(args, new Leaf(tk));
    2298         }
     2306        if(!rExpression(exp))
     2307            return FALSE;
     2308
     2309        args = Ptree::Snoc(args, exp);
     2310        if(lex->LookAhead(0) != ',')
     2311            return TRUE;
     2312        else{
     2313            lex->GetToken(tk);
     2314            args = Ptree::Snoc(args, new Leaf(tk));
     2315        }
    22992316    }
    23002317}
     
    23112328
    23122329    if(lex->GetToken(tk) != ENUM)
    2313         return FALSE;
     2330        return FALSE;
    23142331
    23152332    spec = new PtreeEnumSpec(new Leaf(tk));
    23162333    int t = lex->GetToken(tk);
    23172334    if(t == Identifier){
    2318         Ptree* name = new Leaf(tk);
    2319         encode.SimpleName(name);
    2320         ((PtreeEnumSpec*)spec)->encoded_name = encode.Get();
    2321         spec = Ptree::Snoc(spec, name);
    2322         if(lex->LookAhead(0) == '{')
    2323             t = lex->GetToken(tk);
    2324         else
    2325             return TRUE;
     2335        Ptree* name = new Leaf(tk);
     2336        encode.SimpleName(name);
     2337        ((PtreeEnumSpec*)spec)->encoded_name = encode.Get();
     2338        spec = Ptree::Snoc(spec, name);
     2339        if(lex->LookAhead(0) == '{')
     2340            t = lex->GetToken(tk);
     2341        else
     2342            return TRUE;
    23262343    }
    23272344    else{
    2328         encode.NoName();
    2329         ((PtreeEnumSpec*)spec)->encoded_name = encode.Get();
    2330         spec = Ptree::Snoc(spec, nil);
     2345        encode.NoName();
     2346        ((PtreeEnumSpec*)spec)->encoded_name = encode.Get();
     2347        spec = Ptree::Snoc(spec, nil);
    23312348    }
    23322349
    23332350    if(t != '{')
    2334         return FALSE;
     2351        return FALSE;
    23352352
    23362353    if(lex->LookAhead(0) == '}')
    2337         body = nil;
     2354        body = nil;
    23382355    else
    2339         if(!rEnumBody(body))
    2340             return FALSE;
     2356        if(!rEnumBody(body))
     2357            return FALSE;
    23412358
    23422359    if(lex->GetToken(tk2) != '}')
    2343         return FALSE;
     2360        return FALSE;
    23442361
    23452362    spec = Ptree::Snoc(spec, new PtreeBrace(new Leaf(tk), body,
    2346                                             new Leaf(tk2)));
     2363                                            new Leaf(tk2)));
    23472364    return TRUE;
    23482365}
     
    23592376    body = nil;
    23602377    for(;;){
    2361         if(lex->LookAhead(0) == '}')
    2362             return TRUE;
    2363 
    2364         if(lex->GetToken(tk) != Identifier)
    2365             return FALSE;
    2366 
    2367         if(lex->LookAhead(0, tk2) != '=')
    2368             name = new Leaf(tk);
    2369         else{
    2370             lex->GetToken(tk2);
    2371             if(!rExpression(exp)){
    2372                 if(!SyntaxError())
    2373                     return FALSE;       // too many errors
    2374 
    2375                 SkipTo('}');
    2376                 body = nil;             // empty
    2377                 return TRUE;            // error recovery
    2378             }
    2379 
    2380             name = Ptree::List(new Leaf(tk), new Leaf(tk2), exp);
    2381         }
    2382 
    2383         if(lex->LookAhead(0) != ','){
    2384             body = Ptree::Snoc(body, name);
    2385             return TRUE;
    2386         }
    2387         else{
    2388             lex->GetToken(tk);
    2389             body = Ptree::Nconc(body, Ptree::List(name, new Leaf(tk)));
    2390         }
     2378        if(lex->LookAhead(0) == '}')
     2379            return TRUE;
     2380
     2381        if(lex->GetToken(tk) != Identifier)
     2382            return FALSE;
     2383
     2384        if(lex->LookAhead(0, tk2) != '=')
     2385            name = new Leaf(tk);
     2386        else{
     2387            lex->GetToken(tk2);
     2388            if(!rExpression(exp)){
     2389                if(!SyntaxError())
     2390                    return FALSE;       // too many errors
     2391
     2392                SkipTo('}');
     2393                body = nil;             // empty
     2394                return TRUE;            // error recovery
     2395            }
     2396
     2397            name = Ptree::List(new Leaf(tk), new Leaf(tk2), exp);
     2398        }
     2399
     2400        if(lex->LookAhead(0) != ','){
     2401            body = Ptree::Snoc(body, name);
     2402            return TRUE;
     2403        }
     2404        else{
     2405            lex->GetToken(tk);
     2406            body = Ptree::Nconc(body, Ptree::List(name, new Leaf(tk)));
     2407        }
    23912408    }
    23922409}
     
    24082425    head = nil;
    24092426    if(lex->LookAhead(0) == UserKeyword)
    2410         if(!rUserdefKeyword(head))
    2411             return FALSE;
     2427        if(!rUserdefKeyword(head))
     2428            return FALSE;
    24122429
    24132430    int t = lex->GetToken(tk);
    24142431    if(t != CLASS && t != STRUCT && t != UNION)
    2415         return FALSE;
     2432        return FALSE;
    24162433
    24172434    Ptree* comments = lex->GetComments();
    24182435    spec = new PtreeClassSpec(new LeafReserved(tk), nil, comments);
    24192436    if(head != nil)
    2420         spec = new PtreeClassSpec(head, spec, comments);
     2437        spec = new PtreeClassSpec(head, spec, comments);
    24212438
    24222439    if(lex->LookAhead(0) == '{'){
    2423         encode.NoName();
    2424         spec = Ptree::Snoc(spec, Ptree::List(nil, nil));
     2440        encode.NoName();
     2441        spec = Ptree::Snoc(spec, Ptree::List(nil, nil));
    24252442    }
    24262443    else{
    2427         if(!rName(name, encode))
    2428             return FALSE;
    2429 
    2430         spec = Ptree::Snoc(spec, name);
    2431         t = lex->LookAhead(0);
    2432         if(t == ':'){
    2433             if(!rBaseSpecifiers(bases))
    2434                 return FALSE;
    2435 
    2436             spec = Ptree::Snoc(spec, bases);
    2437         }
    2438         else if(t == '{')
    2439             spec = Ptree::Snoc(spec, nil);
    2440         else{
    2441             ((PtreeClassSpec*)spec)->encoded_name = encode.Get();
    2442             return TRUE;        // class.key Identifier
    2443         }
     2444        if(!rName(name, encode))
     2445            return FALSE;
     2446
     2447        spec = Ptree::Snoc(spec, name);
     2448        t = lex->LookAhead(0);
     2449        if(t == ':'){
     2450            if(!rBaseSpecifiers(bases))
     2451                return FALSE;
     2452
     2453            spec = Ptree::Snoc(spec, bases);
     2454        }
     2455        else if(t == '{')
     2456            spec = Ptree::Snoc(spec, nil);
     2457        else{
     2458            ((PtreeClassSpec*)spec)->encoded_name = encode.Get();
     2459            return TRUE;        // class.key Identifier
     2460        }
    24442461    }
    24452462
    24462463    ((PtreeClassSpec*)spec)->encoded_name = encode.Get();
    24472464    if(!rClassBody(body))
    2448         return FALSE;
     2465        return FALSE;
    24492466
    24502467    spec = Ptree::Snoc(spec, body);
     
    24672484
    24682485    if(lex->GetToken(tk) != ':')
    2469         return FALSE;
     2486        return FALSE;
    24702487
    24712488    bases = Ptree::List(new Leaf(tk));
    24722489    for(;;){
    2473         Ptree* super = nil;
    2474         t = lex->LookAhead(0);
    2475         if(t == VIRTUAL){
    2476             lex->GetToken(tk);
    2477             super = Ptree::Snoc(super, new LeafVIRTUAL(tk));
    2478             t = lex->LookAhead(0);
    2479         }
    2480 
    2481         if(t == PUBLIC || t == PROTECTED || t == PRIVATE){ /* kso | -> || */
    2482             Ptree* lf;
    2483             switch(lex->GetToken(tk)){
    2484             case PUBLIC :
    2485                 lf = new LeafPUBLIC(tk);
    2486                 break;
    2487             case PROTECTED :
    2488                 lf = new LeafPROTECTED(tk);
    2489                 break;
    2490             case PRIVATE :
    2491                 lf = new LeafPRIVATE(tk);
    2492                 break;
    2493             default :
    2494                 MopErrorMessage("rBaseSpecifiers()", "fatal");
    2495                 lf = nil;
    2496                 break;
    2497             }
    2498 
    2499             super = Ptree::Snoc(super, lf);
    2500             t = lex->LookAhead(0);
    2501         }
    2502 
    2503         if(t == VIRTUAL){
    2504             lex->GetToken(tk);
    2505             super = Ptree::Snoc(super, new LeafVIRTUAL(tk));
    2506         }
    2507 
    2508         encode.Clear();
    2509         if(!rName(name, encode))
    2510             return FALSE;
    2511 
    2512         if(!name->IsLeaf())
    2513             name = new PtreeName(name, encode);
    2514 
    2515         super = Ptree::Snoc(super, name);
    2516         bases = Ptree::Snoc(bases, super);
    2517         if(lex->LookAhead(0) != ',')
    2518             return TRUE;
    2519         else{
    2520             lex->GetToken(tk);
    2521             bases = Ptree::Snoc(bases, new Leaf(tk));
    2522         }
     2490        Ptree* super = nil;
     2491        t = lex->LookAhead(0);
     2492        if(t == VIRTUAL){
     2493            lex->GetToken(tk);
     2494            super = Ptree::Snoc(super, new LeafVIRTUAL(tk));
     2495            t = lex->LookAhead(0);
     2496        }
     2497
     2498        if(t == PUBLIC || t == PROTECTED || t == PRIVATE){ /* kso | -> || */
     2499            Ptree* lf;
     2500            switch(lex->GetToken(tk)){
     2501            case PUBLIC :
     2502                lf = new LeafPUBLIC(tk);
     2503                break;
     2504            case PROTECTED :
     2505                lf = new LeafPROTECTED(tk);
     2506                break;
     2507            case PRIVATE :
     2508                lf = new LeafPRIVATE(tk);
     2509                break;
     2510            default :
     2511                MopErrorMessage("rBaseSpecifiers()", "fatal");
     2512                lf = nil;
     2513                break;
     2514            }
     2515
     2516            super = Ptree::Snoc(super, lf);
     2517            t = lex->LookAhead(0);
     2518        }
     2519
     2520        if(t == VIRTUAL){
     2521            lex->GetToken(tk);
     2522            super = Ptree::Snoc(super, new LeafVIRTUAL(tk));
     2523        }
     2524
     2525        encode.Clear();
     2526        if(!rName(name, encode))
     2527            return FALSE;
     2528
     2529        if(!name->IsLeaf())
     2530            name = new PtreeName(name, encode);
     2531
     2532        super = Ptree::Snoc(super, name);
     2533        bases = Ptree::Snoc(bases, super);
     2534        if(lex->LookAhead(0) != ',')
     2535            return TRUE;
     2536        else{
     2537            lex->GetToken(tk);
     2538            bases = Ptree::Snoc(bases, new Leaf(tk));
     2539        }
    25232540    }
    25242541}
     
    25332550
    25342551    if(lex->GetToken(tk) != '{')
    2535         return FALSE;
     2552        return FALSE;
    25362553
    25372554    Ptree* ob = new Leaf(tk);
    25382555    mems = nil;
    25392556    while(lex->LookAhead(0) != '}'){
    2540         if(!rClassMember(m)){
    2541             if(!SyntaxError())
    2542                 return FALSE;   // too many errors
    2543 
    2544             SkipTo('}');
    2545             lex->GetToken(tk);
    2546             body = Ptree::List(ob, nil, new Leaf(tk));
    2547             return TRUE;        // error recovery
    2548         }
    2549 
    2550         lex->GetComments();
    2551         mems = Ptree::Snoc(mems, m);
     2557        if(!rClassMember(m)){
     2558            if(!SyntaxError())
     2559                return FALSE;   // too many errors
     2560
     2561            SkipTo('}');
     2562            lex->GetToken(tk);
     2563            body = Ptree::List(ob, nil, new Leaf(tk));
     2564            return TRUE;        // error recovery
     2565        }
     2566
     2567        lex->GetComments();
     2568        mems = Ptree::Snoc(mems, m);
    25522569    }
    25532570
     
    25782595    int t = lex->LookAhead(0);
    25792596    if(t == PUBLIC || t == PROTECTED || t == PRIVATE){
    2580         Ptree* lf;
    2581         switch(lex->GetToken(tk1)){
    2582         case PUBLIC :
    2583             lf = new LeafPUBLIC(tk1);
    2584             break;
    2585         case PROTECTED :
    2586             lf = new LeafPROTECTED(tk1);
    2587             break;
    2588         case PRIVATE :
    2589             lf = new LeafPRIVATE(tk1);
    2590             break;
    2591         default :
    2592             MopErrorMessage("rClassMember()", "fatal");
    2593             lf = nil;
    2594             break;
    2595         }
    2596 
    2597         if(lex->GetToken(tk2) != ':')
    2598             return FALSE;
    2599 
    2600         mem = new PtreeAccessSpec(lf, Ptree::List(new Leaf(tk2)));
    2601         return TRUE;
     2597        Ptree* lf;
     2598        switch(lex->GetToken(tk1)){
     2599        case PUBLIC :
     2600            lf = new LeafPUBLIC(tk1);
     2601            break;
     2602        case PROTECTED :
     2603            lf = new LeafPROTECTED(tk1);
     2604            break;
     2605        case PRIVATE :
     2606            lf = new LeafPRIVATE(tk1);
     2607            break;
     2608        default :
     2609            MopErrorMessage("rClassMember()", "fatal");
     2610            lf = nil;
     2611            break;
     2612        }
     2613
     2614        if(lex->GetToken(tk2) != ':')
     2615            return FALSE;
     2616
     2617        mem = new PtreeAccessSpec(lf, Ptree::List(new Leaf(tk2)));
     2618        return TRUE;
    26022619    }
    26032620    else if(t == UserKeyword4)
    2604         return rUserAccessSpec(mem);
     2621        return rUserAccessSpec(mem);
    26052622    else if(t == ';')
    2606         return rNullDeclaration(mem);
     2623        return rNullDeclaration(mem);
    26072624    else if(t == TYPEDEF)
    2608         return rTypedef(mem);
     2625        return rTypedef(mem);
    26092626    else if(t == TEMPLATE)
    2610         return rTemplateDecl(mem);
     2627        return rTemplateDecl(mem);
    26112628    else if(t == USING)
    2612         return rUsing(mem);
     2629        return rUsing(mem);
    26132630    else if(t == METACLASS)
    2614         return rMetaclassDecl(mem);
     2631        return rMetaclassDecl(mem);
    26152632    else{
    2616         char* pos = lex->Save();
    2617         Ptree* comments = lex->GetComments2();
    2618         if(rDeclaration(mem)) {
    2619             Walker::SetDeclaratorComments(mem, comments);
    2620             return TRUE;
    2621         }
    2622 
    2623         lex->Restore(pos);
    2624         return rAccessDecl(mem);
     2633        char* pos = lex->Save();
     2634        Ptree* comments = lex->GetComments2();
     2635        if(rDeclaration(mem)) {
     2636            Walker::SetDeclaratorComments(mem, comments);
     2637            return TRUE;
     2638        }
     2639
     2640        lex->Restore(pos);
     2641        return rAccessDecl(mem);
    26252642    }
    26262643}
     
    26282645/*
    26292646  access.decl
    2630   : name ';'            e.g. <qualified class>::<member name>;
     2647  : name ';'            e.g. <qualified class>::<member name>;
    26312648*/
    26322649bool Parser::rAccessDecl(Ptree*& mem)
     
    26372654
    26382655    if(!rName(name, encode))
    2639         return FALSE;
     2656        return FALSE;
    26402657
    26412658    if(lex->GetToken(tk) != ';')
    2642         return FALSE;
     2659        return FALSE;
    26432660
    26442661    mem = new PtreeAccessDecl(new PtreeName(name, encode),
    2645                                Ptree::List(new Leaf(tk)));
     2662                               Ptree::List(new Leaf(tk)));
    26462663    return TRUE;
    26472664}
     
    26582675
    26592676    if(lex->GetToken(tk1) != UserKeyword4)
    2660         return FALSE;
     2677        return FALSE;
    26612678
    26622679    int t = lex->GetToken(tk2);
    26632680    if(t == ':'){
    2664         mem = new PtreeUserAccessSpec(new Leaf(tk1),
    2665                                       Ptree::List(new Leaf(tk2)));
    2666         return TRUE;
     2681        mem = new PtreeUserAccessSpec(new Leaf(tk1),
     2682                                      Ptree::List(new Leaf(tk2)));
     2683        return TRUE;
    26672684    }
    26682685    else if(t == '('){
    2669         if(!rFunctionArguments(args))
    2670             return FALSE;
    2671 
    2672         if(lex->GetToken(tk3) != ')')
    2673             return FALSE;
    2674 
    2675         if(lex->GetToken(tk4) != ':')
    2676             return FALSE;
    2677 
    2678         mem = new PtreeUserAccessSpec(new Leaf(tk1),
    2679                                       Ptree::List(new Leaf(tk2), args,
    2680                                                   new Leaf(tk3),
    2681                                                   new Leaf(tk4)));
    2682         return TRUE;
     2686        if(!rFunctionArguments(args))
     2687            return FALSE;
     2688
     2689        if(lex->GetToken(tk3) != ')')
     2690            return FALSE;
     2691
     2692        if(lex->GetToken(tk4) != ':')
     2693            return FALSE;
     2694
     2695        mem = new PtreeUserAccessSpec(new Leaf(tk1),
     2696                                      Ptree::List(new Leaf(tk2), args,
     2697                                                  new Leaf(tk3),
     2698                                                  new Leaf(tk4)));
     2699        return TRUE;
    26832700    }
    26842701    else
    2685         return FALSE;
     2702        return FALSE;
    26862703}
    26872704
     
    26892706  comma.expression
    26902707  : expression
    2691   | comma.expression ',' expression     (left-to-right)
     2708  | comma.expression ',' expression     (left-to-right)
    26922709*/
    26932710bool Parser::rCommaExpression(Ptree*& exp)
     
    26972714
    26982715    if(!rExpression(exp))
    2699         return FALSE;
     2716        return FALSE;
    27002717
    27012718    while(lex->LookAhead(0) == ','){
    2702         lex->GetToken(tk);
    2703         if(!rExpression(right))
    2704             return FALSE;
    2705 
    2706         exp = new PtreeCommaExpr(exp, Ptree::List(new Leaf(tk), right));
     2719        lex->GetToken(tk);
     2720        if(!rExpression(right))
     2721            return FALSE;
     2722
     2723        exp = new PtreeCommaExpr(exp, Ptree::List(new Leaf(tk), right));
    27072724    }
    27082725
     
    27122729/*
    27132730  expression
    2714   : conditional.expr {(AssignOp | '=') expression}      right-to-left
     2731  : conditional.expr {(AssignOp | '=') expression}      right-to-left
    27152732*/
    27162733bool Parser::rExpression(Ptree*& exp)
     
    27202737
    27212738    if(!rConditionalExpr(left))
    2722         return FALSE;
     2739        return FALSE;
    27232740
    27242741    int t = lex->LookAhead(0);
    27252742    if(t != '=' && t != AssignOp)
    2726         exp = left;
     2743        exp = left;
    27272744    else{
    2728         lex->GetToken(tk);
    2729         if(!rExpression(right))
    2730             return FALSE;
    2731 
    2732         exp = new PtreeAssignExpr(left, Ptree::List(new Leaf(tk), right));
     2745        lex->GetToken(tk);
     2746        if(!rExpression(right))
     2747            return FALSE;
     2748
     2749        exp = new PtreeAssignExpr(left, Ptree::List(new Leaf(tk), right));
    27332750    }
    27342751
     
    27462763
    27472764    if(!rLogicalOrExpr(exp, FALSE))
    2748         return FALSE;
     2765        return FALSE;
    27492766
    27502767    if(lex->LookAhead(0) == '?'){
    2751         lex->GetToken(tk1);
    2752         if(!rCommaExpression(then))
    2753             return FALSE;
    2754 
    2755         if(lex->GetToken(tk2) != ':')
    2756             return FALSE;
    2757 
    2758         if(!rConditionalExpr(otherwise))
    2759             return FALSE;
    2760 
    2761         exp = new PtreeCondExpr(exp, Ptree::List(new Leaf(tk1), then,
    2762                                                 new Leaf(tk2), otherwise));
     2768        lex->GetToken(tk1);
     2769        if(!rCommaExpression(then))
     2770            return FALSE;
     2771
     2772        if(lex->GetToken(tk2) != ':')
     2773            return FALSE;
     2774
     2775        if(!rConditionalExpr(otherwise))
     2776            return FALSE;
     2777
     2778        exp = new PtreeCondExpr(exp, Ptree::List(new Leaf(tk1), then,
     2779                                                new Leaf(tk2), otherwise));
    27632780    }
    27642781
     
    27692786  logical.or.expr
    27702787  : logical.and.expr
    2771   | logical.or.expr LogOrOp logical.and.expr            left-to-right
     2788  | logical.or.expr LogOrOp logical.and.expr            left-to-right
    27722789*/
    27732790bool Parser::rLogicalOrExpr(Ptree*& exp, bool temp_args)
     
    27772794
    27782795    if(!rLogicalAndExpr(exp, temp_args))
    2779         return FALSE;
     2796        return FALSE;
    27802797
    27812798    while(lex->LookAhead(0) == LogOrOp){
    2782         lex->GetToken(tk);
    2783         if(!rLogicalAndExpr(right, temp_args))
    2784             return FALSE;
    2785 
    2786         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2799        lex->GetToken(tk);
     2800        if(!rLogicalAndExpr(right, temp_args))
     2801            return FALSE;
     2802
     2803        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    27872804    }
    27882805
     
    28012818
    28022819    if(!rInclusiveOrExpr(exp, temp_args))
    2803         return FALSE;
     2820        return FALSE;
    28042821
    28052822    while(lex->LookAhead(0) == LogAndOp){
    2806         lex->GetToken(tk);
    2807         if(!rInclusiveOrExpr(right, temp_args))
    2808             return FALSE;
    2809 
    2810         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2823        lex->GetToken(tk);
     2824        if(!rInclusiveOrExpr(right, temp_args))
     2825            return FALSE;
     2826
     2827        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    28112828    }
    28122829
     
    28252842
    28262843    if(!rExclusiveOrExpr(exp, temp_args))
    2827         return FALSE;
     2844        return FALSE;
    28282845
    28292846    while(lex->LookAhead(0) == '|'){
    2830         lex->GetToken(tk);
    2831         if(!rExclusiveOrExpr(right, temp_args))
    2832             return FALSE;
    2833 
    2834         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2847        lex->GetToken(tk);
     2848        if(!rExclusiveOrExpr(right, temp_args))
     2849            return FALSE;
     2850
     2851        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    28352852    }
    28362853
     
    28492866
    28502867    if(!rAndExpr(exp, temp_args))
    2851         return FALSE;
     2868        return FALSE;
    28522869
    28532870    while(lex->LookAhead(0) == '^'){
    2854         lex->GetToken(tk);
    2855         if(!rAndExpr(right, temp_args))
    2856             return FALSE;
    2857 
    2858         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2871        lex->GetToken(tk);
     2872        if(!rAndExpr(right, temp_args))
     2873            return FALSE;
     2874
     2875        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    28592876    }
    28602877
     
    28732890
    28742891    if(!rEqualityExpr(exp, temp_args))
    2875         return FALSE;
     2892        return FALSE;
    28762893
    28772894    while(lex->LookAhead(0) == '&'){
    2878         lex->GetToken(tk);
    2879         if(!rEqualityExpr(right, temp_args))
    2880             return FALSE;
    2881 
    2882         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2895        lex->GetToken(tk);
     2896        if(!rEqualityExpr(right, temp_args))
     2897            return FALSE;
     2898
     2899        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    28832900    }
    28842901
     
    28972914
    28982915    if(!rRelationalExpr(exp, temp_args))
    2899         return FALSE;
     2916        return FALSE;
    29002917
    29012918    while(lex->LookAhead(0) == EqualOp){
    2902         lex->GetToken(tk);
    2903         if(!rRelationalExpr(right, temp_args))
    2904             return FALSE;
    2905 
    2906         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2919        lex->GetToken(tk);
     2920        if(!rRelationalExpr(right, temp_args))
     2921            return FALSE;
     2922
     2923        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    29072924    }
    29082925
     
    29222939
    29232940    if(!rShiftExpr(exp))
    2924         return FALSE;
     2941        return FALSE;
    29252942
    29262943    while(t = lex->LookAhead(0),
    2927           (t == RelOp || t == '<' || (t == '>' && !temp_args))){
    2928         lex->GetToken(tk);
    2929         if(!rShiftExpr(right))
    2930             return FALSE;
    2931 
    2932         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2944          (t == RelOp || t == '<' || (t == '>' && !temp_args))){
     2945        lex->GetToken(tk);
     2946        if(!rShiftExpr(right))
     2947            return FALSE;
     2948
     2949        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    29332950    }
    29342951
     
    29472964
    29482965    if(!rAdditiveExpr(exp))
    2949         return FALSE;
     2966        return FALSE;
    29502967
    29512968    while(lex->LookAhead(0) == ShiftOp){
    2952         lex->GetToken(tk);
    2953         if(!rAdditiveExpr(right))
    2954             return FALSE;
    2955 
    2956         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2969        lex->GetToken(tk);
     2970        if(!rAdditiveExpr(right))
     2971            return FALSE;
     2972
     2973        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    29572974    }
    29582975
     
    29722989
    29732990    if(!rMultiplyExpr(exp))
    2974         return FALSE;
     2991        return FALSE;
    29752992
    29762993    while(t = lex->LookAhead(0), (t == '+' || t == '-')){
    2977         lex->GetToken(tk);
    2978         if(!rMultiplyExpr(right))
    2979             return FALSE;
    2980 
    2981         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     2994        lex->GetToken(tk);
     2995        if(!rMultiplyExpr(right))
     2996            return FALSE;
     2997
     2998        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    29822999    }
    29833000
     
    29973014
    29983015    if(!rPmExpr(exp))
    2999         return FALSE;
     3016        return FALSE;
    30003017
    30013018    while(t = lex->LookAhead(0), (t == '*' || t == '/' || t == '%')){
    3002         lex->GetToken(tk);
    3003         if(!rPmExpr(right))
    3004             return FALSE;
    3005 
    3006         exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
    3007     }
    3008 
    3009     return TRUE;
    3010 }
    3011 
    3012 /*
    3013   pm.expr       (pointer to member .*, ->*)
     3019        lex->GetToken(tk);
     3020        if(!rPmExpr(right))
     3021            return FALSE;
     3022
     3023        exp = new PtreeInfixExpr(exp, Ptree::List(new Leaf(tk), right));
     3024    }
     3025
     3026    return TRUE;
     3027}
     3028
     3029/*
     3030  pm.expr       (pointer to member .*, ->*)
    30143031  : cast.expr
    30153032  | pm.expr PmOp cast.expr
     
    30213038
    30223039    if(!rCastExpr(exp))
    3023         return FALSE;
     3040        return FALSE;
    30243041
    30253042    while(lex->LookAhead(0) == PmOp){
    3026         lex->GetToken(tk);
    3027         if(!rCastExpr(right))
    3028             return FALSE;
    3029 
    3030         exp = new PtreePmExpr(exp, Ptree::List(new Leaf(tk), right));
     3043        lex->GetToken(tk);
     3044        if(!rCastExpr(right))
     3045            return FALSE;
     3046
     3047        exp = new PtreePmExpr(exp, Ptree::List(new Leaf(tk), right));
    30313048    }
    30323049
     
    30423059{
    30433060    if(lex->LookAhead(0) != '(')
    3044         return rUnaryExpr(exp);
     3061        return rUnaryExpr(exp);
    30453062    else{
    3046         Token tk1, tk2;
    3047         Ptree* tname;
    3048         char* pos = lex->Save();
    3049         lex->GetToken(tk1);
    3050         if(rTypeName(tname))
    3051             if(lex->GetToken(tk2) == ')')
    3052                 if(rCastExpr(exp)){
    3053                     exp = new PtreeCastExpr(new Leaf(tk1),
    3054                                             Ptree::List(tname, new Leaf(tk2),
    3055                                                         exp));
    3056                     return TRUE;
    3057                 }
    3058 
    3059         lex->Restore(pos);
    3060         return rUnaryExpr(exp);
     3063        Token tk1, tk2;
     3064        Ptree* tname;
     3065        char* pos = lex->Save();
     3066        lex->GetToken(tk1);
     3067        if(rTypeName(tname))
     3068            if(lex->GetToken(tk2) == ')')
     3069                if(rCastExpr(exp)){
     3070                    exp = new PtreeCastExpr(new Leaf(tk1),
     3071                                            Ptree::List(tname, new Leaf(tk2),
     3072                                                        exp));
     3073                    return TRUE;
     3074                }
     3075
     3076        lex->Restore(pos);
     3077        return rUnaryExpr(exp);
    30613078    }
    30623079}
     
    30783095
    30793096    if(!rTypeSpecifier(type_name, TRUE, type_encode))
    3080         return FALSE;
     3097        return FALSE;
    30813098
    30823099    if(!rDeclarator(arg, kCastDeclarator, FALSE, type_encode, name_encode,
    3083                     FALSE))
    3084         return FALSE;
     3100                    FALSE))
     3101        return FALSE;
    30853102
    30863103    tname = Ptree::List(type_name, arg);
     
    31013118    if(t == '*' || t == '&' || t == '+' || t == '-' || t == '!'
    31023119       || t == '~' || t == IncOp){
    3103         Token tk;
    3104         Ptree* right;
    3105 
    3106         lex->GetToken(tk);
    3107         if(!rCastExpr(right))
    3108             return FALSE;
    3109 
    3110         exp = new PtreeUnaryExpr(new Leaf(tk), Ptree::List(right));
    3111         return TRUE;
     3120        Token tk;
     3121        Ptree* right;
     3122
     3123        lex->GetToken(tk);
     3124        if(!rCastExpr(right))
     3125            return FALSE;
     3126
     3127        exp = new PtreeUnaryExpr(new Leaf(tk), Ptree::List(right));
     3128        return TRUE;
    31123129    }
    31133130    else if(t == SIZEOF)
    3114         return rSizeofExpr(exp);
     3131        return rSizeofExpr(exp);
    31153132    else if(t == THROW)
    3116         return rThrowExpr(exp);
     3133        return rThrowExpr(exp);
    31173134    else if(isAllocateExpr(t))
    3118         return rAllocateExpr(exp);
     3135        return rAllocateExpr(exp);
    31193136    else
    3120         return rPostfixExpr(exp);
     3137        return rPostfixExpr(exp);
    31213138}
    31223139
     
    31313148
    31323149    if(lex->GetToken(tk) != THROW)
    3133         return FALSE;
     3150        return FALSE;
    31343151
    31353152    int t = lex->LookAhead(0);
    31363153    if(t == ':' || t == ';')
    3137         e = nil;
     3154        e = nil;
    31383155    else
    3139         if(!rExpression(e))
    3140             return FALSE;
     3156        if(!rExpression(e))
     3157            return FALSE;
    31413158
    31423159    exp = new PtreeThrowExpr(new LeafReserved(tk), Ptree::List(e));
     
    31553172
    31563173    if(lex->GetToken(tk) != SIZEOF)
    3157         return FALSE;
     3174        return FALSE;
    31583175
    31593176    if(lex->LookAhead(0) == '('){
    3160         Ptree* tname;
    3161         Token op, cp;
    3162 
    3163         char* pos = lex->Save();
    3164         lex->GetToken(op);
    3165         if(rTypeName(tname))
    3166             if(lex->GetToken(cp) == ')'){
    3167                 exp = new PtreeSizeofExpr(new Leaf(tk),
    3168                                           Ptree::List(new Leaf(op), tname,
    3169                                                       new Leaf(cp)));
    3170                 return TRUE;
    3171             }
    3172 
    3173         lex->Restore(pos);
     3177        Ptree* tname;
     3178        Token op, cp;
     3179
     3180        char* pos = lex->Save();
     3181        lex->GetToken(op);
     3182        if(rTypeName(tname))
     3183            if(lex->GetToken(cp) == ')'){
     3184                exp = new PtreeSizeofExpr(new Leaf(tk),
     3185                                          Ptree::List(new Leaf(op), tname,
     3186                                                      new Leaf(cp)));
     3187                return TRUE;
     3188            }
     3189
     3190        lex->Restore(pos);
    31743191    }
    31753192
    31763193    if(!rUnaryExpr(unary))
    3177         return FALSE;
     3194        return FALSE;
    31783195
    31793196    exp = new PtreeSizeofExpr(new Leaf(tk), Ptree::List(unary));
     
    31843201{
    31853202    if(t == UserKeyword)
    3186         return TRUE;
     3203        return TRUE;
    31873204    else{
    3188         if(t == Scope)
    3189             t = lex->LookAhead(1);
    3190 
    3191         if(t == NEW || t == DELETE)
    3192             return TRUE;
    3193         else
    3194             return FALSE;
     3205        if(t == Scope)
     3206            t = lex->LookAhead(1);
     3207
     3208        if(t == NEW || t == DELETE)
     3209            return TRUE;
     3210        else
     3211            return FALSE;
    31953212    }
    31963213}
     
    32093226    int t = lex->LookAhead(0);
    32103227    if(t == Scope){
    3211         lex->GetToken(tk);
    3212         head = new Leaf(tk);
     3228        lex->GetToken(tk);
     3229        head = new Leaf(tk);
    32133230    }
    32143231    else if(t == UserKeyword){
    3215         if(!rUserdefKeyword(head))
    3216             return FALSE;
    3217 
    3218         ukey = TRUE;
     3232        if(!rUserdefKeyword(head))
     3233            return FALSE;
     3234
     3235        ukey = TRUE;
    32193236    }
    32203237
    32213238    t = lex->GetToken(tk);
    32223239    if(t == DELETE){
    3223         Ptree* obj;
    3224         if(ukey)
    3225             return FALSE;
    3226 
    3227         if(head == nil)
    3228             exp = new PtreeDeleteExpr(new LeafReserved(tk), nil);
    3229         else
    3230             exp = new PtreeDeleteExpr(head,
    3231                                       Ptree::List(new LeafReserved(tk)));
    3232 
    3233         if(lex->LookAhead(0) == '['){
    3234             lex->GetToken(tk);
    3235             exp = Ptree::Snoc(exp, new Leaf(tk));
    3236             if(lex->GetToken(tk) != ']')
    3237                 return FALSE;
    3238 
    3239             exp = Ptree::Snoc(exp, new Leaf(tk));
    3240         }
    3241 
    3242         if(!rCastExpr(obj))
    3243             return FALSE;
    3244 
    3245         exp = Ptree::Snoc(exp, obj);
    3246         return TRUE;
     3240        Ptree* obj;
     3241        if(ukey)
     3242            return FALSE;
     3243
     3244        if(head == nil)
     3245            exp = new PtreeDeleteExpr(new LeafReserved(tk), nil);
     3246        else
     3247            exp = new PtreeDeleteExpr(head,
     3248                                      Ptree::List(new LeafReserved(tk)));
     3249
     3250        if(lex->LookAhead(0) == '['){
     3251            lex->GetToken(tk);
     3252            exp = Ptree::Snoc(exp, new Leaf(tk));
     3253            if(lex->GetToken(tk) != ']')
     3254                return FALSE;
     3255
     3256            exp = Ptree::Snoc(exp, new Leaf(tk));
     3257        }
     3258
     3259        if(!rCastExpr(obj))
     3260            return FALSE;
     3261
     3262        exp = Ptree::Snoc(exp, obj);
     3263        return TRUE;
    32473264    }
    32483265    else if(t == NEW){
    3249         Ptree *atype;
    3250         if(head == nil)
    3251             exp = new PtreeNewExpr(new LeafReserved(tk), nil);
    3252         else
    3253             exp = new PtreeNewExpr(head, Ptree::List(new LeafReserved(tk)));
    3254 
    3255         if(!rAllocateType(atype))
    3256             return FALSE;
    3257 
    3258         exp = Ptree::Nconc(exp, atype);
    3259         return TRUE;
     3266        Ptree *atype;
     3267        if(head == nil)
     3268            exp = new PtreeNewExpr(new LeafReserved(tk), nil);
     3269        else
     3270            exp = new PtreeNewExpr(head, Ptree::List(new LeafReserved(tk)));
     3271
     3272        if(!rAllocateType(atype))
     3273            return FALSE;
     3274
     3275        exp = Ptree::Nconc(exp, atype);
     3276        return TRUE;
    32603277    }
    32613278    else
    3262         return FALSE;
     3279        return FALSE;
    32633280}
    32643281
     
    32733290    int t = lex->GetToken(tk);
    32743291    if(t != UserKeyword && t != UserKeyword5)
    3275         return FALSE;
     3292        return FALSE;
    32763293
    32773294    if(lex->LookAhead(0) != '(')
    3278         ukey = new PtreeUserdefKeyword(new Leaf(tk), nil);
     3295        ukey = new PtreeUserdefKeyword(new Leaf(tk), nil);
    32793296    else{
    3280         Ptree* args;
    3281         Token op, cp;
    3282         lex->GetToken(op);
    3283         if(!rFunctionArguments(args))
    3284             return FALSE;
    3285 
    3286         if(lex->GetToken(cp) != ')')
    3287             return FALSE;
    3288 
    3289         ukey = new PtreeUserdefKeyword(new Leaf(tk),
    3290                         Ptree::List(new Leaf(op), args, new Leaf(cp)));
     3297        Ptree* args;
     3298        Token op, cp;
     3299        lex->GetToken(op);
     3300        if(!rFunctionArguments(args))
     3301            return FALSE;
     3302
     3303        if(lex->GetToken(cp) != ')')
     3304            return FALSE;
     3305
     3306        ukey = new PtreeUserdefKeyword(new Leaf(tk),
     3307                        Ptree::List(new Leaf(op), args, new Leaf(cp)));
    32913308    }
    32923309
     
    33063323
    33073324    if(lex->LookAhead(0) != '(')
    3308         atype = Ptree::List(nil);
     3325        atype = Ptree::List(nil);
    33093326    else{
    3310         lex->GetToken(op);
    3311 
    3312         char* pos = lex->Save();
    3313         if(rTypeName(tname))
    3314             if(lex->GetToken(cp) == ')')
    3315                 if(lex->LookAhead(0) != '('){
    3316                     atype = Ptree::List(nil, Ptree::List(new Leaf(op), tname,
    3317                                                         new Leaf(cp)));
    3318                     if(!isTypeSpecifier())
    3319                         return TRUE;
    3320                 }
    3321                 else if(rAllocateInitializer(init)){
    3322                     atype = Ptree::List(nil,
    3323                                         Ptree::List(new Leaf(op), tname,
    3324                                                     new Leaf(cp)),
    3325                                         init);
    3326                     // the next token cannot be '('
    3327                     if(lex->LookAhead(0) != '(')
    3328                         return TRUE;
    3329                 }
    3330 
    3331         // if we reach here, we have to process '(' function.arguments ')'.
    3332         lex->Restore(pos);
    3333         if(!rFunctionArguments(exp))
    3334             return FALSE;
    3335 
    3336         if(lex->GetToken(cp) != ')')
    3337             return FALSE;
    3338 
    3339         atype = Ptree::List(Ptree::List(new Leaf(op), exp, new Leaf(cp)));
     3327        lex->GetToken(op);
     3328
     3329        char* pos = lex->Save();
     3330        if(rTypeName(tname))
     3331            if(lex->GetToken(cp) == ')')
     3332                if(lex->LookAhead(0) != '('){
     3333                    atype = Ptree::List(nil, Ptree::List(new Leaf(op), tname,
     3334                                                        new Leaf(cp)));
     3335                    if(!isTypeSpecifier())
     3336                        return TRUE;
     3337                }
     3338                else if(rAllocateInitializer(init)){
     3339                    atype = Ptree::List(nil,
     3340                                        Ptree::List(new Leaf(op), tname,
     3341                                                    new Leaf(cp)),
     3342                                        init);
     3343                    // the next token cannot be '('
     3344                    if(lex->LookAhead(0) != '(')
     3345                        return TRUE;
     3346                }
     3347
     3348        // if we reach here, we have to process '(' function.arguments ')'.
     3349        lex->Restore(pos);
     3350        if(!rFunctionArguments(exp))
     3351            return FALSE;
     3352
     3353        if(lex->GetToken(cp) != ')')
     3354            return FALSE;
     3355
     3356        atype = Ptree::List(Ptree::List(new Leaf(op), exp, new Leaf(cp)));
    33403357    }
    33413358
    33423359    if(lex->LookAhead(0) == '('){
    3343         lex->GetToken(op);
    3344         if(!rTypeName(tname))
    3345             return FALSE;
    3346 
    3347         if(lex->GetToken(cp) != ')')
    3348             return FALSE;
    3349 
    3350         atype = Ptree::Snoc(atype, Ptree::List(new Leaf(op), tname,
    3351                                                new Leaf(cp)));
     3360        lex->GetToken(op);
     3361        if(!rTypeName(tname))
     3362            return FALSE;
     3363
     3364        if(lex->GetToken(cp) != ')')
     3365            return FALSE;
     3366
     3367        atype = Ptree::Snoc(atype, Ptree::List(new Leaf(op), tname,
     3368                                               new Leaf(cp)));
    33523369    }
    33533370    else{
    3354         Ptree* decl;
    3355         Encoding type_encode;
    3356         if(!rTypeSpecifier(tname, FALSE, type_encode))
    3357             return FALSE;
    3358 
    3359         if(!rNewDeclarator(decl, type_encode))
    3360             return FALSE;
    3361 
    3362         atype = Ptree::Snoc(atype, Ptree::List(tname, decl));
     3371        Ptree* decl;
     3372        Encoding type_encode;
     3373        if(!rTypeSpecifier(tname, FALSE, type_encode))
     3374            return FALSE;
     3375
     3376        if(!rNewDeclarator(decl, type_encode))
     3377            return FALSE;
     3378
     3379        atype = Ptree::Snoc(atype, Ptree::List(tname, decl));
    33633380    }
    33643381
    33653382    if(lex->LookAhead(0) == '('){
    3366         if(!rAllocateInitializer(init))
    3367             return FALSE;
    3368 
    3369         atype = Ptree::Snoc(atype, init);
     3383        if(!rAllocateInitializer(init))
     3384            return FALSE;
     3385
     3386        atype = Ptree::Snoc(atype, init);
    33703387    }
    33713388
     
    33833400    decl = nil;
    33843401    if(lex->LookAhead(0) != '[')
    3385         if(!optPtrOperator(decl, encode))
    3386             return FALSE;
     3402        if(!optPtrOperator(decl, encode))
     3403            return FALSE;
    33873404
    33883405    while(lex->LookAhead(0) == '['){
    3389         Token ob, cb;
    3390         Ptree* exp;
    3391         lex->GetToken(ob);
    3392         if(!rCommaExpression(exp))
    3393             return FALSE;
    3394 
    3395         if(lex->GetToken(cb) != ']')
    3396             return FALSE;
    3397 
    3398         encode.Array();
    3399         decl = Ptree::Nconc(decl, Ptree::List(new Leaf(ob), exp,
    3400                                               new Leaf(cb)));
     3406        Token ob, cb;
     3407        Ptree* exp;
     3408        lex->GetToken(ob);
     3409        if(!rCommaExpression(exp))
     3410            return FALSE;
     3411
     3412        if(lex->GetToken(cb) != ']')
     3413            return FALSE;
     3414
     3415        encode.Array();
     3416        decl = Ptree::Nconc(decl, Ptree::List(new Leaf(ob), exp,
     3417                                              new Leaf(cb)));
    34013418    }
    34023419
    34033420    if(decl == nil)
    3404         decl = new PtreeDeclarator(encode);
     3421        decl = new PtreeDeclarator(encode);
    34053422    else
    3406         decl = new PtreeDeclarator(decl, encode);
     3423        decl = new PtreeDeclarator(decl, encode);
    34073424
    34083425    return TRUE;
     
    34183435
    34193436    if(lex->GetToken(op) != '(')
    3420         return FALSE;
     3437        return FALSE;
    34213438
    34223439    if(lex->LookAhead(0) == ')'){
    3423         lex->GetToken(cp);
    3424         init = Ptree::List(new Leaf(op), nil, new Leaf(cp));
    3425         return TRUE;
     3440        lex->GetToken(cp);
     3441        init = Ptree::List(new Leaf(op), nil, new Leaf(cp));
     3442        return TRUE;
    34263443    }
    34273444
    34283445    init = nil;
    34293446    for(;;){
    3430         Ptree* exp;
    3431         if(!rInitializeExpr(exp))
    3432             return FALSE;
    3433 
    3434         init = Ptree::Snoc(init, exp);
    3435         if(lex->LookAhead(0) != ',')
    3436             break;
    3437         else{
    3438             Token tk;
    3439             lex->GetToken(tk);
    3440             init = Ptree::Snoc(init, new Leaf(tk));
    3441         }
     3447        Ptree* exp;
     3448        if(!rInitializeExpr(exp))
     3449            return FALSE;
     3450
     3451        init = Ptree::Snoc(init, exp);
     3452        if(lex->LookAhead(0) != ',')
     3453            break;
     3454        else{
     3455            Token tk;
     3456            lex->GetToken(tk);
     3457            init = Ptree::Snoc(init, new Leaf(tk));
     3458        }
    34423459    }
    34433460
     
    34703487
    34713488    if(!rPrimaryExpr(exp))
    3472         return FALSE;
     3489        return FALSE;
    34733490
    34743491    for(;;){
    3475         switch(lex->LookAhead(0)){
    3476         case '[' :
    3477             lex->GetToken(op);
    3478             if(!rCommaExpression(e))
    3479                 return FALSE;
    3480 
    3481             if(lex->GetToken(cp) != ']')
    3482                 return FALSE;
    3483 
    3484             exp = new PtreeArrayExpr(exp, Ptree::List(new Leaf(op),
    3485                                                       e, new Leaf(cp)));
    3486             break;
    3487         case '(' :
    3488             lex->GetToken(op);
    3489             if(!rFunctionArguments(e))
    3490                 return FALSE;
    3491 
    3492             if(lex->GetToken(cp) != ')')
    3493                 return FALSE;
    3494 
    3495             exp = new PtreeFuncallExpr(exp, Ptree::List(new Leaf(op),
    3496                                                         e, new Leaf(cp)));
    3497             break;
    3498         case IncOp :
    3499             lex->GetToken(op);
    3500             exp = new PtreePostfixExpr(exp, Ptree::List(new Leaf(op)));
    3501             break;
    3502         case '.' :
    3503         case ArrowOp :
    3504             t2 = lex->GetToken(op);
    3505             t = lex->LookAhead(0);
    3506             if(t == UserKeyword || t == UserKeyword2 || t == UserKeyword3){
    3507                 if(!rUserdefStatement(e))
    3508                     return FALSE;
    3509 
    3510                 exp = new PtreeUserStatementExpr(exp,
    3511                                                 Ptree::Cons(new Leaf(op), e));
    3512                 break;
    3513             }
    3514             else{
    3515                 if(!rVarName(e))
    3516                     return FALSE;
    3517 
    3518                 if(t2 == '.')
    3519                     exp = new PtreeDotMemberExpr(exp,
    3520                                                 Ptree::List(new Leaf(op), e));
    3521                 else
    3522                     exp = new PtreeArrowMemberExpr(exp,
    3523                                                 Ptree::List(new Leaf(op), e));
    3524                 break;
    3525             }
    3526         default :
    3527             return TRUE;
    3528         }
     3492        switch(lex->LookAhead(0)){
     3493        case '[' :
     3494            lex->GetToken(op);
     3495            if(!rCommaExpression(e))
     3496                return FALSE;
     3497
     3498            if(lex->GetToken(cp) != ']')
     3499                return FALSE;
     3500
     3501            exp = new PtreeArrayExpr(exp, Ptree::List(new Leaf(op),
     3502                                                      e, new Leaf(cp)));
     3503            break;
     3504        case '(' :
     3505            lex->GetToken(op);
     3506            if(!rFunctionArguments(e))
     3507                return FALSE;
     3508
     3509            if(lex->GetToken(cp) != ')')
     3510                return FALSE;
     3511
     3512            exp = new PtreeFuncallExpr(exp, Ptree::List(new Leaf(op),
     3513                                                        e, new Leaf(cp)));
     3514            break;
     3515        case IncOp :
     3516            lex->GetToken(op);
     3517            exp = new PtreePostfixExpr(exp, Ptree::List(new Leaf(op)));
     3518            break;
     3519        case '.' :
     3520        case ArrowOp :
     3521            t2 = lex->GetToken(op);
     3522            t = lex->LookAhead(0);
     3523            if(t == UserKeyword || t == UserKeyword2 || t == UserKeyword3){
     3524                if(!rUserdefStatement(e))
     3525                    return FALSE;
     3526
     3527                exp = new PtreeUserStatementExpr(exp,
     3528                                                Ptree::Cons(new Leaf(op), e));
     3529                break;
     3530            }
     3531            else{
     3532                if(!rVarName(e))
     3533                    return FALSE;
     3534
     3535                if(t2 == '.')
     3536                    exp = new PtreeDotMemberExpr(exp,
     3537                                                Ptree::List(new Leaf(op), e));
     3538                else
     3539                    exp = new PtreeArrowMemberExpr(exp,
     3540                                                Ptree::List(new Leaf(op), e));
     3541                break;
     3542            }
     3543        default :
     3544            return TRUE;
     3545        }
    35293546    }
    35303547}
     
    35523569    switch(lex->LookAhead(0)){
    35533570    case Constant : case CharConst : case StringL :
    3554         lex->GetToken(tk);
    3555         exp = new Leaf(tk);
    3556         return TRUE;
     3571        lex->GetToken(tk);
     3572        exp = new Leaf(tk);
     3573        return TRUE;
    35573574    case THIS :
    3558         lex->GetToken(tk);
    3559         exp = new LeafThis(tk);
    3560         return TRUE;
     3575        lex->GetToken(tk);
     3576        exp = new LeafThis(tk);
     3577        return TRUE;
    35613578    case '(' :
    3562         lex->GetToken(tk);
    3563         if(!rCommaExpression(exp2))
    3564             return FALSE;
    3565 
    3566         if(lex->GetToken(tk2) != ')')
    3567             return FALSE;
    3568 
    3569         exp = new PtreeParenExpr(new Leaf(tk),
    3570                                 Ptree::List(exp2, new Leaf(tk2)));
    3571         return TRUE;
     3579        lex->GetToken(tk);
     3580        if(!rCommaExpression(exp2))
     3581            return FALSE;
     3582
     3583        if(lex->GetToken(tk2) != ')')
     3584            return FALSE;
     3585
     3586        exp = new PtreeParenExpr(new Leaf(tk),
     3587                                Ptree::List(exp2, new Leaf(tk2)));
     3588        return TRUE;
    35723589    default :
    3573         if(!optIntegralTypeOrClassSpec(exp, cast_type_encode))
    3574             return FALSE;
    3575 
    3576         if(exp != nil){         // if integral.or.class.spec
    3577             if(lex->GetToken(tk) != '(')
    3578                 return FALSE;
    3579 
    3580             if(!rFunctionArguments(exp2))
    3581                 return FALSE;
    3582 
    3583             if(lex->GetToken(tk2) != ')')
    3584                 return FALSE;
    3585 
    3586             exp = new PtreeFstyleCastExpr(cast_type_encode, exp,
    3587                                           Ptree::List(new Leaf(tk), exp2,
    3588                                                       new Leaf(tk2)));
    3589             return TRUE;
    3590         }
    3591         else{
    3592             if(!rVarName(exp))
    3593                 return FALSE;
    3594 
    3595             if(lex->LookAhead(0) == Scope){
    3596                 lex->GetToken(tk);
    3597                 if(!rUserdefStatement(exp2))
    3598                     return FALSE;
    3599 
    3600                 exp = new PtreeStaticUserStatementExpr(exp,
    3601                                         Ptree::Cons(new Leaf(tk), exp2));
    3602             }
    3603 
    3604             return TRUE;
    3605         }
     3590        if(!optIntegralTypeOrClassSpec(exp, cast_type_encode))
     3591            return FALSE;
     3592
     3593        if(exp != nil){         // if integral.or.class.spec
     3594            if(lex->GetToken(tk) != '(')
     3595                return FALSE;
     3596
     3597            if(!rFunctionArguments(exp2))
     3598                return FALSE;
     3599
     3600            if(lex->GetToken(tk2) != ')')
     3601                return FALSE;
     3602
     3603            exp = new PtreeFstyleCastExpr(cast_type_encode, exp,
     3604                                          Ptree::List(new Leaf(tk), exp2,
     3605                                                      new Leaf(tk2)));
     3606            return TRUE;
     3607        }
     3608        else{
     3609            if(!rVarName(exp))
     3610                return FALSE;
     3611
     3612            if(lex->LookAhead(0) == Scope){
     3613                lex->GetToken(tk);
     3614                if(!rUserdefStatement(exp2))
     3615                    return FALSE;
     3616
     3617                exp = new PtreeStaticUserStatementExpr(exp,
     3618                                        Ptree::Cons(new Leaf(tk), exp2));
     3619            }
     3620
     3621            return TRUE;
     3622        }
    36063623    }
    36073624}
     
    36123629  | UserKeyword2 '(' arg.decl.list ')' compound.statement
    36133630  | UserKeyword3 '(' expr.statement {comma.expression} ';'
    3614                         {comma.expression} ')' compound.statement
     3631                        {comma.expression} ')' compound.statement
    36153632*/
    36163633bool Parser::rUserdefStatement(Ptree*& st)
     
    36223639    int t = lex->GetToken(tk);
    36233640    if(lex->GetToken(tk2) != '(')
    3624         return FALSE;
     3641        return FALSE;
    36253642
    36263643    switch(t){
    36273644    case UserKeyword :
    3628         keyword = new LeafReserved(tk);
    3629         if(!rFunctionArguments(exp))
    3630             return FALSE;
    3631         goto rest;
     3645        keyword = new LeafReserved(tk);
     3646        if(!rFunctionArguments(exp))
     3647            return FALSE;
     3648        goto rest;
    36323649    case UserKeyword2 :
    3633         keyword = new LeafUserKeyword2(tk);
    3634         if(!rArgDeclList(exp, dummy_encode))
    3635             return FALSE;
     3650        keyword = new LeafUserKeyword2(tk);
     3651        if(!rArgDeclList(exp, dummy_encode))
     3652            return FALSE;
    36363653    rest:
    3637         if(lex->GetToken(tk3) != ')')
    3638             return FALSE;
    3639 
    3640         if(!rCompoundStatement(body))
    3641             return FALSE;
    3642 
    3643         st = Ptree::List(keyword, new Leaf(tk2), exp, new Leaf(tk3),
    3644                         body);
    3645         return TRUE;
     3654        if(lex->GetToken(tk3) != ')')
     3655            return FALSE;
     3656
     3657        if(!rCompoundStatement(body))
     3658            return FALSE;
     3659
     3660        st = Ptree::List(keyword, new Leaf(tk2), exp, new Leaf(tk3),
     3661                        body);
     3662        return TRUE;
    36463663    case UserKeyword3 :
    3647         if(!rExprStatement(exp))
    3648             return FALSE;
    3649 
    3650         if(lex->LookAhead(0) == ';')
    3651             exp2 = nil;
    3652         else
    3653             if(!rCommaExpression(exp2))
    3654                 return FALSE;
    3655 
    3656         if(lex->GetToken(tk3) != ';')
    3657             return FALSE;
    3658 
    3659         if(lex->LookAhead(0) == ')')
    3660             exp3 = nil;
    3661         else
    3662             if(!rCommaExpression(exp3))
    3663                 return FALSE;
    3664 
    3665         if(lex->GetToken(tk4) != ')')
    3666             return FALSE;
    3667 
    3668         if(!rCompoundStatement(body))
    3669             return FALSE;
    3670 
    3671         st = Ptree::List(new Leaf(tk), new Leaf(tk2), exp, exp2,
    3672                         new Leaf(tk3), exp3, new Leaf(tk4), body);
    3673         return TRUE;
     3664        if(!rExprStatement(exp))
     3665            return FALSE;
     3666
     3667        if(lex->LookAhead(0) == ';')
     3668            exp2 = nil;
     3669        else
     3670            if(!rCommaExpression(exp2))
     3671                return FALSE;
     3672
     3673        if(lex->GetToken(tk3) != ';')
     3674            return FALSE;
     3675
     3676        if(lex->LookAhead(0) == ')')
     3677            exp3 = nil;
     3678        else
     3679            if(!rCommaExpression(exp3))
     3680                return FALSE;
     3681
     3682        if(lex->GetToken(tk4) != ')')
     3683            return FALSE;
     3684
     3685        if(!rCompoundStatement(body))
     3686            return FALSE;
     3687
     3688        st = Ptree::List(new Leaf(tk), new Leaf(tk2), exp, exp2,
     3689                        new Leaf(tk3), exp3, new Leaf(tk4), body);
     3690        return TRUE;
    36743691    default :
    3675         return FALSE;
     3692        return FALSE;
    36763693    }
    36773694}
     
    36923709
    36933710    if(rVarNameCore(name, encode)){
    3694         if(!name->IsLeaf())
    3695             name = new PtreeName(name, encode);
    3696 
    3697         return TRUE;
     3711        if(!name->IsLeaf())
     3712            name = new PtreeName(name, encode);
     3713
     3714        return TRUE;
    36983715    }
    36993716    else
    3700         return FALSE;
     3717        return FALSE;
    37013718}
    37023719
     
    37073724
    37083725    if(lex->LookAhead(0) == Scope){
    3709         lex->GetToken(tk);
    3710         name = Ptree::List(new Leaf(tk));
    3711         encode.GlobalScope();
    3712         ++length;
     3726        lex->GetToken(tk);
     3727        name = Ptree::List(new Leaf(tk));
     3728        encode.GlobalScope();
     3729        ++length;
    37133730    }
    37143731    else
    3715         name = nil;
     3732        name = nil;
    37163733
    37173734    for(;;){
    3718         int t = lex->GetToken(tk);
    3719         if(t == Identifier){
    3720             Ptree* n = new LeafName(tk);
    3721             if(isTemplateArgs()){
    3722                 Ptree* args;
    3723                 Encoding args_encode;
    3724                 if(!rTemplateArgs(args, args_encode))
    3725                     return FALSE;
    3726 
    3727                 encode.Template(n, args_encode);
    3728                 ++length;
    3729                 n = Ptree::List(n, args);
    3730             }
    3731             else{
    3732                 encode.SimpleName(n);
    3733                 ++length;
    3734             }
    3735 
    3736             if(moreVarName()){
    3737                 lex->GetToken(tk);
    3738                 name = Ptree::Nconc(name, Ptree::List(n, new Leaf(tk)));
    3739             }
    3740             else{
    3741                 if(name == nil)
    3742                     name = n;
    3743                 else
    3744                     name = Ptree::Snoc(name, n);
    3745 
    3746                 if(length > 1)
    3747                     encode.Qualified(length);
    3748 
    3749                 return TRUE;
    3750             }
    3751         }
    3752         else if(t == '~'){
    3753             Token tk2;
    3754             if(lex->LookAhead(0) != Identifier)
    3755                 return FALSE;
    3756 
    3757             lex->GetToken(tk2);
    3758             Ptree* class_name = new Leaf(tk2);
    3759             Ptree* dt = Ptree::List(new Leaf(tk), class_name);
    3760             if(name == nil)
    3761                 name = dt;
    3762             else
    3763                 name = Ptree::Snoc(name, dt);
    3764 
    3765             encode.Destructor(class_name);
    3766             if(length > 0)
    3767                 encode.Qualified(length + 1);
    3768 
    3769             return TRUE;
    3770         }
    3771         else if(t == OPERATOR){
    3772             Ptree* op;
    3773             if(!rOperatorName(op, encode))
    3774                 return FALSE;
    3775 
    3776             Ptree* opf = Ptree::List(new LeafReserved(tk), op);
    3777             if(name == nil)
    3778                 name = opf;
    3779             else
    3780                 name = Ptree::Snoc(name, opf);
    3781 
    3782             if(length > 0)
    3783                 encode.Qualified(length + 1);
    3784 
    3785             return TRUE;
    3786         }
    3787         else
    3788             return FALSE;
     3735        int t = lex->GetToken(tk);
     3736        if(t == Identifier){
     3737            Ptree* n = new LeafName(tk);
     3738            if(isTemplateArgs()){
     3739                Ptree* args;
     3740                Encoding args_encode;
     3741                if(!rTemplateArgs(args, args_encode))
     3742                    return FALSE;
     3743
     3744                encode.Template(n, args_encode);
     3745                ++length;
     3746                n = Ptree::List(n, args);
     3747            }
     3748            else{
     3749                encode.SimpleName(n);
     3750                ++length;
     3751            }
     3752
     3753            if(moreVarName()){
     3754                lex->GetToken(tk);
     3755                name = Ptree::Nconc(name, Ptree::List(n, new Leaf(tk)));
     3756            }
     3757            else{
     3758                if(name == nil)
     3759                    name = n;
     3760                else
     3761                    name = Ptree::Snoc(name, n);
     3762
     3763                if(length > 1)
     3764                    encode.Qualified(length);
     3765
     3766                return TRUE;
     3767            }
     3768        }
     3769        else if(t == '~'){
     3770            Token tk2;
     3771            if(lex->LookAhead(0) != Identifier)
     3772                return FALSE;
     3773
     3774            lex->GetToken(tk2);
     3775            Ptree* class_name = new Leaf(tk2);
     3776            Ptree* dt = Ptree::List(new Leaf(tk), class_name);
     3777            if(name == nil)
     3778                name = dt;
     3779            else
     3780                name = Ptree::Snoc(name, dt);
     3781
     3782            encode.Destructor(class_name);
     3783            if(length > 0)
     3784                encode.Qualified(length + 1);
     3785
     3786            return TRUE;
     3787        }
     3788        else if(t == OPERATOR){
     3789            Ptree* op;
     3790            if(!rOperatorName(op, encode))
     3791                return FALSE;
     3792
     3793            Ptree* opf = Ptree::List(new LeafReserved(tk), op);
     3794            if(name == nil)
     3795                name = opf;
     3796            else
     3797                name = Ptree::Snoc(name, opf);
     3798
     3799            if(length > 0)
     3800                encode.Qualified(length + 1);
     3801
     3802            return TRUE;
     3803        }
     3804        else
     3805            return FALSE;
    37893806    }
    37903807}
     
    37933810{
    37943811    if(lex->LookAhead(0) == Scope){
    3795         int t = lex->LookAhead(1);
    3796         if(t == Identifier || t == '~' || t == OPERATOR)
    3797             return TRUE;
     3812        int t = lex->LookAhead(1);
     3813        if(t == Identifier || t == '~' || t == OPERATOR)
     3814            return TRUE;
    37983815    }
    37993816
     
    38113828    int t = lex->LookAhead(i++);
    38123829    if(t == '<'){
    3813         int n = 1;
    3814         while(n > 0){
    3815             int u = lex->LookAhead(i++);
    3816             if(u == '<')
    3817                 ++n;
    3818             else if(u == '>')
    3819                 --n;
    3820             else if(u == '('){
    3821                 int m = 1;
    3822                 while(m > 0){
    3823                     int v = lex->LookAhead(i++);
    3824                     if(v == '(')
    3825                         ++m;
    3826                     else if(v == ')')
    3827                         --m;
    3828                     else if(v == '\0' || v == ';' || v == '}')
    3829                         return FALSE;
    3830                 }
    3831             }
    3832             else if(u == '\0' || u == ';' || u == '}')
    3833                 return FALSE;
    3834         }
    3835 
    3836         t = lex->LookAhead(i);
    3837         return bool(t == Scope || t == '(');
     3830        int n = 1;
     3831        while(n > 0){
     3832            int u = lex->LookAhead(i++);
     3833            if(u == '<')
     3834                ++n;
     3835            else if(u == '>')
     3836                --n;
     3837            else if(u == '('){
     3838                int m = 1;
     3839                while(m > 0){
     3840                    int v = lex->LookAhead(i++);
     3841                    if(v == '(')
     3842                        ++m;
     3843                    else if(v == ')')
     3844                        --m;
     3845                    else if(v == '\0' || v == ';' || v == '}')
     3846                        return FALSE;
     3847                }
     3848            }
     3849            else if(u == '\0' || u == ';' || u == '}')
     3850                return FALSE;
     3851        }
     3852
     3853        t = lex->LookAhead(i);
     3854        return bool(t == Scope || t == '(');
    38383855    }
    38393856
     
    38583875
    38593876    if(lex->GetToken(ob) != '{')
    3860         return FALSE;
     3877        return FALSE;
    38613878
    38623879    Ptree* sts = nil;
    38633880    while(lex->LookAhead(0) != '}'){
    3864         Ptree* st;
    3865         if(!rStatement(st)){
    3866             if(!SyntaxError())
    3867                 return FALSE;   // too many errors
    3868 
    3869             SkipTo('}');
    3870             lex->GetToken(cb);
    3871             body = Ptree::List(new Leaf(ob), nil, new Leaf(cb));
    3872             return TRUE;        // error recovery
    3873         }
    3874 
    3875         lex->GetComments();
    3876         sts = Ptree::Snoc(sts, st);
     3881        Ptree* st;
     3882        if(!rStatement(st)){
     3883            if(!SyntaxError())
     3884                return FALSE;   // too many errors
     3885
     3886            SkipTo('}');
     3887            lex->GetToken(cb);
     3888            body = Ptree::List(new Leaf(ob), nil, new Leaf(cb));
     3889            return TRUE;        // error recovery
     3890        }
     3891
     3892        lex->GetComments();
     3893        sts = Ptree::Snoc(sts, st);
    38773894    }
    38783895
    38793896    if(lex->GetToken(cb) != '}')
    3880         return FALSE;
     3897        return FALSE;
    38813898
    38823899    body = new PtreeBlock(new Leaf(ob), sts, new Leaf(cb));
     
    39113928    switch(k = lex->LookAhead(0)){
    39123929    case '{' :
    3913         return rCompoundStatement(st);
     3930        return rCompoundStatement(st);
    39143931    case TYPEDEF :
    3915         return rTypedef(st);
     3932        return rTypedef(st);
    39163933    case IF :
    3917         return rIfStatement(st);
     3934        return rIfStatement(st);
    39183935    case SWITCH :
    3919         return rSwitchStatement(st);
     3936        return rSwitchStatement(st);
    39203937    case WHILE :
    3921         return rWhileStatement(st);
     3938        return rWhileStatement(st);
    39223939    case DO :
    3923         return rDoStatement(st);
     3940        return rDoStatement(st);
    39243941    case FOR :
    3925         return rForStatement(st);
     3942        return rForStatement(st);
    39263943    case TRY :
    3927         return rTryStatement(st);
     3944        return rTryStatement(st);
    39283945    case BREAK :
    39293946    case CONTINUE :
    3930         lex->GetToken(tk1);
    3931         if(lex->GetToken(tk2) != ';')
    3932             return FALSE;
    3933 
    3934         if(k == BREAK)
    3935             st = new PtreeBreakStatement(new LeafReserved(tk1),
    3936                                         Ptree::List(new Leaf(tk2)));
    3937         else
    3938             st = new PtreeContinueStatement(new LeafReserved(tk1),
    3939                                             Ptree::List(new Leaf(tk2)));
    3940         return TRUE;
     3947        lex->GetToken(tk1);
     3948        if(lex->GetToken(tk2) != ';')
     3949            return FALSE;
     3950
     3951        if(k == BREAK)
     3952            st = new PtreeBreakStatement(new LeafReserved(tk1),
     3953                                        Ptree::List(new Leaf(tk2)));
     3954        else
     3955            st = new PtreeContinueStatement(new LeafReserved(tk1),
     3956                                            Ptree::List(new Leaf(tk2)));
     3957        return TRUE;
    39413958    case RETURN :
    3942         lex->GetToken(tk1);
    3943         if(lex->LookAhead(0) == ';'){
    3944             lex->GetToken(tk2);
    3945             st = new PtreeReturnStatement(new LeafReserved(tk1),
    3946                                           Ptree::List(new Leaf(tk2)));
    3947             return TRUE;
    3948         }
    3949         else{
    3950             if(!rCommaExpression(exp))
    3951                 return FALSE;
    3952 
    3953             if(lex->GetToken(tk2) != ';')
    3954                 return FALSE;
    3955 
    3956             st = new PtreeReturnStatement(new LeafReserved(tk1),
    3957                                           Ptree::List(exp, new Leaf(tk2)));
    3958             return TRUE;
    3959         }
     3959        lex->GetToken(tk1);
     3960        if(lex->LookAhead(0) == ';'){
     3961            lex->GetToken(tk2);
     3962            st = new PtreeReturnStatement(new LeafReserved(tk1),
     3963                                          Ptree::List(new Leaf(tk2)));
     3964            return TRUE;
     3965        }
     3966        else{
     3967            if(!rCommaExpression(exp))
     3968                return FALSE;
     3969
     3970            if(lex->GetToken(tk2) != ';')
     3971                return FALSE;
     3972
     3973            st = new PtreeReturnStatement(new LeafReserved(tk1),
     3974                                          Ptree::List(exp, new Leaf(tk2)));
     3975            return TRUE;
     3976        }
    39603977    case GOTO :
    3961         lex->GetToken(tk1);
    3962         if(lex->GetToken(tk2) != Identifier)
    3963             return FALSE;
    3964 
    3965         if(lex->GetToken(tk3) != ';')
    3966             return FALSE;
    3967 
    3968         st = new PtreeGotoStatement(new LeafReserved(tk1),
    3969                                     Ptree::List(new Leaf(tk2), new Leaf(tk3)));
    3970         return TRUE;
     3978        lex->GetToken(tk1);
     3979        if(lex->GetToken(tk2) != Identifier)
     3980            return FALSE;
     3981
     3982        if(lex->GetToken(tk3) != ';')
     3983            return FALSE;
     3984
     3985        st = new PtreeGotoStatement(new LeafReserved(tk1),
     3986                                    Ptree::List(new Leaf(tk2), new Leaf(tk3)));
     3987        return TRUE;
    39713988    case CASE :
    3972         lex->GetToken(tk1);
    3973         if(!rExpression(exp))
    3974             return FALSE;
    3975 
    3976         if(lex->GetToken(tk2) != ':')
    3977             return FALSE;
    3978 
    3979         if(!rStatement(st2))
    3980             return FALSE;
    3981 
    3982         st = new PtreeCaseStatement(new LeafReserved(tk1),
    3983                                     Ptree::List(exp, new Leaf(tk2), st2));
    3984         return TRUE;
     3989        lex->GetToken(tk1);
     3990        if(!rExpression(exp))
     3991            return FALSE;
     3992
     3993        if(lex->GetToken(tk2) != ':')
     3994            return FALSE;
     3995
     3996        if(!rStatement(st2))
     3997            return FALSE;
     3998
     3999        st = new PtreeCaseStatement(new LeafReserved(tk1),
     4000                                    Ptree::List(exp, new Leaf(tk2), st2));
     4001        return TRUE;
    39854002    case DEFAULT :
    3986         lex->GetToken(tk1);
    3987         if(lex->GetToken(tk2) != ':')
    3988             return FALSE;
    3989 
    3990         if(!rStatement(st2))
    3991             return FALSE;
    3992 
    3993         st = new PtreeDefaultStatement(new LeafReserved(tk1),
    3994                                        Ptree::List(new Leaf(tk2), st2));
    3995         return TRUE;
     4003        lex->GetToken(tk1);
     4004        if(lex->GetToken(tk2) != ':')
     4005            return FALSE;
     4006
     4007        if(!rStatement(st2))
     4008            return FALSE;
     4009
     4010        st = new PtreeDefaultStatement(new LeafReserved(tk1),
     4011                                       Ptree::List(new Leaf(tk2), st2));
     4012        return TRUE;
    39964013    case Identifier :
    3997         if(lex->LookAhead(1) == ':'){   // label statement
    3998             lex->GetToken(tk1);
    3999             lex->GetToken(tk2);
    4000             if(!rStatement(st2))
    4001                 return FALSE;
    4002 
    4003             st = new PtreeLabelStatement(new Leaf(tk1),
    4004                                         Ptree::List(new Leaf(tk2), st2));
    4005             return TRUE;
    4006         }
    4007         // don't break here!
     4014        if(lex->LookAhead(1) == ':'){   // label statement
     4015            lex->GetToken(tk1);
     4016            lex->GetToken(tk2);
     4017            if(!rStatement(st2))
     4018                return FALSE;
     4019
     4020            st = new PtreeLabelStatement(new Leaf(tk1),
     4021                                        Ptree::List(new Leaf(tk2), st2));
     4022            return TRUE;
     4023        }
     4024        // don't break here!
    40084025    default :
    4009         return rExprStatement(st);
     4026        return rExprStatement(st);
    40104027    }
    40114028}
     
    40214038
    40224039    if(lex->GetToken(tk1) != IF)
    4023         return FALSE;
     4040        return FALSE;
    40244041
    40254042    if(lex->GetToken(tk2) != '(')
    4026         return FALSE;
     4043        return FALSE;
    40274044
    40284045    if(!rCommaExpression(exp))
    4029         return FALSE;
     4046        return FALSE;
    40304047
    40314048    if(lex->GetToken(tk3) != ')')
    4032         return FALSE;
     4049        return FALSE;
    40334050
    40344051    if(!rStatement(then))
    4035         return FALSE;
     4052        return FALSE;
    40364053
    40374054    st = new PtreeIfStatement(new LeafReserved(tk1),
    4038                               Ptree::List(new Leaf(tk2), exp, new Leaf(tk3),
    4039                                           then));
     4055                              Ptree::List(new Leaf(tk2), exp, new Leaf(tk3),
     4056                                          then));
    40404057    if(lex->LookAhead(0) == ELSE){
    4041         lex->GetToken(tk4);
    4042         if(!rStatement(otherwise))
    4043             return FALSE;
    4044 
    4045         st = Ptree::Nconc(st, Ptree::List(new Leaf(tk4), otherwise));
     4058        lex->GetToken(tk4);
     4059        if(!rStatement(otherwise))
     4060            return FALSE;
     4061
     4062        st = Ptree::Nconc(st, Ptree::List(new Leaf(tk4), otherwise));
    40464063    }
    40474064
     
    40594076
    40604077    if(lex->GetToken(tk1) != SWITCH)
    4061         return FALSE;
     4078        return FALSE;
    40624079
    40634080    if(lex->GetToken(tk2) != '(')
    4064         return FALSE;
     4081        return FALSE;
    40654082
    40664083    if(!rCommaExpression(exp))
    4067         return FALSE;
     4084        return FALSE;
    40684085
    40694086    if(lex->GetToken(tk3) != ')')
    4070         return FALSE;
     4087        return FALSE;
    40714088
    40724089    if(!rStatement(body))
    4073         return FALSE;
     4090        return FALSE;
    40744091
    40754092    st = new PtreeSwitchStatement(new LeafReserved(tk1),
    4076                                   Ptree::List(new Leaf(tk2), exp,
    4077                                               new Leaf(tk3), body));
     4093                                  Ptree::List(new Leaf(tk2), exp,
     4094                                              new Leaf(tk3), body));
    40784095    return TRUE;
    40794096}
     
    40894106
    40904107    if(lex->GetToken(tk1) != WHILE)
    4091         return FALSE;
     4108        return FALSE;
    40924109
    40934110    if(lex->GetToken(tk2) != '(')
    4094         return FALSE;
     4111        return FALSE;
    40954112
    40964113    if(!rCommaExpression(exp))
    4097         return FALSE;
     4114        return FALSE;
    40984115
    40994116    if(lex->GetToken(tk3) != ')')
    4100         return FALSE;
     4117        return FALSE;
    41014118
    41024119    if(!rStatement(body))
    4103         return FALSE;
     4120        return FALSE;
    41044121
    41054122    st = new PtreeWhileStatement(new LeafReserved(tk1),
    4106                                 Ptree::List(new Leaf(tk2), exp,
    4107                                               new Leaf(tk3), body));
     4123                                Ptree::List(new Leaf(tk2), exp,
     4124                                              new Leaf(tk3), body));
    41084125    return TRUE;
    41094126}
     
    41194136
    41204137    if(lex->GetToken(tk0) != DO)
    4121         return FALSE;
     4138        return FALSE;
    41224139
    41234140    if(!rStatement(body))
    4124         return FALSE;
     4141        return FALSE;
    41254142
    41264143    if(lex->GetToken(tk1) != WHILE)
    4127         return FALSE;
     4144        return FALSE;
    41284145
    41294146    if(lex->GetToken(tk2) != '(')
    4130         return FALSE;
     4147        return FALSE;
    41314148
    41324149    if(!rCommaExpression(exp))
    4133         return FALSE;
     4150        return FALSE;
    41344151
    41354152    if(lex->GetToken(tk3) != ')')
    4136         return FALSE;
     4153        return FALSE;
    41374154
    41384155    if(lex->GetToken(tk4) != ';')
    4139         return FALSE;
     4156        return FALSE;
    41404157
    41414158    st = new PtreeDoStatement(new LeafReserved(tk0),
    4142                                 Ptree::List(body, new LeafReserved(tk1),
    4143                                              new Leaf(tk2), exp,
    4144                                              new Leaf(tk3), new Leaf(tk4)));
     4159                                Ptree::List(body, new LeafReserved(tk1),
     4160                                             new Leaf(tk2), exp,
     4161                                             new Leaf(tk3), new Leaf(tk4)));
    41454162    return TRUE;
    41464163}
     
    41574174
    41584175    if(lex->GetToken(tk1) != FOR)
    4159         return FALSE;
     4176        return FALSE;
    41604177
    41614178    if(lex->GetToken(tk2) != '(')
    4162         return FALSE;
     4179        return FALSE;
    41634180
    41644181    if(!rExprStatement(exp1))
    4165         return FALSE;
     4182        return FALSE;
    41664183
    41674184    if(lex->LookAhead(0) == ';')
    4168         exp2 = nil;
     4185        exp2 = nil;
    41694186    else
    4170         if(!rCommaExpression(exp2))
    4171             return FALSE;
     4187        if(!rCommaExpression(exp2))
     4188            return FALSE;
    41724189
    41734190    if(lex->GetToken(tk3) != ';')
    4174         return FALSE;
     4191        return FALSE;
    41754192
    41764193    if(lex->LookAhead(0) == ')')
    4177         exp3 = nil;
     4194        exp3 = nil;
    41784195    else
    4179         if(!rCommaExpression(exp3))
    4180             return FALSE;
     4196        if(!rCommaExpression(exp3))
     4197            return FALSE;
    41814198
    41824199    if(lex->GetToken(tk4) != ')')
    4183         return FALSE;
     4200        return FALSE;
    41844201
    41854202    if(!rStatement(body))
    4186         return FALSE;
     4203        return FALSE;
    41874204
    41884205
    41894206    st = new PtreeForStatement(new LeafReserved(tk1),
    4190                                Ptree::List(new Leaf(tk2), exp1, exp2,
    4191                                            new Leaf(tk3), exp3,
    4192                                            new Leaf(tk4), body));
     4207                               Ptree::List(new Leaf(tk2), exp1, exp2,
     4208                                           new Leaf(tk3), exp3,
     4209                                           new Leaf(tk4), body));
    41934210    return TRUE;
    41944211}
     
    42074224
    42084225    if(lex->GetToken(tk) != TRY)
    4209         return FALSE;
     4226        return FALSE;
    42104227
    42114228    if(!rCompoundStatement(body))
    4212         return FALSE;
     4229        return FALSE;
    42134230
    42144231    st = new PtreeTryStatement(new LeafReserved(tk), Ptree::List(body));
    42154232
    42164233    do{
    4217         if(lex->GetToken(tk) != CATCH)
    4218             return FALSE;
    4219 
    4220         if(lex->GetToken(op) != '(')
    4221             return FALSE;
    4222 
    4223         if(lex->LookAhead(0) == Ellipsis){
    4224             lex->GetToken(cp);
    4225             handler = new Leaf(cp);
    4226         }
    4227         else{
    4228             Encoding encode;
    4229             if(!rArgDeclaration(handler, encode))
    4230                 return FALSE;
    4231         }
    4232 
    4233         if(lex->GetToken(cp) != ')')
    4234             return FALSE;
    4235 
    4236         if(!rCompoundStatement(body))
    4237             return FALSE;
    4238 
    4239         st = Ptree::Snoc(st, Ptree::List(new LeafReserved(tk),
    4240                                         new Leaf(op), handler, new Leaf(cp),
    4241                                         body));
     4234        if(lex->GetToken(tk) != CATCH)
     4235            return FALSE;
     4236
     4237        if(lex->GetToken(op) != '(')
     4238            return FALSE;
     4239
     4240        if(lex->LookAhead(0) == Ellipsis){
     4241            lex->GetToken(cp);
     4242            handler = new Leaf(cp);
     4243        }
     4244        else{
     4245            Encoding encode;
     4246            if(!rArgDeclaration(handler, encode))
     4247                return FALSE;
     4248        }
     4249
     4250        if(lex->GetToken(cp) != ')')
     4251            return FALSE;
     4252
     4253        if(!rCompoundStatement(body))
     4254            return FALSE;
     4255
     4256        st = Ptree::Snoc(st, Ptree::List(new LeafReserved(tk),
     4257                                        new Leaf(op), handler, new Leaf(cp),
     4258                                        body));
    42424259    } while(lex->LookAhead(0) == CATCH);
    42434260    return TRUE;
     
    42574274
    42584275    if(lex->LookAhead(0) == ';'){
    4259         lex->GetToken(tk);
    4260         st = new PtreeExprStatement(nil, Ptree::List(new Leaf(tk)));
    4261         return TRUE;
     4276        lex->GetToken(tk);
     4277        st = new PtreeExprStatement(nil, Ptree::List(new Leaf(tk)));
     4278        return TRUE;
    42624279    }
    42634280    else{
    4264         char* pos = lex->Save();
    4265         if(rDeclarationStatement(st))
    4266             return TRUE;
    4267         else{
    4268             Ptree* exp;
    4269             lex->Restore(pos);
    4270             if(!rCommaExpression(exp))
    4271                 return FALSE;
    4272 
    4273             if(exp->IsA(ntUserStatementExpr, ntStaticUserStatementExpr)){
    4274                 st = exp;
    4275                 return TRUE;
    4276             }
    4277 
    4278             if(lex->GetToken(tk) != ';')
    4279                 return FALSE;
    4280 
    4281             st = new PtreeExprStatement(exp, Ptree::List(new Leaf(tk)));
    4282             return TRUE;
    4283         }
     4281        char* pos = lex->Save();
     4282        if(rDeclarationStatement(st))
     4283            return TRUE;
     4284        else{
     4285            Ptree* exp;
     4286            lex->Restore(pos);
     4287            if(!rCommaExpression(exp))
     4288                return FALSE;
     4289
     4290            if(exp->IsA(ntUserStatementExpr, ntStaticUserStatementExpr)){
     4291                st = exp;
     4292                return TRUE;
     4293            }
     4294
     4295            if(lex->GetToken(tk) != ';')
     4296                return FALSE;
     4297
     4298            st = new PtreeExprStatement(exp, Ptree::List(new Leaf(tk)));
     4299            return TRUE;
     4300        }
    42844301    }
    42854302}
     
    43074324       || !optCvQualify(cv_q)
    43084325       || !optIntegralTypeOrClassSpec(integral, type_encode))
    4309         return FALSE;
     4326        return FALSE;
    43104327
    43114328    Ptree* head = nil;
    43124329    if(storage_s != nil)
    4313         head = Ptree::Snoc(head, storage_s);
     4330        head = Ptree::Snoc(head, storage_s);
    43144331
    43154332    if(integral != nil)
    4316         return rIntegralDeclStatement(statement, type_encode, integral,
    4317                                       cv_q, head);
     4333        return rIntegralDeclStatement(statement, type_encode, integral,
     4334                                      cv_q, head);
    43184335    else{
    4319         type_encode.Clear();
    4320         int t = lex->LookAhead(0);
    4321         if(cv_q != nil && ((t == Identifier && lex->LookAhead(1) == '=')
    4322                            || t == '*'))
    4323             return rConstDeclaration(statement, type_encode, head, cv_q);
    4324         else
    4325             return rOtherDeclStatement(statement, type_encode, cv_q, head);
     4336        type_encode.Clear();
     4337        int t = lex->LookAhead(0);
     4338        if(cv_q != nil && ((t == Identifier && lex->LookAhead(1) == '=')
     4339                           || t == '*'))
     4340            return rConstDeclaration(statement, type_encode, head, cv_q);
     4341        else
     4342            return rOtherDeclStatement(statement, type_encode, cv_q, head);
    43264343    }
    43274344}
     
    43324349*/
    43334350bool Parser::rIntegralDeclStatement(Ptree*& statement, Encoding& type_encode,
    4334                                     Ptree* integral, Ptree* cv_q, Ptree* head)
     4351                                    Ptree* integral, Ptree* cv_q, Ptree* head)
    43354352{
    43364353    Ptree *cv_q2, *decl;
     
    43384355
    43394356    if(!optCvQualify(cv_q2))
    4340         return FALSE;
     4357        return FALSE;
    43414358
    43424359    if(cv_q != nil)
    4343         if(cv_q2 == nil)
    4344             integral = Ptree::Snoc(cv_q, integral);
    4345         else
    4346             integral = Ptree::Nconc(cv_q, Ptree::Cons(integral, cv_q2));
     4360        if(cv_q2 == nil)
     4361            integral = Ptree::Snoc(cv_q, integral);
     4362        else
     4363            integral = Ptree::Nconc(cv_q, Ptree::Cons(integral, cv_q2));
    43474364    else if(cv_q2 != nil)
    4348         integral = Ptree::Cons(integral, cv_q2);
     4365        integral = Ptree::Cons(integral, cv_q2);
    43494366
    43504367    type_encode.CvQualify(cv_q, cv_q2);
    43514368    if(lex->LookAhead(0) == ';'){
    4352         lex->GetToken(tk);
    4353         statement = new PtreeDeclaration(head, Ptree::List(integral,
    4354                                                            new Leaf(tk)));
    4355         return TRUE;
     4369        lex->GetToken(tk);
     4370        statement = new PtreeDeclaration(head, Ptree::List(integral,
     4371                                                           new Leaf(tk)));
     4372        return TRUE;
    43564373    }
    43574374    else{
    4358         if(!rDeclarators(decl, type_encode, FALSE, TRUE))
    4359             return FALSE;
    4360 
    4361         if(lex->GetToken(tk) != ';')
    4362             return FALSE;
    4363        
    4364         statement = new PtreeDeclaration(head, Ptree::List(integral, decl,
    4365                                                            new Leaf(tk)));
    4366         return TRUE;
     4375        if(!rDeclarators(decl, type_encode, FALSE, TRUE))
     4376            return FALSE;
     4377
     4378        if(lex->GetToken(tk) != ';')
     4379            return FALSE;
     4380
     4381        statement = new PtreeDeclaration(head, Ptree::List(integral, decl,
     4382                                                           new Leaf(tk)));
     4383        return TRUE;
    43674384    }
    43684385}
     
    43734390*/
    43744391bool Parser::rOtherDeclStatement(Ptree*& statement, Encoding& type_encode,
    4375                                 Ptree* cv_q, Ptree* head)
     4392                                Ptree* cv_q, Ptree* head)
    43764393{
    43774394    Ptree *type_name, *cv_q2, *decl;
     
    43794396
    43804397    if(!rName(type_name, type_encode))
    4381         return FALSE;
     4398        return FALSE;
    43824399
    43834400    if(!optCvQualify(cv_q2))
    4384         return FALSE;
     4401        return FALSE;
    43854402
    43864403    if(cv_q != nil)
    4387         if(cv_q2 == nil)
    4388             type_name = Ptree::Snoc(cv_q, type_name);
    4389         else
    4390             type_name = Ptree::Nconc(cv_q, Ptree::Cons(type_name, cv_q2));
     4404        if(cv_q2 == nil)
     4405            type_name = Ptree::Snoc(cv_q, type_name);
     4406        else
     4407            type_name = Ptree::Nconc(cv_q, Ptree::Cons(type_name, cv_q2));
    43914408    else if(cv_q2 != nil)
    4392         type_name = Ptree::Cons(type_name, cv_q2);
     4409        type_name = Ptree::Cons(type_name, cv_q2);
    43934410
    43944411    type_encode.CvQualify(cv_q, cv_q2);
    43954412    if(!rDeclarators(decl, type_encode, FALSE, TRUE))
    4396         return FALSE;
     4413        return FALSE;
    43974414
    43984415    if(lex->GetToken(tk) != ';')
    4399         return FALSE;
     4416        return FALSE;
    44004417
    44014418    statement = new PtreeDeclaration(head, Ptree::List(type_name, decl,
    4402                                                        new Leaf(tk)));
     4419                                                       new Leaf(tk)));
    44034420    return TRUE;
    44044421}
     
    44144431
    44154432    for(;;){
    4416         int t = lex->LookAhead(0);
    4417         if(t == token || t == '\0')
    4418             break;
    4419         else
    4420             lex->GetToken(tk);
     4433        int t = lex->LookAhead(0);
     4434        if(t == token || t == '\0')
     4435            break;
     4436        else
     4437            lex->GetToken(tk);
    44214438    }
    44224439}
     
    44294446main()
    44304447{
    4431     ProgramFromStdin    prog;
    4432     Lex                 lex(&prog);
    4433     Parser              parse(&lex);
    4434     Walker              w(&parse);
    4435     Ptree*              def;
     4448    ProgramFromStdin    prog;
     4449    Lex                 lex(&prog);
     4450    Parser              parse(&lex);
     4451    Walker              w(&parse);
     4452    Ptree*              def;
    44364453
    44374454    while(parse.rProgram(def)){
    4438         def->Display2(cout);
    4439         w.Translate(def);
     4455        def->Display2(cout);
     4456        w.Translate(def);
    44404457    }
    44414458
  • branches/stage2/tools/database/occ/parse.h

    r6768 r6774  
    22  Copyright (C) 1997-2001 Shigeru Chiba, Tokyo Institute of Technology.
    33
    4   Permission to use, copy, distribute and modify this software and   
    5   its documentation for any purpose is hereby granted without fee,       
    6   provided that the above copyright notice appear in all copies and that 
    7   both that copyright notice and this permission notice appear in 
     4  Permission to use, copy, distribute and modify this software and
     5  its documentation for any purpose is hereby granted without fee,
     6  provided that the above copyright notice appear in all copies and that
     7  both that copyright notice and this permission notice appear in
    88  supporting documentation.
    99
    10   Shigeru Chiba makes no representations about the suitability of this 
     10  Shigeru Chiba makes no representations about the suitability of this
    1111  software for any purpose.  It is provided "as is" without express or
    1212  implied warranty.
     
    3939    int NumOfErrors() { return nerrors; }
    4040    uint LineNumber(char* pos, char*& fname, int& fname_len);
     41    #ifdef SDS
     42    uint LineNumber(char* pos, char*& fname, int& fname_len, int& col_num, int& abs_pos);
     43    #endif
    4144
    4245    bool rProgram(Ptree*&);
     
    4447protected:
    4548    enum DeclKind { kDeclarator, kArgDeclarator, kCastDeclarator };
    46     enum TemplateDeclKind { tdk_unknown, tdk_decl, tdk_instantiation, 
    47                             tdk_specialization, num_tdks };
     49    enum TemplateDeclKind { tdk_unknown, tdk_decl, tdk_instantiation,
     50                            tdk_specialization, num_tdks };
    4851
    4952    bool SyntaxError();
     
    8487    bool rDeclaratorWithInit(Ptree*&, Encoding&, bool, bool);
    8588    bool rDeclarator(Ptree*&, DeclKind, bool, Encoding&, Encoding&, bool,
    86                      bool = FALSE);
     89                     bool = FALSE);
    8790    bool rDeclarator2(Ptree*&, DeclKind, bool, Encoding&, Encoding&, bool,
    88                       bool, Ptree**);
     91                      bool, Ptree**);
    8992    bool optPtrOperator(Ptree*&, Encoding&);
    9093    bool rMemberInitializers(Ptree*&);
  • branches/stage2/tools/database/occ/token.cpp

    r6771 r6774  
    4242
    4343#if defined(_PARSE_VCC)
    44 #define _MSC_VER        1100
     44#define _MSC_VER        1100
    4545#endif
    4646
    4747#if defined(_MSC_VER) || defined(OS2) //kso: OS2
    48 #include <assert.h>             // for assert in InitializeOtherKeywords
    49 #endif
    50 
    51 extern BOOL regularCpp;         // defined in main.cc
     48#include <assert.h>             // for assert in InitializeOtherKeywords
     49#endif
     50
     51extern BOOL regularCpp;         // defined in main.cc
    5252static void InitializeOtherKeywords();
    5353
     
    5555
    5656#ifdef __GNUG__
    57 #define token(x)        (long)#x
     57#define token(x)        (long)#x
    5858#else
    59 #define token(x)        (long)"x"
     59#define token(x)        (long)"x"
    6060#endif
    6161
    6262#else
    6363
    64 #define token(x)        x
     64#define token(x)        x
    6565
    6666#endif
     
    160160
    161161    if(keyword == nil)
    162         return FALSE;
     162        return FALSE;
    163163
    164164    str = new(GC) char[strlen(keyword) + 1];
     
    166166
    167167    if(user_keywords == nil)
    168         user_keywords = new HashTable;
     168        user_keywords = new HashTable;
    169169
    170170    if(user_keywords->AddEntry(str, (HashValue)token, &index) >= 0)
    171         return TRUE;
     171        return TRUE;
    172172    else
    173         return bool(user_keywords->Peek(index) == (HashValue)token);
     173        return bool(user_keywords->Peek(index) == (HashValue)token);
    174174}
    175175
     
    177177{
    178178    if(t == nil || !t->IsLeaf())
    179         return FALSE;
     179        return FALSE;
    180180
    181181    char* p = t->GetPosition();
     
    183183    value = 0;
    184184    if(len > 2 && *p == '0' && is_xletter(p[1])){
    185         for(int i = 2; i < len; ++i){
    186             char c = p[i];
    187             if(is_digit(c))
    188                 value = value * 0x10 + (c - '0');
    189             else if('A' <= c && c <= 'F')
    190                 value = value * 0x10 + (c - 'A' + 10);
    191             else if('a' <= c && c <= 'f')
    192                 value = value * 0x10 + (c - 'a' + 10);
    193             else if(is_int_suffix(c))
    194                 break;
    195             else
    196                 return FALSE;
    197         }
    198 
    199         return TRUE;
     185        for(int i = 2; i < len; ++i){
     186            char c = p[i];
     187            if(is_digit(c))
     188                value = value * 0x10 + (c - '0');
     189            else if('A' <= c && c <= 'F')
     190                value = value * 0x10 + (c - 'A' + 10);
     191            else if('a' <= c && c <= 'f')
     192                value = value * 0x10 + (c - 'a' + 10);
     193            else if(is_int_suffix(c))
     194                break;
     195            else
     196                return FALSE;
     197        }
     198
     199        return TRUE;
    200200    }
    201201    else if(len > 0 && is_digit(*p)){
    202         for(int i = 0; i < len; ++i){
    203             char c = p[i];
    204             if(is_digit(c))
    205                 value = value * 10 + c - '0';
    206             else if(is_int_suffix(c))
    207                 break;
    208             else
    209                 return FALSE;
    210         }
    211 
    212         return TRUE;
     202        for(int i = 0; i < len; ++i){
     203            char c = p[i];
     204            if(is_digit(c))
     205                value = value * 10 + c - '0';
     206            else if(is_int_suffix(c))
     207                break;
     208            else
     209                return FALSE;
     210        }
     211
     212        return TRUE;
    213213    }
    214214    else
    215         return FALSE;
     215        return FALSE;
    216216}
    217217
     
    221221{
    222222    if(t == nil || !t->IsLeaf())
    223         return FALSE;
     223        return FALSE;
    224224
    225225    char* p = t->GetPosition();
    226226    int length = t->GetLength();
    227227    if(*p != '"')
    228         return FALSE;
     228        return FALSE;
    229229    else{
    230         str = new(GC) char[length];
    231         char* sp = str;
    232         for(int i = 1; i < length; ++i)
    233             if(p[i] != '"'){
    234                 *sp++ = p[i];
    235                 if(p[i] == '\\' && i + 1 < length)
    236                     *sp++ = p[++i];
    237             }
    238             else
    239                 while(++i < length && p[i] != '"')
    240                     ;
    241 
    242         *sp = '\0';
    243         return TRUE;
     230        str = new(GC) char[length];
     231        char* sp = str;
     232        for(int i = 1; i < length; ++i)
     233            if(p[i] != '"'){
     234                *sp++ = p[i];
     235                if(p[i] == '\\' && i + 1 < length)
     236                    *sp++ = p[++i];
     237            }
     238            else
     239                while(++i < length && p[i] != '"')
     240                    ;
     241
     242        *sp = '\0';
     243        return TRUE;
    244244    }
    245245}
     
    273273    head = (head + 1) % size;
    274274    if(head == tail){
    275         Slot* ring2 = new (GC) Slot[size + Plus];
     275        Slot* ring2 = new (GC) Slot[size + Plus];
    276276        int i = 0;
    277         do{
    278             ring2[i++] = ring[tail];
    279             tail = (tail + 1) % size;
    280         } while(head != tail);
    281         head = i;
    282         tail = 0;
    283         size += Plus;
    284         // delete [] ring;
    285         ring = ring2;
     277        do{
     278            ring2[i++] = ring[tail];
     279            tail = (tail + 1) % size;
     280        } while(head != tail);
     281        head = i;
     282        tail = 0;
     283        size += Plus;
     284        // delete [] ring;
     285        ring = ring2;
    286286    }
    287287}
     
    290290{
    291291    if(head == tail)
    292         return lex->ReadToken(pos, len);
     292        return lex->ReadToken(pos, len);
    293293
    294294    int t = ring[tail].token;
     
    318318
    319319    for(i = 0; i <= offset; ++i){
    320         if(head == cur){
    321             while(i++ <= offset){
    322                 char* p;
    323                 int   l;
    324                 int t = lex->ReadToken(p, l);
    325                 Push(t, p, l);
    326             }
    327 
    328             break;
    329         }
    330 
    331         cur = (cur + 1) % size;
     320        if(head == cur){
     321            while(i++ <= offset){
     322                char* p;
     323                int   l;
     324                int t = lex->ReadToken(p, l);
     325                Push(t, p, l);
     326            }
     327
     328            break;
     329        }
     330
     331        cur = (cur + 1) % size;
    332332    }
    333333
     
    344344
    345345    for(;;){
    346         t = ReadLine();
     346        t = ReadLine();
    347347
    348348        if(t == Ignore)
    349             continue;
    350 
    351         last_token = t;
     349            continue;
     350
     351        last_token = t;
    352352
    353353#if defined(__GNUG__) || defined(_GNUG_SYNTAX)
    354         if(t == ATTRIBUTE){
    355             SkipAttributeToken();
    356             continue;
    357         }
    358         else if(t == EXTENSION){
    359             t = SkipExtensionToken(ptr, len);
    360             if(t == Ignore)
    361                 continue;
    362             else
    363                 return t;
    364         }
     354        if(t == ATTRIBUTE){
     355            SkipAttributeToken();
     356            continue;
     357        }
     358        else if(t == EXTENSION){
     359            t = SkipExtensionToken(ptr, len);
     360            if(t == Ignore)
     361                continue;
     362            else
     363                return t;
     364        }
    365365#endif
    366366#if defined(_MSC_VER) || defined(OS2) //kso: OS2
    367367        if(t == ASM){
    368368            SkipAsmToken();
    369             continue;
    370         }
     369            continue;
     370        }
    371371        else if(t == DECLSPEC){
    372             SkipDeclspecToken();
    373             continue;
    374         }
    375 #endif
    376         if(t != '\n')
    377             break;
     372            SkipDeclspecToken();
     373            continue;
     374        }
     375#endif
     376        if(t != '\n')
     377            break;
    378378    }
    379379
     
    390390
    391391    do{
    392         c = file->Get();
     392        c = file->Get();
    393393    }while(c != '(' && c != '\0');
    394394
    395395    int i = 1;
    396396    do{
    397         c = file->Get();
    398         if(c == '(')
    399             ++i;
    400         else if(c == ')')
    401             --i;
    402         else if(c == '\0')
    403             break;
     397        c = file->Get();
     398        if(c == '(')
     399            ++i;
     400        else if(c == ')')
     401            --i;
     402        else if(c == '\0')
     403            break;
    404404    } while(i > 0);
    405405}
     
    415415
    416416    do{
    417         c = file->Get();
     417        c = file->Get();
    418418    }while(is_blank(c) || c == '\n');
    419419
    420420    if(c != '('){
    421         file->Unget();
    422         return Ignore;          // if no (..) follows, ignore __extension__
     421        file->Unget();
     422        return Ignore;          // if no (..) follows, ignore __extension__
    423423    }
    424424
    425425    int i = 1;
    426426    do{
    427         c = file->Get();
    428         if(c == '(')
    429             ++i;
    430         else if(c == ')')
    431             --i;
    432         else if(c == '\0')
    433             break;
     427        c = file->Get();
     428        if(c == '(')
     429            ++i;
     430        else if(c == ')')
     431            --i;
     432        else if(c == '\0')
     433            break;
    434434    } while(i > 0);
    435435
    436     return Identifier;  // regards it as the identifier __extension__
     436    return Identifier;  // regards it as the identifier __extension__
    437437}
    438438
     
    440440
    441441#define CHECK_END_OF_INSTRUCTION(C, EOI) \
    442         if (C == '\0') return; \
    443         if (strchr(EOI, C)) { \
    444             this->file->Unget(); \
    445             return; \
    446         }
     442        if (C == '\0') return; \
     443        if (strchr(EOI, C)) { \
     444            this->file->Unget(); \
     445            return; \
     446        }
    447447
    448448/* SkipAsmToken() skips __asm ...
     
    467467
    468468    do{
    469         c = file->Get();
    470         CHECK_END_OF_INSTRUCTION(c, "");
     469        c = file->Get();
     470        CHECK_END_OF_INSTRUCTION(c, "");
    471471    }while(is_blank(c) || c == '\n');
    472472
     
    474474        int i = 1;
    475475        do{
    476             c = file->Get();
    477             CHECK_END_OF_INSTRUCTION(c, "");
    478             if(c == '{')
    479                 ++i;
    480             else if(c == '}')
    481                 --i;
     476            c = file->Get();
     477            CHECK_END_OF_INSTRUCTION(c, "");
     478            if(c == '{')
     479                ++i;
     480            else if(c == '}')
     481                --i;
    482482        } while(i > 0);
    483483    }
    484484    else{
    485485        for(;;){
    486             CHECK_END_OF_INSTRUCTION(c, "}\n");
    487             c = file->Get();
     486            CHECK_END_OF_INSTRUCTION(c, "}\n");
     487            c = file->Get();
    488488        }
    489489    }
     
    497497
    498498    do{
    499         c = file->Get();
    500         CHECK_END_OF_INSTRUCTION(c, "");
     499        c = file->Get();
     500        CHECK_END_OF_INSTRUCTION(c, "");
    501501    }while(is_blank(c));
    502502
     
    504504        int i = 1;
    505505        do{
    506             c = file->Get();
    507             CHECK_END_OF_INSTRUCTION(c, "};");
    508             if(c == '(')
    509                 ++i;
    510             else if(c == ')')
    511                 --i;
     506            c = file->Get();
     507            CHECK_END_OF_INSTRUCTION(c, "};");
     508            if(c == '(')
     509                ++i;
     510            else if(c == ')')
     511                --i;
    512512        }while(i > 0);
    513513    }
     
    524524    for(;;){
    525525        do{
    526             c = file->Get();
     526            c = file->Get();
    527527        }while(is_blank(c));
    528528
    529529        if(c != '\\')
    530             break;
     530            break;
    531531
    532532        c = file->Get();
    533533        if(c != '\n' && c!= '\r') {
    534             file->Unget();
    535             break;
    536         }
     534            file->Unget();
     535            break;
     536        }
    537537    }
    538538
     
    549549    tokenp = top = file->GetCurPos();
    550550    if(c == '\0'){
    551         file->Unget();
    552         return '\0';
     551        file->Unget();
     552        return '\0';
    553553    }
    554554    else if(c == '\n')
    555         return '\n';
     555        return '\n';
    556556    else if(c == '#' && last_token == '\n'){
    557         if(ReadLineDirective())
    558             return '\n';
    559         else{
    560             file->Rewind(top + 1);
    561             token_len = 1;
    562             return SingleCharOp(c);
    563         }
     557        if(ReadLineDirective())
     558            return '\n';
     559        else{
     560            file->Rewind(top + 1);
     561            token_len = 1;
     562            return SingleCharOp(c);
     563        }
    564564    }
    565565    else if(c == '\'' || c == '"'){
    566         if(c == '\''){
    567             if(ReadCharConst(top))
    568                 return token(CharConst);
    569         }
    570         else{
    571             if(ReadStrConst(top))
    572                 return token(StringL);
    573         }
    574 
    575         file->Rewind(top + 1);
    576         token_len = 1;
    577         return SingleCharOp(c);
     566        if(c == '\''){
     567            if(ReadCharConst(top))
     568                return token(CharConst);
     569        }
     570        else{
     571            if(ReadStrConst(top))
     572                return token(StringL);
     573        }
     574
     575        file->Rewind(top + 1);
     576        token_len = 1;
     577        return SingleCharOp(c);
    578578    }
    579579    else if(is_digit(c))
    580         return ReadNumber(c, top);
     580        return ReadNumber(c, top);
    581581    else if(c == '.'){
    582         c = file->Get();
    583         if(is_digit(c))
    584             return ReadFloat(top);
    585         else{
    586             file->Unget();
    587             return ReadSeparator('.', top);
    588         }
     582        c = file->Get();
     583        if(is_digit(c))
     584            return ReadFloat(top);
     585        else{
     586            file->Unget();
     587            return ReadSeparator('.', top);
     588        }
    589589    }
    590590    else if(is_letter(c))
    591         return ReadIdentifier(top);
     591        return ReadIdentifier(top);
    592592    else
    593         return ReadSeparator(c, top);
     593        return ReadSeparator(c, top);
    594594}
    595595
     
    599599
    600600    for(;;){
    601         c = file->Get();
    602         if(c == '\\'){
    603             c = file->Get();
    604             if(c == '\0')
    605                 return FALSE;
    606         }
    607         else if(c == '\''){
    608             token_len = int(file->GetCurPos() - top + 1);
    609             return TRUE;
    610         }
    611         else if(c == '\n' || c == '\0')
    612             return FALSE;
     601        c = file->Get();
     602        if(c == '\\'){
     603            c = file->Get();
     604            if(c == '\0')
     605                return FALSE;
     606        }
     607        else if(c == '\''){
     608            token_len = int(file->GetCurPos() - top + 1);
     609            return TRUE;
     610        }
     611        else if(c == '\n' || c == '\0')
     612            return FALSE;
    613613    }
    614614}
     
    616616/*
    617617  If text is a sequence of string constants like:
    618         "string1" "string2"
     618        "string1" "string2"
    619619  then the string constants are delt with as a single constant.
    620620*/
     
    624624
    625625    for(;;){
    626         c = file->Get();
    627         if(c == '\\'){
    628             c = file->Get();
    629             if(c == '\0')
    630                 return FALSE;
    631         }
    632         else if(c == '"'){
    633             uint pos = file->GetCurPos() + 1;
    634             int nline = 0;
    635             do{
    636                 c = file->Get();
    637                 if(c == '\n')
    638                     ++nline;
    639             } while(is_blank(c) || c == '\n');
    640 
    641             if(c == '"')
    642                 /* line_number += nline; */ ;
    643             else{
    644                 token_len = int(pos - top);
    645                 file->Rewind(pos);
    646                 return TRUE;
    647             }
    648         }
    649         else if(c == '\n' || c == '\0')
    650             return FALSE;
     626        c = file->Get();
     627        if(c == '\\'){
     628            c = file->Get();
     629            if(c == '\0')
     630                return FALSE;
     631        }
     632        else if(c == '"'){
     633            uint pos = file->GetCurPos() + 1;
     634            int nline = 0;
     635            do{
     636                c = file->Get();
     637                if(c == '\n')
     638                    ++nline;
     639            } while(is_blank(c) || c == '\n');
     640
     641            if(c == '"')
     642                /* line_number += nline; */ ;
     643            else{
     644                token_len = int(pos - top);
     645                file->Rewind(pos);
     646                return TRUE;
     647            }
     648        }
     649        else if(c == '\n' || c == '\0')
     650            return FALSE;
    651651    }
    652652}
     
    657657
    658658    if(c == '0' && is_xletter(c2)){
    659         do{
    660             c = file->Get();
    661         } while(is_hexdigit(c));
    662         while(is_int_suffix(c))
    663             c = file->Get();
    664 
    665         file->Unget();
    666         token_len = int(file->GetCurPos() - top + 1);
    667         return token(Constant);
     659        do{
     660            c = file->Get();
     661        } while(is_hexdigit(c));
     662        while(is_int_suffix(c))
     663            c = file->Get();
     664
     665        file->Unget();
     666        token_len = int(file->GetCurPos() - top + 1);
     667        return token(Constant);
    668668    }
    669669
    670670    while(is_digit(c2))
    671         c2 = file->Get();
     671        c2 = file->Get();
    672672
    673673    if(is_int_suffix(c2))
    674         do{
    675             c2 = file->Get();
    676         }while(is_int_suffix(c2));
     674        do{
     675            c2 = file->Get();
     676        }while(is_int_suffix(c2));
    677677    else if(c2 == '.')
    678         return ReadFloat(top);
     678        return ReadFloat(top);
    679679    else if(is_eletter(c2)){
    680         file->Unget();
    681         return ReadFloat(top);
     680        file->Unget();
     681        return ReadFloat(top);
    682682    }
    683683
     
    692692
    693693    do{
    694         c = file->Get();
     694        c = file->Get();
    695695    }while(is_digit(c));
    696696    if(is_float_suffix(c))
    697         do{
    698             c = file->Get();
    699         }while(is_float_suffix(c));
     697        do{
     698            c = file->Get();
     699        }while(is_float_suffix(c));
    700700    else if(is_eletter(c)){
    701         uint p = file->GetCurPos();
    702         c = file->Get();
    703         if(c == '+' || c == '-'){
    704              c = file->Get();
    705              if(!is_digit(c)){
    706                 file->Rewind(p);
    707                 token_len = int(p - top);
    708                 return token(Constant);
    709             }
    710         }
    711         else if(!is_digit(c)){
    712             file->Rewind(p);
    713             token_len = int(p - top);
    714             return token(Constant);
    715         }
    716 
    717         do{
    718             c = file->Get();
    719         }while(is_digit(c));
    720 
    721         while(is_float_suffix(c))
    722             c = file->Get();
     701        uint p = file->GetCurPos();
     702        c = file->Get();
     703        if(c == '+' || c == '-'){
     704             c = file->Get();
     705             if(!is_digit(c)){
     706                file->Rewind(p);
     707                token_len = int(p - top);
     708                return token(Constant);
     709            }
     710        }
     711        else if(!is_digit(c)){
     712            file->Rewind(p);
     713            token_len = int(p - top);
     714            return token(Constant);
     715        }
     716
     717        do{
     718            c = file->Get();
     719        }while(is_digit(c));
     720
     721        while(is_float_suffix(c))
     722            c = file->Get();
    723723    }
    724724
     
    735735
    736736    do{
    737         c = file->Get();
     737        c = file->Get();
    738738    }while(c != '\n' && c != '\0');
    739739    return TRUE;
     
    745745
    746746    do{
    747         c = file->Get();
     747        c = file->Get();
    748748    }while(is_letter(c) || is_digit(c));
    749749
     
    760760*/
    761761static struct rw_table {
    762     char*       name;
    763     long        value;
     762    char*       name;
     763    long        value;
    764764} table[] = {
    765765#if defined(__GNUG__) || defined(_GNUG_SYNTAX)
    766     { "__alignof__",    token(SIZEOF) },
    767     { "__asm__",        token(ATTRIBUTE) },
    768     { "__attribute__",  token(ATTRIBUTE) },
    769     { "__const",        token(CONST) },
    770     { "__const__",      token(Ignore) }, //kso: gcc supports this AFAIK
    771     { "__extension__",  token(EXTENSION) },
    772     { "__inline__",     token(INLINE) },
    773     { "__restrict",     token(Ignore) },
    774     { "__signed",       token(SIGNED) },
    775     { "__signed__",     token(SIGNED) },
    776 #endif
    777     { "asm",            token(ATTRIBUTE) },
    778     { "auto",           token(AUTO) },
     766    { "__alignof__",    token(SIZEOF) },
     767    { "__asm__",        token(ATTRIBUTE) },
     768    { "__attribute__",  token(ATTRIBUTE) },
     769    { "__const",        token(CONST) },
     770    { "__const__",      token(CONST) }, //kso: gcc supports this AFAIK
     771    { "__extension__",  token(EXTENSION) },
     772    { "__inline__",     token(INLINE) },
     773    { "__restrict",     token(Ignore) },
     774    { "__signed",       token(SIGNED) },
     775    { "__signed__",     token(SIGNED) },
     776#endif
     777    { "asm",            token(ATTRIBUTE) },
     778    { "auto",           token(AUTO) },
    779779#if (!defined(_MSC_VER) || (_MSC_VER >= 1100)) && !defined(__IBMCPP__)
    780     { "bool",           token(BOOLEAN) },
    781 #endif
    782     { "break",          token(BREAK) },
    783     { "case",           token(CASE) },
    784     { "catch",          token(CATCH) },
    785     { "char",           token(CHAR) },
    786     { "class",          token(CLASS) },
    787     { "const",          token(CONST) },
    788     { "continue",       token(CONTINUE) },
    789     { "default",        token(DEFAULT) },
    790     { "delete",         token(DELETE) },
    791     { "do",             token(DO) },
    792     { "double",         token(DOUBLE) },
    793     { "else",           token(ELSE) },
    794     { "enum",           token(ENUM) },
    795     { "extern",         token(EXTERN) },
    796     { "float",          token(FLOAT) },
    797     { "for",            token(FOR) },
    798     { "friend",         token(FRIEND) },
    799     { "goto",           token(GOTO) },
    800     { "if",             token(IF) },
    801     { "inline",         token(INLINE) },
    802     { "int",            token(INT) },
    803     { "long",           token(LONG) },
    804     { "metaclass",      token(METACLASS) },     // OpenC++
    805     { "mutable",        token(MUTABLE) },
    806     { "namespace",      token(NAMESPACE) },
    807     { "new",            token(NEW) },
    808     { "operator",       token(OPERATOR) },
    809     { "private",        token(PRIVATE) },
    810     { "protected",      token(PROTECTED) },
    811     { "public",         token(PUBLIC) },
    812     { "register",       token(REGISTER) },
    813     { "return",         token(RETURN) },
    814     { "short",          token(SHORT) },
    815     { "signed",         token(SIGNED) },
    816     { "sizeof",         token(SIZEOF) },
    817     { "static",         token(STATIC) },
    818     { "struct",         token(STRUCT) },
    819     { "switch",         token(SWITCH) },
    820     { "template",       token(TEMPLATE) },
    821     { "this",           token(THIS) },
    822     { "throw",          token(THROW) },
    823     { "try",            token(TRY) },
    824     { "typedef",        token(TYPEDEF) },
    825     { "typename",       token(CLASS) }, // it's not identical to class, but...
    826     { "union",          token(UNION) },
    827     { "unsigned",       token(UNSIGNED) },
    828     { "using",          token(USING) },
    829     { "virtual",        token(VIRTUAL) },
    830     { "void",           token(VOID) },
    831     { "volatile",       token(VOLATILE) },
    832     { "while",          token(WHILE) },
     780    { "bool",           token(BOOLEAN) },
     781#endif
     782    { "break",          token(BREAK) },
     783    { "case",           token(CASE) },
     784    { "catch",          token(CATCH) },
     785    { "char",           token(CHAR) },
     786    { "class",          token(CLASS) },
     787    { "const",          token(CONST) },
     788    { "continue",       token(CONTINUE) },
     789    { "default",        token(DEFAULT) },
     790    { "delete",         token(DELETE) },
     791    { "do",             token(DO) },
     792    { "double",         token(DOUBLE) },
     793    { "else",           token(ELSE) },
     794    { "enum",           token(ENUM) },
     795    { "extern",         token(EXTERN) },
     796    { "float",          token(FLOAT) },
     797    { "for",            token(FOR) },
     798    { "friend",         token(FRIEND) },
     799    { "goto",           token(GOTO) },
     800    { "if",             token(IF) },
     801    { "inline",         token(INLINE) },
     802    { "int",            token(INT) },
     803    { "long",           token(LONG) },
     804    { "metaclass",      token(METACLASS) },     // OpenC++
     805    { "mutable",        token(MUTABLE) },
     806    { "namespace",      token(NAMESPACE) },
     807    { "new",            token(NEW) },
     808    { "operator",       token(OPERATOR) },
     809    { "private",        token(PRIVATE) },
     810    { "protected",      token(PROTECTED) },
     811    { "public",         token(PUBLIC) },
     812    { "register",       token(REGISTER) },
     813    { "return",         token(RETURN) },
     814    { "short",          token(SHORT) },
     815    { "signed",         token(SIGNED) },
     816    { "sizeof",         token(SIZEOF) },
     817    { "static",         token(STATIC) },
     818    { "struct",         token(STRUCT) },
     819    { "switch",         token(SWITCH) },
     820    { "template",       token(TEMPLATE) },
     821    { "this",           token(THIS) },
     822    { "throw",          token(THROW) },
     823    { "try",            token(TRY) },
     824    { "typedef",        token(TYPEDEF) },
     825    { "typename",       token(CLASS) }, // it's not identical to class, but...
     826    { "union",          token(UNION) },
     827    { "unsigned",       token(UNSIGNED) },
     828    { "using",          token(USING) },
     829    { "virtual",        token(VIRTUAL) },
     830    { "void",           token(VOID) },
     831    { "volatile",       token(VOLATILE) },
     832    { "while",          token(WHILE) },
    833833    /* NULL slot */
    834834};
     
    839839
    840840    if(done)
    841         return;
     841        return;
    842842    else
    843         done = TRUE;
     843        done = TRUE;
    844844
    845845    if(regularCpp)
    846         for(unsigned int i = 0; i < sizeof(table) / sizeof(table[0]); ++i)
    847             if(table[i].value == METACLASS){
    848                 table[i].value = Identifier;
    849                 break;
    850             }
     846        for(unsigned int i = 0; i < sizeof(table) / sizeof(table[0]); ++i)
     847            if(table[i].value == METACLASS){
     848                table[i].value = Identifier;
     849                break;
     850            }
    851851
    852852#if defined(_MSC_VER) || defined(OS2)   //kso: OS2
     
    896896int Lex::Screening(char *identifier, int len)
    897897{
    898     struct rw_table     *low, *high, *mid;
    899     int                 c, token;
     898    struct rw_table     *low, *high, *mid;
     899    int                 c, token;
    900900
    901901    low = table;
    902902    high = &table[sizeof(table) / sizeof(table[0]) - 1];
    903903    while(low <= high){
    904         mid = low + (high - low) / 2;
    905         if((c = strncmp(mid->name, identifier, len)) == 0)
    906             if(mid->name[len] == '\0')
    907                 return mid->value;
    908             else
    909                 high = mid - 1;
    910         else if(c < 0)
    911             low = mid + 1;
    912         else
    913             high = mid - 1;
     904        mid = low + (high - low) / 2;
     905        if((c = strncmp(mid->name, identifier, len)) == 0)
     906            if(mid->name[len] == '\0')
     907                return mid->value;
     908            else
     909                high = mid - 1;
     910        else if(c < 0)
     911            low = mid + 1;
     912        else
     913            high = mid - 1;
    914914    }
    915915
    916916    if(user_keywords == nil)
    917         user_keywords = new HashTable;
     917        user_keywords = new HashTable;
    918918
    919919    if(user_keywords->Lookup(identifier, len, (HashValue*)&token))
    920         return token;
     920        return token;
    921921
    922922    return token(Identifier);
     
    929929    token_len = 2;
    930930    if(c1 == '='){
    931         switch(c){
    932         case '*' :
    933         case '/' :
    934         case '%' :
    935         case '+' :
    936         case '-' :
    937         case '&' :
    938         case '^' :
    939         case '|' :
    940             return token(AssignOp);
    941         case '=' :
    942         case '!' :
    943             return token(EqualOp);
    944         case '<' :
    945         case '>' :
    946             return token(RelOp);
    947         default :
    948             file->Unget();
    949             token_len = 1;
    950             return SingleCharOp(c);
    951         }
     931        switch(c){
     932        case '*' :
     933        case '/' :
     934        case '%' :
     935        case '+' :
     936        case '-' :
     937        case '&' :
     938        case '^' :
     939        case '|' :
     940            return token(AssignOp);
     941        case '=' :
     942        case '!' :
     943            return token(EqualOp);
     944        case '<' :
     945        case '>' :
     946            return token(RelOp);
     947        default :
     948            file->Unget();
     949            token_len = 1;
     950            return SingleCharOp(c);
     951        }
    952952    }
    953953    else if(c == c1){
    954         switch(c){
    955         case '<' :
    956         case '>' :
    957             if(file->Get() != '='){
    958                 file->Unget();
    959                 return token(ShiftOp);
    960             }
    961             else{
    962                 token_len = 3;
    963                 return token(AssignOp);
    964             }
    965         case '|' :
    966             return token(LogOrOp);
    967         case '&' :
    968             return token(LogAndOp);
    969         case '+' :
    970         case '-' :
    971             return token(IncOp);
    972         case ':' :
    973             return token(Scope);
    974         case '.' :
    975             if(file->Get() == '.'){
    976                 token_len = 3;
    977                 return token(Ellipsis);
    978             }
    979             else
    980                 file->Unget();
    981         case '/' :
    982             return ReadComment(c1, top);
    983         default :
    984             file->Unget();
    985             token_len = 1;
    986             return SingleCharOp(c);
    987         }
     954        switch(c){
     955        case '<' :
     956        case '>' :
     957            if(file->Get() != '='){
     958                file->Unget();
     959                return token(ShiftOp);
     960            }
     961            else{
     962                token_len = 3;
     963                return token(AssignOp);
     964            }
     965        case '|' :
     966            return token(LogOrOp);
     967        case '&' :
     968            return token(LogAndOp);
     969        case '+' :
     970        case '-' :
     971            return token(IncOp);
     972        case ':' :
     973            return token(Scope);
     974        case '.' :
     975            if(file->Get() == '.'){
     976                token_len = 3;
     977                return token(Ellipsis);
     978            }
     979            else
     980                file->Unget();
     981        case '/' :
     982            return ReadComment(c1, top);
     983        default :
     984            file->Unget();
     985            token_len = 1;
     986            return SingleCharOp(c);
     987        }
    988988    }
    989989    else if(c == '.' && c1 == '*')
    990         return token(PmOp);
     990        return token(PmOp);
    991991    else if(c == '-' && c1 == '>')
    992         if(file->Get() == '*'){
    993             token_len = 3;
    994             return token(PmOp);
    995         }
    996         else{
    997             file->Unget();
    998             return token(ArrowOp);
    999         }
     992        if(file->Get() == '*'){
     993            token_len = 3;
     994            return token(PmOp);
     995        }
     996        else{
     997            file->Unget();
     998            return token(ArrowOp);
     999        }
    10001000    else if(c == '/' && c1 == '*')
    1001         return ReadComment(c1, top);
     1001        return ReadComment(c1, top);
    10021002    else{
    1003         file->Unget();
    1004         token_len = 1;
    1005         return SingleCharOp(c);
     1003        file->Unget();
     1004        token_len = 1;
     1005        return SingleCharOp(c);
    10061006    }
    10071007
    10081008    cerr << "*** An invalid character has been found! ("
    1009         << (int)c << ',' << (int)c1 << ")\n";
     1009        << (int)c << ',' << (int)c1 << ")\n";
    10101010    return token(BadToken);
    10111011}
     
    10131013int Lex::SingleCharOp(unsigned char c)
    10141014{
    1015                         /* !"#$%&'()*+,-./0123456789:;<=>? */
     1015                        /* !"#$%&'()*+,-./0123456789:;<=>? */
    10161016    static char valid[] = "x   xx xxxxxxxx          xxxxxx";
    10171017
    10181018    if('!' <= c && c <= '?' && valid[c - '!'] == 'x')
    1019         return c;
     1019        return c;
    10201020    else if(c == '[' || c == ']' || c == '^')
    1021         return c;
     1021        return c;
    10221022    else if('{' <= c && c <= '~')
    1023         return c;
     1023        return c;
    10241024    else
    1025         return token(BadToken);
     1025        return token(BadToken);
    10261026}
    10271027
     
    10311031    bool foneliner = false;
    10321032    #endif
    1033     if (c == '*')       // a nested C-style comment is prohibited.
    1034         do {
    1035             c = file->Get();
    1036             if (c == '*') {
    1037                 c = file->Get();
    1038                 if (c == '/') {
    1039                     len = 1;
    1040                     break;
    1041                 }
    1042                 else
    1043                     file->Unget();
    1044             }
    1045         }while(c != '\0');
     1033    if (c == '*')       // a nested C-style comment is prohibited.
     1034        do {
     1035            c = file->Get();
     1036            if (c == '*') {
     1037                c = file->Get();
     1038                if (c == '/') {
     1039                    len = 1;
     1040                    break;
     1041                }
     1042                else
     1043                    file->Unget();
     1044            }
     1045        }while(c != '\0');
    10461046    else /* if (c == '/') */
    10471047    #ifdef SDS
     
    10541054    }
    10551055    #else
    1056         do {
    1057             c = file->Get();
    1058         }while(c != '\n' && c != '\0');
     1056        do {
     1057            c = file->Get();
     1058        }while(c != '\n' && c != '\0');
    10591059    #endif
    10601060
     
    10991099    Lex lex(new ProgramFromStdin);
    11001100    for(;;){
    1101 //      int t = lex.GetToken(token);
    1102         int t = lex.LookAhead(i++, token);
    1103         if(t == 0)
    1104             break;
    1105         else if(t < 128)
    1106             printf("%c (%x): ", t, t);
    1107         else
    1108             printf("%-10.10s (%x): ", (char*)t, t);
    1109 
    1110         putchar('"');
    1111         while(token.len-- > 0)
    1112             putchar(*token.ptr++);
    1113 
    1114         puts("\"");
     1101//      int t = lex.GetToken(token);
     1102        int t = lex.LookAhead(i++, token);
     1103        if(t == 0)
     1104            break;
     1105        else if(t < 128)
     1106            printf("%c (%x): ", t, t);
     1107        else
     1108            printf("%-10.10s (%x): ", (char*)t, t);
     1109
     1110        putchar('"');
     1111        while(token.len-- > 0)
     1112            putchar(*token.ptr++);
     1113
     1114        puts("\"");
    11151115    };
    11161116}
     
    11251125^"#"{blank}*"pragma".*\n
    11261126
    1127 Constant        {digit}+{int_suffix}*
    1128                 "0"{xletter}{hexdigit}+{int_suffix}*
    1129                 {digit}*\.{digit}+{float_suffix}*
    1130                 {digit}+\.{float_suffix}*
    1131                 {digit}*\.{digit}+"e"("+"|"-")*{digit}+{float_suffix}*
    1132                 {digit}+\."e"("+"|"-")*{digit}+{float_suffix}*
    1133                 {digit}+"e"("+"|"-")*{digit}+{float_suffix}*
    1134 
    1135 CharConst       \'([^'\n]|\\[^\n])\'
    1136 
    1137 StringL         \"([^"\n]|\\["\n])*\"
    1138 
    1139 Identifier      {letter}+({letter}|{digit})*
    1140 
    1141 AssignOp        *= /= %= += -= &= ^= <<= >>=
    1142 
    1143 EqualOp         == !=
    1144 
    1145 RelOp           <= >=
    1146 
    1147 ShiftOp         << >>
    1148 
    1149 LogOrOp         ||
    1150 
    1151 LogAndOp        &&
    1152 
    1153 IncOp           ++ --
    1154 
    1155 Scope           ::
    1156 
    1157 Ellipsis        ...
    1158 
    1159 PmOp            .* ->*
    1160 
    1161 ArrowOp         ->
    1162 
    1163 others          !%^&*()-+={}|~[];:<>?,./
    1164 
    1165 BadToken        others
     1127Constant        {digit}+{int_suffix}*
     1128                "0"{xletter}{hexdigit}+{int_suffix}*
     1129                {digit}*\.{digit}+{float_suffix}*
     1130                {digit}+\.{float_suffix}*
     1131                {digit}*\.{digit}+"e"("+"|"-")*{digit}+{float_suffix}*
     1132                {digit}+\."e"("+"|"-")*{digit}+{float_suffix}*
     1133                {digit}+"e"("+"|"-")*{digit}+{float_suffix}*
     1134
     1135CharConst       \'([^'\n]|\\[^\n])\'
     1136
     1137StringL         \"([^"\n]|\\["\n])*\"
     1138
     1139Identifier      {letter}+({letter}|{digit})*
     1140
     1141AssignOp        *= /= %= += -= &= ^= <<= >>=
     1142
     1143EqualOp         == !=
     1144
     1145RelOp           <= >=
     1146
     1147ShiftOp         << >>
     1148
     1149LogOrOp         ||
     1150
     1151LogAndOp        &&
     1152
     1153IncOp           ++ --
     1154
     1155Scope           ::
     1156
     1157Ellipsis        ...
     1158
     1159PmOp            .* ->*
     1160
     1161ArrowOp         ->
     1162
     1163others          !%^&*()-+={}|~[];:<>?,./
     1164
     1165BadToken        others
    11661166
    11671167*/
Note: See TracChangeset for help on using the changeset viewer.