Exemple #1
0
 public CLIPSParser(Rete.Rete eng, Stream stream)
 {
     mcc_input_stream = new SimpleCharStream(stream, 1, 1);
     token_source = new CLIPSParserTokenManager(mcc_input_stream);
     token = new Token();
     mcc_ntk = -1;
     mcc_gen = 0;
     for (int i = 0; i < 63; i++) mcc_la1[i] = -1;
     for (int i = 0; i < mcc_2_rtns.Length; i++) mcc_2_rtns[i] = new MccCalls();
     engine = eng;
 }
Exemple #2
0
 public void close()
 {
     engine = null;
     if (token != null)
     {
         token.Clear();
         token = null;
     }
     if (jj_nt != null)
     {
         jj_nt.Clear();
         jj_nt = null;
     }
     if (jj_scanpos != null)
     {
         jj_scanpos.Clear();
         jj_scanpos = null;
     }
     if (jj_lastpos != null)
     {
         jj_lastpos.Clear();
         jj_lastpos = null;
     }
     try
     {
         mcc_input_stream.inputStream.Close();
     }
     catch (IOException e)
     {
         // later on log the error
     }
 }
Exemple #3
0
 private bool mcc_scan_token(int kind)
 {
     if (mcc_scanpos == mcc_lastpos)
     {
         mcc_la--;
         if (mcc_scanpos.next == null)
         {
             mcc_lastpos = mcc_scanpos = mcc_scanpos.next = token_source.GetNextToken();
         }
         else
         {
             mcc_lastpos = mcc_scanpos = mcc_scanpos.next;
         }
     }
     else
     {
         mcc_scanpos = mcc_scanpos.next;
     }
     if (mcc_rescan)
     {
         int i = 0;
         Token tok = token;
         while (tok != null && tok != mcc_scanpos)
         {
             i++;
             tok = tok.next;
         }
         if (tok != null) mcc_add_error_token(kind, i);
     }
     if (mcc_scanpos.kind != kind) return true;
     if (mcc_la == 0 && mcc_scanpos == mcc_lastpos) throw mcc_ls;
     return false;
 }
Exemple #4
0
 private int mcc_mntk()
 {
     if ((mcc_nt = token.next) == null)
         return (mcc_ntk = (token.next = token_source.GetNextToken()).kind);
     else
         return (mcc_ntk = mcc_nt.kind);
 }
Exemple #5
0
 private void mcc_rescan_token()
 {
     mcc_rescan = true;
     for (int i = 0; i < 42; i++)
     {
         MccCalls p = mcc_2_rtns[i];
         do
         {
             if (p.gen > mcc_gen)
             {
                 mcc_la = p.arg;
                 mcc_lastpos = mcc_scanpos = p.first;
                 switch (i)
                 {
                     case 0:
                         mcc_3_1();
                         break;
                     case 1:
                         mcc_3_2();
                         break;
                     case 2:
                         mcc_3_3();
                         break;
                     case 3:
                         mcc_3_4();
                         break;
                     case 4:
                         mcc_3_5();
                         break;
                     case 5:
                         mcc_3_6();
                         break;
                     case 6:
                         mcc_3_7();
                         break;
                     case 7:
                         mcc_3_8();
                         break;
                     case 8:
                         mcc_3_9();
                         break;
                     case 9:
                         mcc_3_10();
                         break;
                     case 10:
                         mcc_3_11();
                         break;
                     case 11:
                         mcc_3_12();
                         break;
                     case 12:
                         mcc_3_13();
                         break;
                     case 13:
                         mcc_3_14();
                         break;
                     case 14:
                         mcc_3_15();
                         break;
                     case 15:
                         mcc_3_16();
                         break;
                     case 16:
                         mcc_3_17();
                         break;
                     case 17:
                         mcc_3_18();
                         break;
                     case 18:
                         mcc_3_19();
                         break;
                     case 19:
                         mcc_3_20();
                         break;
                     case 20:
                         mcc_3_21();
                         break;
                     case 21:
                         mcc_3_22();
                         break;
                     case 22:
                         mcc_3_23();
                         break;
                     case 23:
                         mcc_3_24();
                         break;
                     case 24:
                         mcc_3_25();
                         break;
                     case 25:
                         mcc_3_26();
                         break;
                     case 26:
                         mcc_3_27();
                         break;
                     case 27:
                         mcc_3_28();
                         break;
                     case 28:
                         mcc_3_29();
                         break;
                     case 29:
                         mcc_3_30();
                         break;
                     case 30:
                         mcc_3_31();
                         break;
                     case 31:
                         mcc_3_32();
                         break;
                     case 32:
                         mcc_3_33();
                         break;
                     case 33:
                         mcc_3_34();
                         break;
                     case 34:
                         mcc_3_35();
                         break;
                     case 35:
                         mcc_3_36();
                         break;
                     case 36:
                         mcc_3_37();
                         break;
                     case 37:
                         mcc_3_38();
                         break;
                     case 38:
                         mcc_3_39();
                         break;
                     case 39:
                         mcc_3_40();
                         break;
                     case 40:
                         mcc_3_41();
                         break;
                     case 41:
                         mcc_3_42();
                         break;
                 }
             }
             p = p.next;
         } while (p != null);
     }
     mcc_rescan = false;
 }
Exemple #6
0
 private bool mcc_3_42()
 {
     if (mcc_scan_token(TILDA)) return true;
     Token xsp;
     xsp = mcc_scanpos;
     if (mcc_scan_token(14))
     {
         mcc_scanpos = xsp;
         if (mcc_scan_token(11))
         {
             mcc_scanpos = xsp;
             if (mcc_scan_token(12)) return true;
         }
     }
     return false;
 }
Exemple #7
0
 private Token mcc_consume_token(int kind)
 {
     Token oldToken = null;
     if ((oldToken = token).next != null) token = token.next;
     else token = token.next = token_source.GetNextToken();
     mcc_ntk = -1;
     if (token.kind == kind)
     {
         mcc_gen++;
         if (++mcc_gc > 100)
         {
             mcc_gc = 0;
             for (int i = 0; i < mcc_2_rtns.Length; i++)
             {
                 MccCalls c = mcc_2_rtns[i];
                 while (c != null)
                 {
                     if (c.gen < mcc_gen) c.first = null;
                     c = c.next;
                 }
             }
         }
         return token;
     }
     token = oldToken;
     mcc_kind = kind;
     throw GenerateParseException();
 }
Exemple #8
0
 private bool mcc_2_9(int xla)
 {
     mcc_la = xla;
     mcc_lastpos = mcc_scanpos = token;
     try
     {
         return !mcc_3_9();
     }
     catch (LookaheadSuccess)
     {
         return true;
     }
     finally
     {
         mcc_save(8, xla);
     }
 }
Exemple #9
0
 private bool mcc_3_32()
 {
     Token xsp;
     xsp = mcc_scanpos;
     if (mcc_scan_token(14))
     {
         mcc_scanpos = xsp;
         if (mcc_scan_token(11))
         {
             mcc_scanpos = xsp;
             if (mcc_scan_token(12))
             {
                 mcc_scanpos = xsp;
                 if (mcc_scan_token(15)) return true;
             }
         }
     }
     if (mcc_scan_token(AND2)) return true;
     return false;
 }
Exemple #10
0
 public void ReInit(CLIPSParserTokenManager tm)
 {
     token_source = tm;
     token = new Token();
     mcc_ntk = -1;
     mcc_gen = 0;
     for (int i = 0; i < 63; i++) mcc_la1[i] = -1;
     for (int i = 0; i < mcc_2_rtns.Length; i++) mcc_2_rtns[i] = new MccCalls();
 }
Exemple #11
0
 public void ReInit(TextReader stream)
 {
     mcc_input_stream.ReInit(stream, 1, 1);
     token_source.ReInit(mcc_input_stream);
     token = new Token();
     mcc_ntk = -1;
     mcc_gen = 0;
     for (int i = 0; i < 63; i++) mcc_la1[i] = -1;
     for (int i = 0; i < mcc_2_rtns.Length; i++) mcc_2_rtns[i] = new MccCalls();
 }
Exemple #12
0
        public void propertyType(ArrayList list, Token identifier)
        {
            Token id = null;
            Object body = null;
            Token body2 = null;
            bool bval = false;
            LiteralConstraint vc;
            BoundConstraint bc;
            OrLiteralConstraint orc;
            AndLiteralConstraint andc;
            ArrayList andor = new ArrayList();
            MultiValue mv = null;
            if (mcc_2_26(2147483647))
            {
                predicateFunc(list, identifier);
            }
            else if (mcc_2_27(2147483647))
            {
                body2 = mcc_consume_token(BIND4);
                if (body2 != null)
                {
                    bc = new BoundConstraint();
                    bc.Name = identifier.image;
                    bc.Value = body2.image.Substring(2);
                    bc.IsMultislot = true;
                    list.Add(bc);
                }
            }
            else if (mcc_2_28(2147483647))
            {
                body2 = mcc_consume_token(BIND);
                if (body2 != null)
                {
                    bc = new BoundConstraint();
                    bc.Name = identifier.image;
                    bc.Value = body2.image.Substring(1);
                    list.Add(bc);
                }
            }
            else if (mcc_2_29(2147483647))
            {
                mcc_consume_token(TILDA);
                body2 = mcc_consume_token(BIND);
                if (body2 != null)
                {
                    bc = new BoundConstraint();
                    bc.Name = identifier.image;
                    bc.Value = body2.image.Substring(1);
                    bc.Negated = true;
                    list.Add(bc);
                }
            }
            else if (mcc_2_30(2147483647))
            {
                body = typeExpr();
                while (true)
                {
                    mcc_consume_token(OR2);
                    orType(andor);
                    switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                    {
                        case OR2:
                            ;
                            break;
                        default:
                            mcc_la1[51] = mcc_gen;
                            goto label_25;
                    }
                }
                label_25:
                ;

                if (body != null)
                {
                    orc = new OrLiteralConstraint();
                    orc.Name = identifier.image;
                    mv = new MultiValue(body);
                    orc.addValue(mv);
                    orc.addValues(andor);
                    list.Add(orc);
                }
            }
            else if (mcc_2_31(2147483647))
            {
                mcc_consume_token(TILDA);
                body = typeExpr();
                while (true)
                {
                    mcc_consume_token(OR2);
                    orType(andor);
                    switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                    {
                        case OR2:
                            ;
                            break;
                        default:
                            mcc_la1[52] = mcc_gen;
                            goto label_26;
                    }
                }
                label_26:
                ;

                if (body != null)
                {
                    orc = new OrLiteralConstraint();
                    orc.Name = identifier.image;
                    mv = new MultiValue(body);
                    mv.Negated = true;
                    orc.addValue(mv);
                    orc.addValues(andor);
                    list.Add(orc);
                }
            }
            else if (mcc_2_32(2147483647))
            {
                body = bindTypeExpr();
                while (true)
                {
                    mcc_consume_token(AND2);
                    andType(andor);
                    switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                    {
                        case AND2:
                            ;
                            break;
                        default:
                            mcc_la1[53] = mcc_gen;
                            goto label_27;
                    }
                }
                label_27:
                ;

                if (body != null)
                {
                    if (body is String && ((String) body).StartsWith("?"))
                    {
                        bc = new BoundConstraint();
                        bc.Name = identifier.image;
                        bc.Value = ((String) body).Substring(1);
                        bc.IntraFactJoin = true;
                        bc.addIntrFactJoin(andor);
                        list.Add(bc);
                    }
                    else
                    {
                        andc = new AndLiteralConstraint();
                        andc.Name = identifier.image;
                        mv = new MultiValue(body);
                        andc.addValue(mv);
                        andc.addValues(andor);
                        list.Add(andc);
                    }
                }
            }
            else if (mcc_2_33(2147483647))
            {
                mcc_consume_token(TILDA);
                body = typeExpr();
                while (true)
                {
                    mcc_consume_token(AND2);
                    andType(andor);
                    switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                    {
                        case AND2:
                            ;
                            break;
                        default:
                            mcc_la1[54] = mcc_gen;
                            goto label_28;
                    }
                }
                label_28:
                ;

                if (body != null)
                {
                    andc = new AndLiteralConstraint();
                    andc.Name = identifier.image;
                    mv = new MultiValue(body);
                    mv.Negated = true;
                    andc.addValue(mv);
                    andc.addValues(andor);
                    list.Add(andc);
                }
            }
            else if (mcc_2_34(2147483647))
            {
                mcc_consume_token(TILDA);
                body = typeExpr();
                if (body != null)
                {
                    vc = new LiteralConstraint();
                    vc.Name = identifier.image;
                    vc.Value = body;
                    vc.Negated = true;
                    list.Add(vc);
                }
            }
            else if (mcc_2_35(2147483647))
            {
                id = mcc_consume_token(IDENTIFIER);
                if (id != null)
                {
                    vc = new LiteralConstraint();
                    vc.Name = identifier.image;
                    vc.Value = id.image;
                    list.Add(vc);
                }
            }
            else if (mcc_2_36(2147483647))
            {
                mcc_consume_token(TILDA);
                id = mcc_consume_token(IDENTIFIER);
                if (id != null)
                {
                    vc = new LiteralConstraint();
                    vc.Name = identifier.image;
                    vc.Value = id.image;
                    vc.Negated = true;
                    list.Add(vc);
                }
            }
            else
            {
                switch ((mcc_ntk == -1) ? mcc_mntk() : mcc_ntk)
                {
                    case INTEGER_LITERAL:
                    case FLOATING_POINT_LITERAL:
                    case STRING_LITERAL:
                    case PATH_LITERAL:
                        body = typeExpr();
                        if (body != null)
                        {
                            vc = new LiteralConstraint();
                            vc.Name = identifier.image;
                            vc.Value = body;
                            list.Add(vc);
                        }
                        break;
                    case TRUE:
                    case TRUE2:
                    case FALSE:
                    case FALSE2:
                        bval = trueFalse();
                        vc = new LiteralConstraint();
                        vc.Name = identifier.image;
                        vc.Value = Convert.ToBoolean(bval);
                        list.Add(vc);
                        break;
                    default:
                        mcc_la1[55] = mcc_gen;
                        mcc_consume_token(-1);
                        throw new ParseException();
                }
            }
        }
Exemple #13
0
 public void predicateFunc(ArrayList list, Token identifier)
 {
     Token varname = null;
     String func = null;
     ArrayList parms = new ArrayList();
     Token bind = null;
     Token val = null;
     varname = mcc_consume_token(BIND2);
     mcc_consume_token(LBRACE);
     func = functionName();
     bind = mcc_consume_token(BIND);
     actionParams(parms);
     mcc_consume_token(RBRACE);
     PredicateConstraint predc = new PredicateConstraint();
     predc.Name = identifier.image;
     predc.VariableName = varname.image.Substring(1, varname.image.Length - 2);
     predc.FunctionName = func;
     BoundParam bp = new BoundParam();
     bp.VariableName = bind.image;
     predc.addParameter(bp);
     predc.addParameters(parms);
     list.Add(predc);
 }
Exemple #14
0
 public Token GetNextToken()
 {
     if (token.next != null) token = token.next;
     else token = token.next = token_source.GetNextToken();
     mcc_ntk = -1;
     mcc_gen++;
     return token;
 }