Пример #1
0
        public void Union_WhenTwoSets_ReturnsUnionOfSets(string[] set1, string[] set2, string[] expected)
        {
            // Arrange:
            var ts1 = new TerminalSet();

            foreach (var terminal in set1)
            {
                ts1.Add(terminal);
            }

            var ts2 = new TerminalSet();

            foreach (var terminal in set2)
            {
                ts2.Add(terminal);
            }

            // Act:
            ts1.Union(ts2, false);

            // Assert:
            Assert.That(ts1.AsEnumerable(), Is.EquivalentTo(expected));
        }
Пример #2
0
 private void PrologTerm(TerminalSet _TS, out Term t)
 {
     Term lastInfix = null;
       string s;
       ArrayList termInfixArr = new ArrayList();
       termInfixArr.Add(null);
       do
       {
     GetSymbol(new TerminalSet(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                             CutSym, LSqBracket, LCuBracket, PrologString), false, true);
     if (symbol.Terminal == Operator)
     {
       symbol.SetProcessed();
       t = new Term((OperatorDescr)symbol.OValue);
     }
     else if (symbol.IsMemberOf(StringLiteral, Atom))
     {
       GetSymbol(new TerminalSet(StringLiteral, Atom), false, true);
       if (symbol.Terminal == Atom)
       {
     symbol.SetProcessed();
     s = symbol.ToString();
       }
       else
       {
     symbol.SetProcessed();
     s = Utils.UnquoteIfUnnecessary(symbol.ToString());
       }
       Term[] terms = null;
       bool b = is1000OperatorSetting;
       GetSymbol(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                         CutSym, LSqBracket, LCuBracket, PrologString), false, true);
       if (symbol.Terminal == LeftParen)
       {
     symbol.SetProcessed();
     Set1000Operators(true);
     terminalTable[DOT] = Atom;
     terminalTable[OP] = Atom;
     PrologTerm(new TerminalSet(RightParen), out t);
     terminalTable[DOT] = Dot;
     terminalTable[OP] = OpSym;
     terms = t.ArgumentsToTermArray();
     Set1000Operators(b);
     GetSymbol(new TerminalSet(RightParen), true, true);
       }
       if (terms == null) t = new Term(s); else t = new Term(s, terms);
     }
     else if (symbol.Terminal == Identifier)
     {
       symbol.SetProcessed();
       s = symbol.ToString();
       t = Globals.GetVariable(s);
       if (t == null)
       {
     t = new NamedVar(s);
     Globals.SetVariable(t, s);
       }
     }
     else if (symbol.Terminal == Anonymous)
     {
       symbol.SetProcessed();
       t = new Term();
     }
     else if (symbol.IsMemberOf(IntLiteral, RealLiteral))
     {
       GetSymbol(new TerminalSet(IntLiteral, RealLiteral), false, true);
       if (symbol.Terminal == IntLiteral)
       {
     symbol.SetProcessed();
       }
       else
       {
     symbol.SetProcessed();
       }
       t = new Term(symbol.ToString(), FType.number);
     }
     else if (symbol.Terminal == LSqBracket)
     {
       List(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                    LSqBracket, LCuBracket, PrologString), out t);
     }
     else if (symbol.Terminal == LCuBracket)
     {
       DCGBracketList(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                              CutSym, LSqBracket, LCuBracket, PrologString), out t);
     }
     else if (symbol.Terminal == PrologString)
     {
       symbol.SetProcessed();
       t = new Term(symbol.ToUnquoted(), FType.text);
     }
     else if (symbol.Terminal == CutSym)
     {
       symbol.SetProcessed();
       t = new Cut(0);
     }
     else
     {
       symbol.SetProcessed();
       PrologTerm(new TerminalSet(RightParen), out t);
       GetSymbol(new TerminalSet(RightParen), true, true);
       t.IsPacked = true;
     }
     termInfixArr.Add(t);
     Term.AnalyzeInput(ref termInfixArr, ref lastInfix);
     GetSymbol(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                       LSqBracket, LCuBracket, PrologString), false, true);
       } while (!(_TS.Contains(symbol.Terminal)));
       termInfixArr.Add(null);
       Term.AnalyzeInput(ref termInfixArr, ref lastInfix);
       t = Term.InfixToPrefix(termInfixArr);
 }
Пример #3
0
 private void PrologCode(TerminalSet _TS)
 {
     inQueryMode = false;
       try
       {
     SeeEndOfLine = false;
     GetSymbol(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                       LSqBracket, LCuBracket, OpSym, BuiltinSym, ProgramSym, ReadingSym, PrologString, QMark), false,
            true);
     if (symbol.IsMemberOf(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                        LSqBracket, LCuBracket, OpSym, BuiltinSym, ProgramSym, ReadingSym, PrologString, QMark))
     {
       GetSymbol(new TerminalSet(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                               CutSym, LSqBracket, LCuBracket, OpSym, BuiltinSym, ProgramSym, ReadingSym, PrologString,
                               QMark), false, true);
       if (symbol.Terminal == BuiltinSym)
       {
     symbol.SetProcessed();
     parseMode = ParseMode.Builtin;
     Initialize();
     Predefineds(_TS);
       }
       else if (symbol.Terminal == ProgramSym)
       {
     symbol.SetProcessed();
     parseMode = ParseMode.Program;
     Initialize();
     Program(_TS);
       }
       else if (symbol.Terminal == ReadingSym)
       {
     symbol.SetProcessed();
     parseMode = ParseMode.Reading;
     ClauseSequence(_TS);
       }
       else
       {
     Globals.EraseVariables();
     parseMode = ParseMode.Query;
     inQueryMode = true;
     GetSymbol(new TerminalSet(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                                 CutSym, LSqBracket, LCuBracket, OpSym, PrologString, QMark), false, true);
     if (symbol.IsMemberOf(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous,
                            CutSym, LSqBracket, LCuBracket, PrologString, QMark))
     {
       terminalTable[DOT] = Dot;
       Set1000Operators(true);
       Query(new TerminalSet(Dot), out queryNode);
     }
     else
     {
       OperatorDefinition(new TerminalSet(Dot), true);
       queryNode = null;
     }
     GetSymbol(new TerminalSet(Dot), true, true);
       }
     }
       }
       finally
       {
     terminalTable[COMMA] = Operator;
     terminalTable[OP] = OpSym;
     terminalTable[DOT] = Dot;
     Terminate();
       }
 }
Пример #4
0
 private void Program(TerminalSet _TS)
 {
     do
       {
     ClauseNode(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                        ImpliesSym, PromptSym, LSqBracket, LCuBracket, PrologString));
     GetSymbol(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                       ImpliesSym, PromptSym, LSqBracket, LCuBracket, PrologString), false, true);
       } while (!(_TS.Contains(symbol.Terminal)));
 }
Пример #5
0
 private void ClauseSequence(TerminalSet _TS)
 {
     Monitor.Enter(PrologEngine.TermMonitor);
       do
       {
     ClauseNode(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                        ImpliesSym, PromptSym, LSqBracket, LCuBracket, PrologString));
     Monitor.Pulse(PrologEngine.TermMonitor);
     Monitor.Wait(PrologEngine.TermMonitor);
     GetSymbol(_TS.Union(LeftParen, Identifier, IntLiteral, RealLiteral, StringLiteral, Operator, Atom, Anonymous, CutSym,
                       ImpliesSym, PromptSym, LSqBracket, LCuBracket, PrologString), false, true);
       } while (!(_TS.Contains(symbol.Terminal)));
       readTerm = new Term(EOF);
       Monitor.Pulse(PrologEngine.TermMonitor);
       Monitor.Exit(PrologEngine.TermMonitor);
 }