コード例 #1
0
ファイル: TmtParser.cs プロジェクト: simonec73/threatsmanager
	public BooleanContext boolean() {
		BooleanContext _localctx = new BooleanContext(Context, State);
		EnterRule(_localctx, 6, RULE_boolean);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 47;
			_la = TokenStream.LA(1);
			if ( !(_la==AND || _la==OR) ) {
			ErrorHandler.RecoverInline(this);
			}
			else {
				ErrorHandler.ReportMatch(this);
			    Consume();
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
コード例 #2
0
        internal override void Draw(TMenu instance)
        {
            if (this.lastInstance == null || this.lastContext == null || !this.lastInstance.Equals(instance))
            {
                this.lastContext = this.GetContext(instance);
            }

            this.lastContext.Draw();
        }
コード例 #3
0
    bool Visit(BooleanContext context)
    {
        if (context.GetText() == "true")
        {
            return(true);
        }

        else
        {
            return(false);
        }
    }
コード例 #4
0
 public object VisitBoolean([NotNull] BooleanContext context)
 {
     if (context.TRUE() != null)
     {
         context.value = true;
     }
     else
     {
         context.value = false;
     }
     return(context.value);
 }
コード例 #5
0
ファイル: FormulaParser.cs プロジェクト: zxf033/FormulaCS
        private ExprContext expr(int _p)
        {
            ParserRuleContext _parentctx = Context;
            int         _parentState     = State;
            ExprContext _localctx        = new ExprContext(Context, _parentState);
            ExprContext _prevctx         = _localctx;
            int         _startState      = 2;

            EnterRecursionRule(_localctx, 2, RULE_expr, _p);
            int _la;

            try {
                int _alt;
                EnterOuterAlt(_localctx, 1);
                {
                    State = 34;
                    ErrorHandler.Sync(this);
                    switch (Interpreter.AdaptivePredict(TokenStream, 2, Context))
                    {
                    case 1:
                    {
                        _localctx = new UnaryContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;

                        State = 9;
                        ((UnaryContext)_localctx).sign = TokenStream.LT(1);
                        _la = TokenStream.LA(1);
                        if (!(_la == T__2 || _la == T__3))
                        {
                            ((UnaryContext)_localctx).sign = ErrorHandler.RecoverInline(this);
                        }
                        else
                        {
                            ErrorHandler.ReportMatch(this);
                            Consume();
                        }
                        State = 10; expr(16);
                    }
                    break;

                    case 2:
                    {
                        _localctx = new ParenthesisContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 11; Match(T__14);
                        State     = 12; expr(0);
                        State     = 13; Match(T__15);
                    }
                    break;

                    case 3:
                    {
                        _localctx = new FunctionContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 15; ((FunctionContext)_localctx).name = Match(NAME);
                        State     = 16; Match(T__14);
                        State     = 25;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                        if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__2) | (1L << T__3) | (1L << T__14) | (1L << STRING) | (1L << CELLREF) | (1L << BOOLEAN) | (1L << NUMBER) | (1L << NAME) | (1L << ERROR))) != 0))
                        {
                            {
                                State = 17; expr(0);
                                State = 22;
                                ErrorHandler.Sync(this);
                                _la = TokenStream.LA(1);
                                while (_la == T__16)
                                {
                                    {
                                        {
                                            State = 18; Match(T__16);
                                            State = 19; expr(0);
                                        }
                                    }
                                    State = 24;
                                    ErrorHandler.Sync(this);
                                    _la = TokenStream.LA(1);
                                }
                            }
                        }

                        State = 27; Match(T__15);
                    }
                    break;

                    case 4:
                    {
                        _localctx = new StringContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 28; Match(STRING);
                    }
                    break;

                    case 5:
                    {
                        _localctx = new CellRefContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 29; Match(CELLREF);
                    }
                    break;

                    case 6:
                    {
                        _localctx = new BooleanContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 30; Match(BOOLEAN);
                    }
                    break;

                    case 7:
                    {
                        _localctx = new NumberContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 31; Match(NUMBER);
                    }
                    break;

                    case 8:
                    {
                        _localctx = new NameContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 32; Match(NAME);
                    }
                    break;

                    case 9:
                    {
                        _localctx = new ErrorContext(_localctx);
                        Context   = _localctx;
                        _prevctx  = _localctx;
                        State     = 33; Match(ERROR);
                    }
                    break;
                    }
                    Context.Stop = TokenStream.LT(-1);
                    State        = 61;
                    ErrorHandler.Sync(this);
                    _alt = Interpreter.AdaptivePredict(TokenStream, 4, Context);
                    while (_alt != 2 && _alt != global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER)
                    {
                        if (_alt == 1)
                        {
                            if (ParseListeners != null)
                            {
                                TriggerExitRuleEvent();
                            }
                            _prevctx = _localctx;
                            {
                                State = 59;
                                ErrorHandler.Sync(this);
                                switch (Interpreter.AdaptivePredict(TokenStream, 3, Context))
                                {
                                case 1:
                                {
                                    _localctx = new RangeContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 36;
                                    if (!(Precpred(Context, 17)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 17)");
                                    }
                                    State = 37; Match(T__1);
                                    State = 38; expr(18);
                                }
                                break;

                                case 2:
                                {
                                    _localctx = new PowContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 39;
                                    if (!(Precpred(Context, 14)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 14)");
                                    }
                                    State = 40; Match(T__5);
                                    State = 41; expr(15);
                                }
                                break;

                                case 3:
                                {
                                    _localctx = new MulDivContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 42;
                                    if (!(Precpred(Context, 13)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 13)");
                                    }
                                    State = 43;
                                    ((MulDivContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!(_la == T__6 || _la == T__7))
                                    {
                                        ((MulDivContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 44; expr(14);
                                }
                                break;

                                case 4:
                                {
                                    _localctx = new AddSubContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 45;
                                    if (!(Precpred(Context, 12)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 12)");
                                    }
                                    State = 46;
                                    ((AddSubContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!(_la == T__2 || _la == T__3))
                                    {
                                        ((AddSubContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 47; expr(13);
                                }
                                break;

                                case 5:
                                {
                                    _localctx = new ConcatenateContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 48;
                                    if (!(Precpred(Context, 11)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 11)");
                                    }
                                    State = 49; Match(T__8);
                                    State = 50; expr(12);
                                }
                                break;

                                case 6:
                                {
                                    _localctx = new EqualityContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 51;
                                    if (!(Precpred(Context, 10)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 10)");
                                    }
                                    State = 52;
                                    ((EqualityContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!(_la == T__0 || _la == T__9))
                                    {
                                        ((EqualityContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 53; expr(11);
                                }
                                break;

                                case 7:
                                {
                                    _localctx = new RelationalContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 54;
                                    if (!(Precpred(Context, 9)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 9)");
                                    }
                                    State = 55;
                                    ((RelationalContext)_localctx).op = TokenStream.LT(1);
                                    _la = TokenStream.LA(1);
                                    if (!((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__10) | (1L << T__11) | (1L << T__12) | (1L << T__13))) != 0)))
                                    {
                                        ((RelationalContext)_localctx).op = ErrorHandler.RecoverInline(this);
                                    }
                                    else
                                    {
                                        ErrorHandler.ReportMatch(this);
                                        Consume();
                                    }
                                    State = 56; expr(10);
                                }
                                break;

                                case 8:
                                {
                                    _localctx = new PercentageContext(new ExprContext(_parentctx, _parentState));
                                    PushNewRecursionContext(_localctx, _startState, RULE_expr);
                                    State = 57;
                                    if (!(Precpred(Context, 15)))
                                    {
                                        throw new FailedPredicateException(this, "Precpred(Context, 15)");
                                    }
                                    State = 58; Match(T__4);
                                }
                                break;
                                }
                            }
                        }
                        State = 63;
                        ErrorHandler.Sync(this);
                        _alt = Interpreter.AdaptivePredict(TokenStream, 4, Context);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                UnrollRecursionContexts(_parentctx);
            }
            return(_localctx);
        }
 public override ASTN VisitBoolean([NotNull] BooleanContext context) => new BoolNode(context, context.GetText());
コード例 #7
0
 public override SymbolBase VisitBoolean([NotNull] BooleanContext context) =>
 new BooleanSymbol(context.GetText());
コード例 #8
0
ファイル: Program.cs プロジェクト: denkavs/Design_Pattern
        static void Main(string[] args)
        {
            string srcImagePath = @"http://dev.mygemplace.com/Content/_Traders/2/jwProducts/8_Ring2_1qK1b.jpg";
            string photoName    = Path.GetFileNameWithoutExtension(srcImagePath);

            MemoryStream   memory    = new MemoryStream();
            HttpWebRequest lxRequest = (HttpWebRequest)WebRequest.Create(srcImagePath);

            using (HttpWebResponse lxResponse = (HttpWebResponse)lxRequest.GetResponse())
            {
                using (BinaryReader reader = new BinaryReader(lxResponse.GetResponseStream()))
                {
                    reader.BaseStream.CopyTo(memory);
                    //Byte[] lnByte = reader.ReadBytes(1 * 1024 * 1024 * 10);
                    //using (FileStream lxFS = new FileStream("34891.jpg", FileMode.Create))
                    //{
                    //    lxFS.Write(lnByte, 0, lnByte.Length);
                    //}
                }
            }

            Bitmap photo;

            try
            {
                photo = new Bitmap(memory);
            }
            catch (ArgumentException e)
            {
                throw new FileNotFoundException(string.Format(" GDIThumbnail generator file[{0}] not found.", srcImagePath), e);
            }

            // Factory Method
            Console.WriteLine();
            Console.WriteLine("[Abstract Factory] Pattern");
            IWidgetFactory abstractFactory = new PMWidgetFactory();
            IWidgetButton  abstractButton  = abstractFactory.CreateWidgetButton();
            IWidgetDialog  abstractDialog  = abstractFactory.CreateWidgetDialog();

            abstractButton.DrawButton();
            abstractDialog.DrawWidget();

            abstractButton.SetLocation();
            abstractDialog.SetTopMost();
            //-------------------

            // FactoryMethod/Virtual Constructor
            Console.WriteLine();
            Console.WriteLine("[FactoryMethod/Virtual Constructor] Pattern");
            Creator          creator    = new ConcreteCreator();
            IAMethodDocument amDocument = creator.CreateDocument();

            amDocument.Open();
            //----------------------------------

            // Builder
            Console.WriteLine("[Builder] Pattern");
            Console.WriteLine();
            Shop            shop    = new Shop();
            IVehicleBuilder builder = new CarBuilder();

            shop.Construct(builder);
            shop.ShowVehicle();
            builder = new VeloByke();
            shop.Construct(builder);
            shop.ShowVehicle();
            //----------------------

            // Facade
            // Provides more simple unified interface instead of few interfaces some subsystem.
            // Subsystem interfaces don't keep references to facade interface.
            Console.WriteLine();
            Console.WriteLine("[Facade] Pattern");
            Facade facade = new Facade();

            facade.MethodA();
            facade.MethodB();
            //-------

            // Flyweight
            // Build a document with text
            Console.WriteLine();
            Console.WriteLine("[Flyweight] Pattern");
            string document = "AAZZBBZB";

            char[]           chars   = document.ToCharArray();
            CharacterFactory factory = new CharacterFactory();

            // extrinsic state
            int pointSize = 10;

            //For each character use a flyweight object
            foreach (char c in chars)
            {
                pointSize++;
                Character character = factory.GetCharacter(c);
                character.Display(pointSize);
            }
            //-----------

            // Proxy
            Console.WriteLine();
            Console.WriteLine("[Proxy] pattern");
            IImage proxy = new ProxyImage();

            proxy.GetSize();
            proxy.Draw();
            //--------


            //Chain Responsibilities
            Console.WriteLine();
            Console.WriteLine("[Chain of Responsibilities] pattern");
            DialogChain dc1          = new DialogChain(null);
            ButtonChain bc1          = new ButtonChain(dc1);
            DialogChain dc2          = new DialogChain(bc1);
            ButtonChain buttonChain2 = new ButtonChain(dc2);
            IRequest    request1     = new Request1();

            ((Request1)request1).Value = "QWE_RTYU";
            buttonChain2.HandleRequest(request1);

            Request2 rq2 = new Request2();

            rq2.Value = "123456";
            buttonChain2.HandleRequest(rq2);

            //----------------------

            // Command
            Console.WriteLine();
            Console.WriteLine("[Command] Pattern");
            List <SourceCommand> srcCmd = new List <SourceCommand>();

            SourceCommand scr1 = new SourceCommand();

            scr1.Command = new OpenCommand(new Receiver1("Star1"));

            SourceCommand scr2 = new SourceCommand();

            scr2.Command = new PasteCommand(new Receiver2("Paste Star 2"));

            srcCmd.Add(scr1);
            srcCmd.Add(scr2);

            TemplatedCommand <string>       templatedCommand = new TemplatedCommand <string>(delegate(string s) { Console.WriteLine("---Delegate command is executed @@@@ {0}", s); });
            TemplatedSourceCommand <string> scr3             = new TemplatedSourceCommand <string>(templatedCommand);

            scr3.ActionInvoke("1111");

            foreach (var sourceCommand in srcCmd)
            {
                sourceCommand.InvokeCommand();
            }
            //---------

            // Interpreter
            string  roman   = "MCMXXVIII";
            Context context = new Context(roman);

            // Build the 'parse tree'
            List <Expression> tree = new List <Expression>();

            tree.Add(new ThousandExpression());
            tree.Add(new HundredExpression());
            tree.Add(new TenExpression());
            tree.Add(new OneExpression());

            // Interpret
            foreach (Expression exp in tree)
            {
                exp.Interpret(context);
            }

            Console.WriteLine("{0} = {1}", roman, context.Output);

            // define booleand expression
            // (true and x) or (y and x)
            Console.WriteLine("----------------------------");
            BooleanExp     expressing;
            BooleanContext boolContext = new BooleanContext();

            expressing = new OrExp(new AndExp(new BooleanConstant("true"), new VariableExp("x")),
                                   new AndExp(new VariableExp("y"), new NotExp("x")));

            boolContext.Assign("x", false);
            boolContext.Assign("y", false);

            Console.WriteLine("Result of boolean interpreter is [{0}]", expressing.Evaluate(boolContext));
            //-------------

            // Iterator
            Console.WriteLine();
            Console.WriteLine("Pattern Iterator");
            ConcreteAggregate aggregate = new ConcreteAggregate();

            aggregate[0] = "Object 1";
            aggregate[1] = "Object 2";
            aggregate[2] = "Object 3";
            aggregate[3] = "Object 4";
            Iterator iter = aggregate.CreateIterator();

            for (object i = iter.First(); !iter.IsDone(); i = iter.Next())
            {
                Console.WriteLine("Current object [{0}]", i);
            }

            //--------------

            // Mediator
            Console.WriteLine();
            Console.WriteLine("Pattern Mediator");

            // parts could be informed about its mediator.
            ConcreteMediator cm = new ConcreteMediator(new Collegue1(), new Collegue2(), new Collegue3());

            cm.Process1AndInform23();
            cm.Process3AndInform1();
            //------------

            // Memento
            Console.WriteLine();
            Console.WriteLine("Pattern Memento");

            SalesProspect salesProspect = new SalesProspect();

            salesProspect.Budget = 45.56;
            salesProspect.Name   = "Super Man";
            salesProspect.Phone  = "45-78-96";

            ProspectMemory prospectMemory = new ProspectMemory();

            prospectMemory.Memento = salesProspect.SaveMemento();

            salesProspect.Budget = 11.11;
            salesProspect.Name   = "Spider Man";
            salesProspect.Phone  = "33-44-55";

            salesProspect.RestoreMemento(prospectMemory.Memento);
            //--------------

            // Observer (Dependents, Publish-Subscriber)
            Console.WriteLine();
            Console.WriteLine("Pattern Observer");

            Subject           subject           = new Subject();
            ConcreteObserver1 concreteObserver1 = new ConcreteObserver1();
            ConcreteObserver2 concreteObserver2 = new ConcreteObserver2();

            subject.Register(concreteObserver1);
            subject.Register(concreteObserver2);
            subject.Register(concreteObserver1);

            subject.NotifyObservers();

            subject.UnRegister(concreteObserver2);
            subject.UnRegister(concreteObserver2);

            subject.NotifyObservers();
            //------------------------------------------

            // State
            Console.WriteLine();
            Console.WriteLine("Pattern State");
            Account account = new Account("Jim Johnson");

            // Apply financial transactions
            account.Deposit(500.0);
            account.Deposit(300.0);
            account.Deposit(550.0);
            account.PayInterest();
            account.Withdraw(2000.00);
            account.Withdraw(1100.00);
            account.Deposit(50000);
            account.PayInterest();


            //------------------------------------------

            // Strategy
            // Client should knew all available strategies.
            Console.WriteLine();
            Console.WriteLine("Pattern Strategy");

            StrategyContext strategyContext = new StrategyContext(null);

            strategyContext.ContextOperationOne();
            strategyContext.ContextOperationTwo();

            strategyContext.Strategy = new ConcreteStrategy();
            strategyContext.ContextOperationOne();
            strategyContext.ContextOperationTwo();

            //------------------------------------------

            // Template Method
            Console.WriteLine();
            Console.WriteLine("Template Method");
            TemplateMethodClass tmc = new ConcreteTemplateMethodClass1();

            tmc.TemplateMethod();
            //------------------------------------------

            // Visitor
            Console.WriteLine();
            Console.WriteLine("Visitor");
            List <INode> elements = new List <INode>();

            elements.Add(new NodeType1()
            {
                Balance = 400, Name = "Qwerty"
            });
            elements.Add(new NodeType1()
            {
                Balance = 333, Name = "QasxzWe"
            });
            elements.Add(new NodeType2()
            {
                CarName = "Mersedes"
            });
            NodeVisitor visitor = new ConcreteNodeVisitor();

            foreach (var element in elements)
            {
                element.Accept(visitor);
            }

            //------------------------------------------

            ThreadTest threadTest = new ThreadTest();

            //threadTest.RunTask();
            threadTest.TestFactory();

            // Unit of Work patternt with Repository pattern
            Console.WriteLine();
            Console.WriteLine("UOW pattern");
            StudentController sc = new StudentController();

            sc.DoAction();

            MoneyPattern.Start();
            Console.Read();
        }
コード例 #9
0
ファイル: AndExp.cs プロジェクト: denkavs/Design_Pattern
 public bool Evaluate(BooleanContext context)
 {
     return(this.operand1.Evaluate(context) && this.operand2.Evaluate(context));
 }
コード例 #10
0
ファイル: DeltaVisitor.cs プロジェクト: migueladanrm/Volta
 public object VisitBoolean([NotNull] BooleanContext context)
 {
     return(context.value ? "true" : "false");
 }
コード例 #11
0
ファイル: BooleanContext.cs プロジェクト: lyonl/MandateThat
 internal BooleanContext(BooleanContext parentContext) : base(parentContext)
 {
 }
コード例 #12
0
 public bool Evaluate(BooleanContext context)
 {
     return(context.Lookup(this.value));
 }