~ubuntu-branches/ubuntu/saucy/gnudatalanguage/saucy-proposed

« back to all changes in this revision

Viewing changes to src/GDLTreeParser.cpp

  • Committer: Package Import Robot
  • Author(s): Axel Beckert
  • Date: 2013-05-15 02:23:58 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130515022358-rziznpf225zn9lv9
Tags: 0.9.3-2
* Upload to unstable.
* Revamp debian/rules
  - Allow parallel builds
  - Use debian/manpages instead of dh_installman parameter
  - Switch to dh7 style debian/rules file
* Bump debhelper compatibility to 9
  - Update versioned debhelper build-dependency
* Bump Standards-Version to 3.9.4 (no changes)
* Apply wrap-and-sort

Show diffs side-by-side

added added

removed removed

Lines of Context:
431
431
        }
432
432
        }
433
433
        
 
434
        if( NCompileErrors() > 0)
 
435
        throw GDLException( i2s(NCompileErrors()) + " compilation error(s) in module " + name->getText() + ".");
 
436
        
434
437
        comp.EndPro();
435
438
        
436
439
        currentAST = __currentAST19;
671
674
        }
672
675
        }
673
676
        
 
677
        if( NCompileErrors() > 0)
 
678
        throw GDLException( i2s(NCompileErrors()) + " compilation error(s) in module " + name->getText() + ".");
 
679
        
674
680
        comp.EndFun();
675
681
        
676
682
        currentAST = __currentAST24;
1543
1549
        case ASSIGN:
1544
1550
        case ARRAYDEF:
1545
1551
        case ARRAYDEF_CONST:
1546
 
        case ARRAYEXPR_FN:
 
1552
        case ARRAYEXPR_FCALL:
1547
1553
        case ARRAYEXPR_MFCALL:
1548
1554
        case CONSTANT:
1549
1555
        case FCALL:
 
1556
        case GDLNULL:
1550
1557
        case MFCALL:
1551
1558
        case MFCALL_PARENT:
1552
1559
        case NSTRUC_REF:
3010
3017
                nParam = para_AST->GetNParam();
3011
3018
                
3012
3019
                int libParam = libProList[i]->NPar();
 
3020
                int libParamMin = libProList[i]->NParMin();
3013
3021
                if( libParam != -1 && nParam > libParam)
3014
3022
                throw GDLException(     p, libProList[i]->Name() + ": Too many arguments.");
 
3023
                if( libParam != -1 && nParam < libParamMin)
 
3024
                throw GDLException(     p, libProList[i]->Name() + ": Too few arguments.");
3015
3025
                
3016
3026
                p_AST->setType(PCALL_LIB);
3017
3027
                p_AST->setText("pcall_lib");
3089
3099
        case ARRAYDEF:
3090
3100
        case ARRAYDEF_CONST:
3091
3101
        case ARRAYEXPR:
3092
 
        case ARRAYEXPR_FN:
 
3102
        case ARRAYEXPR_FCALL:
3093
3103
        case ARRAYEXPR_MFCALL:
3094
3104
        case CONSTANT:
3095
3105
        case DEREF:
3096
3106
        case EXPR:
3097
3107
        case FCALL:
 
3108
        case GDLNULL:
3098
3109
        case MFCALL:
3099
3110
        case MFCALL_PARENT:
3100
3111
        case NSTRUC_REF:
3452
3463
                case ARRAYDEF:
3453
3464
                case ARRAYDEF_CONST:
3454
3465
                case ARRAYEXPR:
3455
 
                case ARRAYEXPR_FN:
 
3466
                case ARRAYEXPR_FCALL:
3456
3467
                case ARRAYEXPR_MFCALL:
3457
3468
                case CONSTANT:
3458
3469
                case DEREF:
3459
3470
                case EXPR:
3460
3471
                case FCALL:
 
3472
                case GDLNULL:
3461
3473
                case MFCALL:
3462
3474
                case MFCALL_PARENT:
3463
3475
                case NSTRUC_REF:
3797
3809
                case ARRAYDEF:
3798
3810
                case ARRAYDEF_CONST:
3799
3811
                case ARRAYEXPR:
3800
 
                case ARRAYEXPR_FN:
 
3812
                case ARRAYEXPR_FCALL:
3801
3813
                case ARRAYEXPR_MFCALL:
3802
3814
                case CONSTANT:
3803
3815
                case DEREF:
3804
3816
                case EXPR:
3805
3817
                case FCALL:
 
3818
                case GDLNULL:
3806
3819
                case MFCALL:
3807
3820
                case MFCALL_PARENT:
3808
3821
                case NSTRUC_REF:
3939
3952
        {
3940
3953
        int t = k_AST->getType();
3941
3954
        if( t == FCALL_LIB || t == MFCALL_LIB || //t == FCALL_LIB_N_ELEMENTS ||
3942
 
        
3943
 
        t == MFCALL_PARENT_LIB //||
 
3955
        t == MFCALL_PARENT_LIB  || t == QUESTION //||
3944
3956
        //                          t == FCALL_LIB_RETNEW || t == MFCALL_LIB_RETNEW || 
3945
3957
        //                          t == MFCALL_PARENT_LIB_RETNEW //||
3946
3958
        //                          t == ARRARYEXPR_MFCALL_LIB // MFCALL_LIB or VAR or DEREF 
4016
4028
        int t = e_AST->getType();
4017
4029
        // Note: Right now there are no MFCALL_LIB or MFCALL_PARENT_LIB nodes
4018
4030
        if( t == FCALL_LIB || t == MFCALL_LIB || //t == FCALL_LIB_N_ELEMENTS ||
4019
 
        t == MFCALL_PARENT_LIB //||
 
4031
        t == MFCALL_PARENT_LIB || t == QUESTION //||
4020
4032
        //                      t == FCALL_LIB_RETNEW || t == MFCALL_LIB_RETNEW || 
4021
4033
        //                      t == MFCALL_PARENT_LIB_RETNEW
4022
4034
        //                      t == ARRARYEXPR_MFCALL_LIB // MFCALL_LIB or VAR or DEREF 
4248
4260
                case ARRAYDEF:
4249
4261
                case ARRAYDEF_CONST:
4250
4262
                case ARRAYEXPR:
4251
 
                case ARRAYEXPR_FN:
 
4263
                case ARRAYEXPR_FCALL:
4252
4264
                case ARRAYEXPR_MFCALL:
4253
4265
                case CONSTANT:
4254
4266
                case DEREF:
4255
4267
                case EXPR:
4256
4268
                case FCALL:
 
4269
                case GDLNULL:
4257
4270
                case MFCALL:
4258
4271
                case MFCALL_PARENT:
4259
4272
                case NSTRUC_REF:
4322
4335
                                case ARRAYDEF:
4323
4336
                                case ARRAYDEF_CONST:
4324
4337
                                case ARRAYEXPR:
4325
 
                                case ARRAYEXPR_FN:
 
4338
                                case ARRAYEXPR_FCALL:
4326
4339
                                case ARRAYEXPR_MFCALL:
4327
4340
                                case CONSTANT:
4328
4341
                                case DEREF:
4329
4342
                                case EXPR:
4330
4343
                                case FCALL:
 
4344
                                case GDLNULL:
4331
4345
                                case MFCALL:
4332
4346
                                case MFCALL_PARENT:
4333
4347
                                case NSTRUC_REF:
4573
4587
        case ARRAYDEF:
4574
4588
        case ARRAYDEF_CONST:
4575
4589
        case ARRAYEXPR:
4576
 
        case ARRAYEXPR_FN:
 
4590
        case ARRAYEXPR_FCALL:
4577
4591
        case ARRAYEXPR_MFCALL:
4578
4592
        case CONSTANT:
4579
4593
        case DEREF:
4580
4594
        case EXPR:
4581
4595
        case FCALL:
 
4596
        case GDLNULL:
4582
4597
        case MFCALL:
4583
4598
        case MFCALL_PARENT:
4584
4599
        case NSTRUC_REF:
4640
4655
                expr(_t);
4641
4656
                _t = _retTree;
4642
4657
                e1_AST = returnAST;
 
4658
                
 
4659
                // in ConstantIndex the cData of all nodes is stolen
 
4660
                // (in case it succeeds)
 
4661
                // therefore we build here the new constant node with
 
4662
                // proper cData. See below (e2)
 
4663
                c1 = comp.ConstantIndex( e1_AST);
 
4664
                if( c1 != NULL)
 
4665
                {    
 
4666
                int e1Line = e1_AST->getLine();
 
4667
                e1_AST = astFactory->create(CONSTANT,"CONST_IX");
 
4668
                e1_AST->ResetCData( c1);
 
4669
                e1_AST->SetLine( e1Line);
 
4670
                }
 
4671
                
4643
4672
                {
4644
4673
                if (_t == RefDNode(antlr::nullAST) )
4645
4674
                        _t = ASTNULL;
4648
4677
                {
4649
4678
                        arrayindex_AST = RefDNode(currentAST.root);
4650
4679
                        
4651
 
                        c1 = comp.Constant( e1); 
 
4680
                        bool    constantOK = false;
 
4681
                        
4652
4682
                        if( c1 != NULL)
4653
 
                        {   
 
4683
                        {    
 
4684
                        DType dType = c1->Type();
 
4685
                        int typeCheck = DTypeOrder[ dType];
 
4686
                        if( dType == GDL_STRING || typeCheck >= 100)
 
4687
                        {
 
4688
                        //delete c1;
 
4689
                        }
 
4690
                        else
 
4691
                        {
 
4692
                        
 
4693
                        try {
 
4694
                        // ATTENTION: These two grab c1 (all others don't)
 
4695
                        // a bit unclean, but for maximum efficiency
4654
4696
                        if( c1->Rank() == 0)
4655
 
                        
4656
 
                        ixList->
4657
 
                        push_back( new 
4658
 
                        CArrayIndexScalar( c1));
4659
 
                        else
4660
 
                        ixList->
4661
 
                        push_back( new 
4662
 
                        CArrayIndexIndexed( c1));
4663
 
                        }
4664
 
                        else
 
4697
                        ixList->push_back( new CArrayIndexScalar( c1));
 
4698
                        else
 
4699
                        ixList->push_back( new CArrayIndexIndexed( c1));
 
4700
                        
 
4701
                        // prevent c1 from being deleted
 
4702
                        e1_AST->StealCData(); // ok, as #e1 is not used anymore
 
4703
                        
 
4704
                        constantOK = true;
 
4705
                        }
 
4706
                        catch( GDLException& e) {
 
4707
                        //delete c1; // owned by #e1
 
4708
                        }  
 
4709
                        }
 
4710
                        }
 
4711
                        
 
4712
                        if( !constantOK)
4665
4713
                        {
4666
4714
                        if( LoopVar( e1_AST))
 
4715
                        {
4667
4716
                        if( e1_AST->getType() == VAR)
4668
 
                        ixList->push_back( new 
4669
 
                        ArrayIndexScalar( e1_AST));
 
4717
                        ixList->push_back( new ArrayIndexScalar( e1_AST));
4670
4718
                        else
4671
 
                        ixList->push_back( new 
4672
 
                        ArrayIndexScalarVP( e1_AST));
 
4719
                        ixList->push_back( new ArrayIndexScalarVP( e1_AST));
 
4720
                        }
4673
4721
                        else
4674
4722
                        {
4675
4723
                        arrayindex_AST = e1_AST;
4676
 
                        ixList->push_back( new 
4677
 
                        ArrayIndexIndexed());
 
4724
                        ixList->push_back( new ArrayIndexIndexed());
4678
4725
                        }
4679
4726
                        }
4680
4727
                        
4703
4750
                        {
4704
4751
                                arrayindex_AST = RefDNode(currentAST.root);
4705
4752
                                
4706
 
                                c1 = comp.Constant( e1); 
 
4753
                                //c1 = comp.ConstantIndex( #e1); 
4707
4754
                                if( c1 != NULL)
4708
4755
                                {
4709
4756
                                ixList->push_back( new CArrayIndexORange( c1));
4727
4774
                        case ARRAYDEF:
4728
4775
                        case ARRAYDEF_CONST:
4729
4776
                        case ARRAYEXPR:
4730
 
                        case ARRAYEXPR_FN:
 
4777
                        case ARRAYEXPR_FCALL:
4731
4778
                        case ARRAYEXPR_MFCALL:
4732
4779
                        case CONSTANT:
4733
4780
                        case DEREF:
4734
4781
                        case EXPR:
4735
4782
                        case FCALL:
 
4783
                        case GDLNULL:
4736
4784
                        case MFCALL:
4737
4785
                        case MFCALL_PARENT:
4738
4786
                        case NSTRUC_REF:
4793
4841
                                expr(_t);
4794
4842
                                _t = _retTree;
4795
4843
                                e2_AST = returnAST;
 
4844
                                
 
4845
                                // in ConstantIndex the cData of all nodes is stolen
 
4846
                                // (in case it succeeds)
 
4847
                                // therefore we build here the new constant node with
 
4848
                                // proper cData. This is crucial because if e. g. only e1 but not e2
 
4849
                                // is constant, #e1 is put to the output tree (with stolen cData) -> crash
 
4850
                                c2 = comp.ConstantIndex( e2_AST);
 
4851
                                if( c2 != NULL)
 
4852
                                {    
 
4853
                                int e2Line = e2_AST->getLine();
 
4854
                                e2_AST = astFactory->create(CONSTANT,"CONST_IX");
 
4855
                                e2_AST->ResetCData( c2);
 
4856
                                e2_AST->SetLine( e2Line);
 
4857
                                }
 
4858
                                
4796
4859
                                arrayindex_AST = RefDNode(currentAST.root);
4797
4860
                                
4798
 
                                c1 = comp.Constant( e1); 
4799
 
                                c2 = comp.Constant( e2); 
 
4861
                                //c1 = comp.ConstantIndex( #e1); 
 
4862
                                //c2 = comp.ConstantIndex( #e2); 
4800
4863
                                if( c1 != NULL && c2 != NULL)
4801
4864
                                {
4802
4865
                                ixList->push_back( new 
4804
4867
                                }
4805
4868
                                else
4806
4869
                                {
 
4870
                                //delete c1;
 
4871
                                //delete c2;
4807
4872
                                arrayindex_AST = RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(NULL))->add(antlr::RefAST(e1_AST))->add(antlr::RefAST(e2_AST))));
4808
4873
                                ixList->push_back( new 
4809
4874
                                ArrayIndexORangeS());
4830
4895
                case ARRAYDEF:
4831
4896
                case ARRAYDEF_CONST:
4832
4897
                case ARRAYEXPR:
4833
 
                case ARRAYEXPR_FN:
 
4898
                case ARRAYEXPR_FCALL:
4834
4899
                case ARRAYEXPR_MFCALL:
4835
4900
                case CONSTANT:
4836
4901
                case DEREF:
4837
4902
                case EXPR:
4838
4903
                case FCALL:
 
4904
                case GDLNULL:
4839
4905
                case MFCALL:
4840
4906
                case MFCALL_PARENT:
4841
4907
                case NSTRUC_REF:
4896
4962
                        expr(_t);
4897
4963
                        _t = _retTree;
4898
4964
                        e3_AST = returnAST;
 
4965
                        
 
4966
                        // see above (#e2)
 
4967
                        c3 = comp.ConstantIndex( e3_AST);
 
4968
                        if( c3 != NULL)
 
4969
                        {    
 
4970
                        int e3Line = e3_AST->getLine();
 
4971
                        e3_AST = astFactory->create(CONSTANT,"CONST_IX");
 
4972
                        e3_AST->ResetCData( c3);
 
4973
                        e3_AST->SetLine( e3Line);
 
4974
                        }
 
4975
                        
4899
4976
                        {
4900
4977
                        if (_t == RefDNode(antlr::nullAST) )
4901
4978
                                _t = ASTNULL;
4904
4981
                        {
4905
4982
                                arrayindex_AST = RefDNode(currentAST.root);
4906
4983
                                
4907
 
                                c1 = comp.Constant( e1); 
4908
 
                                c3 = comp.Constant( e3); 
 
4984
                                //c1 = comp.ConstantIndex( #e1); 
 
4985
                                //c3 = comp.ConstantIndex( #e3); 
4909
4986
                                if( c1 != NULL && c3 != NULL)
4910
4987
                                {
4911
4988
                                ixList->push_back( new 
4913
4990
                                }
4914
4991
                                else
4915
4992
                                {
 
4993
                                //delete c1;
 
4994
                                //delete c3;
4916
4995
                                arrayindex_AST = RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(NULL))->add(antlr::RefAST(e1_AST))->add(antlr::RefAST(e3_AST))));
4917
4996
                                ixList->push_back( new ArrayIndexRange());
4918
4997
                                }
4930
5009
                        case ARRAYDEF:
4931
5010
                        case ARRAYDEF_CONST:
4932
5011
                        case ARRAYEXPR:
4933
 
                        case ARRAYEXPR_FN:
 
5012
                        case ARRAYEXPR_FCALL:
4934
5013
                        case ARRAYEXPR_MFCALL:
4935
5014
                        case CONSTANT:
4936
5015
                        case DEREF:
4937
5016
                        case EXPR:
4938
5017
                        case FCALL:
 
5018
                        case GDLNULL:
4939
5019
                        case MFCALL:
4940
5020
                        case MFCALL_PARENT:
4941
5021
                        case NSTRUC_REF:
4996
5076
                                expr(_t);
4997
5077
                                _t = _retTree;
4998
5078
                                e4_AST = returnAST;
 
5079
                                
 
5080
                                // see above (#e2)
 
5081
                                c4 = comp.ConstantIndex( e4_AST);
 
5082
                                if( c4 != NULL)
 
5083
                                {    
 
5084
                                int e4Line = e4_AST->getLine();
 
5085
                                e4_AST = astFactory->create(CONSTANT,"CONST_IX");
 
5086
                                e4_AST->ResetCData( c4);
 
5087
                                e4_AST->SetLine( e4Line);
 
5088
                                }
 
5089
                                
4999
5090
                                arrayindex_AST = RefDNode(currentAST.root);
5000
5091
                                
5001
 
                                c1 = comp.Constant( e1); 
5002
 
                                c3 = comp.Constant( e3); 
5003
 
                                c4 = comp.Constant( e4); 
 
5092
                                //c1 = comp.ConstantIndex( #e1); 
 
5093
                                //c3 = comp.ConstantIndex( #e3); 
 
5094
                                //c4 = comp.ConstantIndex( #e4); 
5004
5095
                                if( c1 != NULL && c3 != NULL && c4 != NULL)
5005
5096
                                {
5006
5097
                                ixList->push_back( new CArrayIndexRangeS( c1, c3, c4));
5007
5098
                                }
5008
5099
                                else
5009
5100
                                {
 
5101
                                //delete c1;
 
5102
                                //delete c3;
 
5103
                                //delete c4;
5010
5104
                                arrayindex_AST = RefDNode(astFactory->make((new antlr::ASTArray(4))->add(antlr::RefAST(NULL))->add(antlr::RefAST(e1_AST))->add(antlr::RefAST(e3_AST))->add(antlr::RefAST(e4_AST))));
5011
5105
                                ixList->push_back( new ArrayIndexRangeS());
5012
5106
                                }
5386
5480
        RefDNode va_AST = RefDNode(antlr::nullAST);
5387
5481
        RefDNode id = RefDNode(antlr::nullAST);
5388
5482
        RefDNode id_AST = RefDNode(antlr::nullAST);
5389
 
        RefDNode al_AST = RefDNode(antlr::nullAST);
5390
 
        RefDNode al = RefDNode(antlr::nullAST);
5391
5483
        RefDNode el_AST = RefDNode(antlr::nullAST);
5392
5484
        RefDNode el = RefDNode(antlr::nullAST);
5393
5485
        
5394
5486
        std::string id_text;
5395
5487
        bool isVar;
 
5488
        RefDNode mark, va2, vaAlt, fn, arrayindex_listAST;
5396
5489
        
5397
5490
        
5398
5491
        RefDNode __t153 = _t;
5402
5495
        antlr::ASTPair __currentAST153 = currentAST;
5403
5496
        currentAST.root = currentAST.child;
5404
5497
        currentAST.child = RefDNode(antlr::nullAST);
5405
 
        match(antlr::RefAST(_t),ARRAYEXPR_FN);
 
5498
        match(antlr::RefAST(_t),ARRAYEXPR_FCALL);
5406
5499
        _t = _t->getFirstChild();
5407
5500
        RefDNode __t154 = _t;
5408
5501
        va = (_t == RefDNode(ASTNULL)) ? RefDNode(antlr::nullAST) : _t;
5422
5515
        _t = __t154;
5423
5516
        _t = _t->getNextSibling();
5424
5517
        
5425
 
        id_text=id_AST->getText(); 
5426
 
        
5427
 
        // IsVar already tries to find the function and compile it
5428
 
        isVar = comp.IsVar( id_text);
5429
 
        
5430
 
        int i=-1;
5431
 
        if( !isVar)
5432
 
        i=LibFunIx(id_text);
 
5518
        mark = _t;
 
5519
        
 
5520
        id_text = id_AST->getText(); 
 
5521
        
 
5522
        // IsVar is not needed, we must emit an ARRAYEXPR_FCALL even if the variable is known
 
5523
        // (rule: Accessible functions always override variables
 
5524
        //isVar = comp.IsVar( id_text); 
 
5525
        // isVar == true -> VAR for sure 
 
5526
        // (== false: maybe VAR nevertheless)
 
5527
        
 
5528
        int libIx = LibFunIx(id_text);
 
5529
        
5433
5530
        
5434
5531
        {
5435
 
        if (_t == RefDNode(antlr::nullAST) )
5436
 
                _t = ASTNULL;
5437
 
        if (((_t->getType() == ARRAYIX))&&( isVar)) {
5438
 
                al = (_t == ASTNULL) ? RefDNode(antlr::nullAST) : _t;
5439
 
                arrayindex_list(_t);
5440
 
                _t = _retTree;
5441
 
                al_AST = returnAST;
5442
 
        }
5443
 
        else if ((_t->getType() == ARRAYIX)) {
5444
 
                el = (_t == ASTNULL) ? RefDNode(antlr::nullAST) : _t;
5445
 
                arrayindex_list_to_parameter_list(_t, i != -1 && libFunList[ i]->NPar() == -1);
5446
 
                _t = _retTree;
5447
 
                el_AST = returnAST;
5448
 
        }
5449
 
        else {
5450
 
                throw antlr::NoViableAltException(antlr::RefAST(_t));
5451
 
        }
5452
 
        
 
5532
        el = (_t == ASTNULL) ? RefDNode(antlr::nullAST) : _t;
 
5533
        arrayindex_list_to_parameter_list(_t, libIx != -1 && libFunList[ libIx]->NPar() == -1);
 
5534
        _t = _retTree;
 
5535
        el_AST = returnAST;
5453
5536
        }
5454
5537
        arrayexpr_fn_AST = RefDNode(currentAST.root);
5455
5538
        
5456
 
        if( !isVar)
5457
 
        {   // no variable -> function call
5458
 
        
5459
5539
        // first search library functions
5460
 
        int i=LibFunIx(id_text);
5461
 
        if( i != -1)
 
5540
        if( libIx != -1)
5462
5541
        {
5463
5542
        int nParam = 0;
5464
5543
        if( el_AST != RefDNode(antlr::nullAST))
5465
5544
        nParam = el_AST->GetNParam();
5466
5545
        
5467
 
        int libParam = libFunList[i]->NPar();
 
5546
        int libParam = libFunList[libIx]->NPar();
 
5547
        int libParamMin = libFunList[libIx]->NParMin();
5468
5548
        if( libParam != -1 && nParam > libParam)
5469
 
        throw GDLException(     aIn, libFunList[i]->Name() + ": Too many arguments.");
 
5549
        throw GDLException(     aIn, libFunList[libIx]->Name() + ": Too many arguments.");
 
5550
        if( libParam != -1 && nParam < libParamMin)
 
5551
        throw GDLException(     aIn, libFunList[libIx]->Name() + ": Too few arguments.");
5470
5552
        
5471
 
        id_AST->SetLibFun( libFunList[i]);
5472
 
        if( libFunList[ i]->RetNew())
 
5553
        id_AST->SetLibFun( libFunList[libIx]);
 
5554
        if( libFunList[ libIx]->RetNew())
5473
5555
        {
 
5556
        if( libFunList[ libIx]->Name() == "N_ELEMENTS")
 
5557
        id_AST->setType( FCALL_LIB_N_ELEMENTS);
 
5558
        else if( libFunList[ libIx]->DirectCall())
 
5559
        id_AST->setType( FCALL_LIB_DIRECT);
 
5560
        else
5474
5561
        id_AST->setType( FCALL_LIB_RETNEW);
5475
 
        arrayexpr_fn_AST =
5476
 
        RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
 
5562
        arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5477
5563
        //                              #([/*FCALL_LIB_RETNEW,"fcall_lib_retnew"],*/ id, el);
5478
5564
        }
5479
5565
        else
5480
5566
        {
5481
5567
        id_AST->setType( FCALL_LIB);
5482
 
        arrayexpr_fn_AST =
5483
 
        RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
 
5568
        arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5484
5569
        //                              #(/*[FCALL_LIB,"fcall_lib"],*/ id, el);
5485
5570
        }
5486
5571
        }
5487
 
        else
5488
 
        {
5489
5572
        // then search user defined functions
 
5573
        else
 
5574
        {
 
5575
        
 
5576
        int funIx=FunIx( id_text);
 
5577
        
 
5578
        // we use #id for the FCALL part
5490
5579
        id_AST->setType( FCALL);
5491
 
        i=FunIx(id_text);
5492
 
        id_AST->SetFunIx(i);
5493
 
        
5494
 
        arrayexpr_fn_AST=
5495
 
        RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));
5496
 
        //                        #(/*[FCALL,"fcall"],*/ id, el);
5497
 
        }
5498
 
        }
5499
 
        else
5500
 
        {   // variable -> arrayexpr
5501
 
        
5502
 
        // make var
5503
 
        va_AST=astFactory->create(VAR,id_AST->getText());
5504
 
        //                    #va=#[VAR,id->getText()];
5505
 
        comp.Var(va_AST);       
5506
 
        
5507
 
        arrayexpr_fn_AST=
5508
 
        RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(astFactory->create(ARRAYEXPR,"arrayexpr")))->add(antlr::RefAST(va_AST))->add(antlr::RefAST(al_AST))));
5509
 
        }
 
5580
        id_AST->SetFunIx( funIx);
 
5581
        
 
5582
        if( funIx != -1) // found -> FCALL
 
5583
        {
 
5584
        arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST)))); 
 
5585
        // #(/*[FCALL,"fcall"],*/ id, el);
 
5586
        }
 
5587
        else // function not found -> still ambiguous
 
5588
        {
 
5589
        // _t = mark; // rewind to parse again 
 
5590
        arrayindex_list( mark);
 
5591
        //_t = _retTree;
 
5592
        arrayindex_listAST = returnAST;
 
5593
        
 
5594
        
 
5595
        va2=astFactory->create( VAR, id_text);
 
5596
        // #va=#[VAR,id->getText()];
 
5597
        comp.Var( va2); // we declare the variable here!
 
5598
        // if IsVar() still would be used this would lead to surprising behavior: 
 
5599
        // e. g.: function_call(42) & function_call(43)  
 
5600
        // The first (42) would be an ARRAYEXPR_FCALL the 2nd (43) an ARRAYEXPR
 
5601
        // if then at runtime function "function_call" is known,
 
5602
        // it will be called only at the first appearance of the call.
 
5603
        // that's why we cannot allow unambiguous VAR here 
 
5604
        
 
5605
        vaAlt = RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(astFactory->create(ARRAYEXPR,"arrayexpr")))->add(antlr::RefAST(va2))->add(antlr::RefAST(arrayindex_listAST))));
 
5606
        fn = RefDNode(astFactory->make((new antlr::ASTArray(2))->add(antlr::RefAST(id_AST))->add(antlr::RefAST(el_AST))));    
 
5607
        
 
5608
        arrayexpr_fn_AST = RefDNode(astFactory->make((new antlr::ASTArray(3))->add(antlr::RefAST(aIn_AST))->add(antlr::RefAST(vaAlt))->add(antlr::RefAST(fn)))); 
 
5609
        }
 
5610
        }
 
5611
        
 
5612
        //                 // not valid s. a. (kept for reference): unambiguous VAR
 
5613
        //                 {   // variable -> arrayexpr                    
 
5614
        //                     // make var
 
5615
        //                     #va=astFactory->create(VAR,#id->getText());
 
5616
        // //                    #va=#[VAR,id->getText()];
 
5617
        //                     comp.Var(#va);
 
5618
        //                     #arrayexpr_fn=
 
5619
        //                     #([ARRAYEXPR,"arrayexpr"], va, al);
 
5620
        //                 }
5510
5621
        
5511
5622
        currentAST.root = arrayexpr_fn_AST;
5512
5623
        if ( arrayexpr_fn_AST!=RefDNode(antlr::nullAST) &&
5645
5756
        RefDNode id_AST = RefDNode(antlr::nullAST);
5646
5757
        RefDNode p_AST = RefDNode(antlr::nullAST);
5647
5758
        RefDNode p = RefDNode(antlr::nullAST);
 
5759
        RefDNode g = RefDNode(antlr::nullAST);
 
5760
        RefDNode g_AST = RefDNode(antlr::nullAST);
5648
5761
        
5649
5762
        int dummy;
5650
5763
        RefDNode mark;
5810
5923
                nParam = p_AST->GetNParam();
5811
5924
                
5812
5925
                int libParam = libFunList[i]->NPar();
 
5926
                int libParamMin = libFunList[i]->NParMin();
5813
5927
                if( libParam != -1 && nParam > libParam)
5814
5928
                throw GDLException(     f, libFunList[i]->Name() + ": Too many arguments.");
 
5929
                if( libParam != -1 && nParam < libParamMin)
 
5930
                throw GDLException(     f, libFunList[i]->Name() + ": Too few arguments.");
5815
5931
                if( libFunList[ i]->RetNew())
5816
5932
                {
5817
 
                
 
5933
                if( libFunList[ i]->Name() == "N_ELEMENTS")
 
5934
                f_AST->setType( FCALL_LIB_N_ELEMENTS);
 
5935
                else if( libFunList[ i]->DirectCall())
 
5936
                f_AST->setType( FCALL_LIB_DIRECT);
 
5937
                else
5818
5938
                f_AST->setType(FCALL_LIB_RETNEW);
5819
5939
                f_AST->setText(id_AST->getText());
5820
5940
                f_AST->SetLibFun( libFunList[i]);
5844
5964
                primary_expr_AST = RefDNode(currentAST.root);
5845
5965
                break;
5846
5966
        }
5847
 
        case ARRAYEXPR_FN:
 
5967
        case ARRAYEXPR_FCALL:
5848
5968
        {
5849
5969
                arrayexpr_fn(_t);
5850
5970
                _t = _retTree;
5882
6002
                primary_expr_AST = RefDNode(currentAST.root);
5883
6003
                break;
5884
6004
        }
 
6005
        case GDLNULL:
 
6006
        {
 
6007
                g = _t;
 
6008
                RefDNode g_AST_in = RefDNode(antlr::nullAST);
 
6009
                g_AST = astFactory->create(antlr::RefAST(g));
 
6010
                astFactory->addASTChild(currentAST, antlr::RefAST(g_AST));
 
6011
                match(antlr::RefAST(_t),GDLNULL);
 
6012
                _t = _t->getNextSibling();
 
6013
                
 
6014
                g_AST->setType(SYSVAR);
 
6015
                g_AST->setText("NULL");
 
6016
                comp.SysVar(g_AST); // sets var to NULL
 
6017
                
 
6018
                primary_expr_AST = RefDNode(currentAST.root);
 
6019
                break;
 
6020
        }
5885
6021
        default:
5886
6022
        {
5887
6023
                throw antlr::NoViableAltException(antlr::RefAST(_t));
6596
6732
        case ASSIGN:
6597
6733
        case ARRAYDEF:
6598
6734
        case ARRAYDEF_CONST:
6599
 
        case ARRAYEXPR_FN:
 
6735
        case ARRAYEXPR_FCALL:
6600
6736
        case ARRAYEXPR_MFCALL:
6601
6737
        case CONSTANT:
6602
6738
        case FCALL:
 
6739
        case GDLNULL:
6603
6740
        case MFCALL:
6604
6741
        case MFCALL_PARENT:
6605
6742
        case NSTRUC_REF:
7060
7197
 
7061
7198
void GDLTreeParser::initializeASTFactory( antlr::ASTFactory& factory )
7062
7199
{
7063
 
        factory.setMaxNodeType(231);
 
7200
        factory.setMaxNodeType(234);
7064
7201
}
7065
7202
const char* GDLTreeParser::tokenNames[] = {
7066
7203
        "<0>",
7081
7218
        "ARRAYIX_ORANGE_S",
7082
7219
        "ARRAYIX_RANGE_S",
7083
7220
        "ARRAYEXPR",
7084
 
        "ARRAYEXPR_FN",
 
7221
        "ARRAYEXPR_FCALL",
7085
7222
        "ARRAYEXPR_MFCALL",
7086
7223
        "BLOCK",
7087
7224
        "BREAK",
7103
7240
        "FOREACH_INDEX_LOOP",
7104
7241
        "FCALL",
7105
7242
        "FCALL_LIB",
 
7243
        "FCALL_LIB_DIRECT",
 
7244
        "FCALL_LIB_N_ELEMENTS",
7106
7245
        "FCALL_LIB_RETNEW",
 
7246
        "GDLNULL",
7107
7247
        "IF_ELSE",
7108
7248
        "KEYDECL",
7109
7249
        "KEYDEF",
7298
7438
        0
7299
7439
};
7300
7440
 
7301
 
const unsigned long GDLTreeParser::_tokenSet_0_data_[] = { 1135607840UL, 268632065UL, 35661824UL, 18884864UL, 4194302UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
 
7441
const unsigned long GDLTreeParser::_tokenSet_0_data_[] = { 1135607840UL, 2149056513UL, 285294592UL, 151078912UL, 33554416UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
7302
7442
// ASSIGN BLOCK BREAK CONTINUE COMMONDECL COMMONDEF "for" "foreach" MPCALL 
7303
7443
// MPCALL_PARENT PCALL "repeat" RETURN "while" "case" "forward_function" 
7304
7444
// "goto" "if" "on_ioerror" "switch" DEC INC AND_OP_EQ ASTERIX_EQ EQ_OP_EQ 
7306
7446
// MATRIX_OP2_EQ MINUS_EQ MOD_OP_EQ NE_OP_EQ OR_OP_EQ PLUS_EQ POW_EQ SLASH_EQ 
7307
7447
// XOR_OP_EQ 
7308
7448
const antlr::BitSet GDLTreeParser::_tokenSet_0(_tokenSet_0_data_,12);
7309
 
const unsigned long GDLTreeParser::_tokenSet_1_data_[] = { 739116576UL, 69468224UL, 9371654UL, 139433088UL, 37748734UL, 0UL, 1048256UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
7310
 
// ASSIGN ARRAYDEF ARRAYDEF_CONST ARRAYEXPR ARRAYEXPR_FN ARRAYEXPR_MFCALL 
7311
 
// CONSTANT DEREF EXPR FCALL MFCALL MFCALL_PARENT NSTRUC_REF POSTDEC POSTINC 
7312
 
// STRUC SYSVAR UMINUS VAR "and" "eq" "ge" "gt" "le" "lt" "mod" "ne" "not" 
7313
 
// "or" "xor" DEC INC AND_OP_EQ ASTERIX_EQ EQ_OP_EQ GE_OP_EQ GTMARK_EQ 
7314
 
// GT_OP_EQ LE_OP_EQ LTMARK_EQ LT_OP_EQ MATRIX_OP1_EQ MATRIX_OP2_EQ MINUS_EQ 
7315
 
// MOD_OP_EQ NE_OP_EQ OR_OP_EQ PLUS_EQ POW_EQ SLASH_EQ XOR_OP_EQ SLASH 
7316
 
// ASTERIX DOT POW MATRIX_OP1 MATRIX_OP2 PLUS MINUS LTMARK GTMARK LOG_NEG 
7317
 
// LOG_AND LOG_OR QUESTION 
 
7449
const unsigned long GDLTreeParser::_tokenSet_1_data_[] = { 739116576UL, 555747392UL, 74973232UL, 1115464704UL, 301989872UL, 0UL, 8386048UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL };
 
7450
// ASSIGN ARRAYDEF ARRAYDEF_CONST ARRAYEXPR ARRAYEXPR_FCALL ARRAYEXPR_MFCALL 
 
7451
// CONSTANT DEREF EXPR FCALL GDLNULL MFCALL MFCALL_PARENT NSTRUC_REF POSTDEC 
 
7452
// POSTINC STRUC SYSVAR UMINUS VAR "and" "eq" "ge" "gt" "le" "lt" "mod" 
 
7453
// "ne" "not" "or" "xor" DEC INC AND_OP_EQ ASTERIX_EQ EQ_OP_EQ GE_OP_EQ 
 
7454
// GTMARK_EQ GT_OP_EQ LE_OP_EQ LTMARK_EQ LT_OP_EQ MATRIX_OP1_EQ MATRIX_OP2_EQ 
 
7455
// MINUS_EQ MOD_OP_EQ NE_OP_EQ OR_OP_EQ PLUS_EQ POW_EQ SLASH_EQ XOR_OP_EQ 
 
7456
// SLASH ASTERIX DOT POW MATRIX_OP1 MATRIX_OP2 PLUS MINUS LTMARK GTMARK 
 
7457
// LOG_NEG LOG_AND LOG_OR QUESTION 
7318
7458
const antlr::BitSet GDLTreeParser::_tokenSet_1(_tokenSet_1_data_,16);
7319
7459
 
7320
7460