コード例 #1
0
        public override Symbol VisitBooleanExpression([NotNull] BooleanExpressionContext context)
        {
            var first           = context.left.Accept(this);
            var second          = context.right.Accept(this);
            var logicalOperator = context.booleanOperator().GetText();

            seleniumLogger.Log($"Evaluating {first} {logicalOperator} {second}", SeleniumScriptLogLevel.InterpreterDetails);

            switch (logicalOperator)
            {
            case "==": return(new Symbol(string.Empty, ReturnType.Bool, first.AsString.Equals(second.AsString)));

            case "!=": return(new Symbol(string.Empty, ReturnType.Bool, !first.AsString.Equals(second.AsString)));

            case ">": return(new Symbol(string.Empty, ReturnType.Bool, first.AsInt > second.AsInt));

            case "<": return(new Symbol(string.Empty, ReturnType.Bool, first.AsInt < second.AsInt));

            case ">=": return(new Symbol(string.Empty, ReturnType.Bool, first.AsInt >= second.AsInt));

            case "<=": return(new Symbol(string.Empty, ReturnType.Bool, first.AsInt <= second.AsInt));
            }

            throw new SeleniumScriptVisitorException("Logical operator could not be parsed");
        }
コード例 #2
0
ファイル: TmtParser.cs プロジェクト: simonec73/threatsmanager
	private ExpressionContext expression(int _p) {
		ParserRuleContext _parentctx = Context;
		int _parentState = State;
		ExpressionContext _localctx = new ExpressionContext(Context, _parentState);
		ExpressionContext _prevctx = _localctx;
		int _startState = 2;
		EnterRecursionRule(_localctx, 2, RULE_expression, _p);
		try {
			int _alt;
			EnterOuterAlt(_localctx, 1);
			{
			State = 34;
			ErrorHandler.Sync(this);
			switch ( Interpreter.AdaptivePredict(TokenStream,0,Context) ) {
			case 1:
				{
				_localctx = new ParentExpressionContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;

				State = 16; Match(LPAREN);
				State = 17; expression(0);
				State = 18; Match(RPAREN);
				}
				break;
			case 2:
				{
				_localctx = new NotExpressionContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 20; Match(NOT);
				State = 21; expression(5);
				}
				break;
			case 3:
				{
				_localctx = new PropertyExpressionContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 22; ((PropertyExpressionContext)_localctx).left = subjectproperty();
				State = 23; ((PropertyExpressionContext)_localctx).op = Match(IS);
				State = 24; ((PropertyExpressionContext)_localctx).right = Match(TEXT);
				}
				break;
			case 4:
				{
				_localctx = new SubjectExpressionContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 26; ((SubjectExpressionContext)_localctx).left = subject();
				State = 27; ((SubjectExpressionContext)_localctx).op = Match(IS);
				State = 28; ((SubjectExpressionContext)_localctx).right = Match(TEXT);
				}
				break;
			case 5:
				{
				_localctx = new FlowExpressionContext(_localctx);
				Context = _localctx;
				_prevctx = _localctx;
				State = 30; ((FlowExpressionContext)_localctx).left = Match(FLOW);
				State = 31; ((FlowExpressionContext)_localctx).op = @operator();
				State = 32; ((FlowExpressionContext)_localctx).right = Match(TEXT);
				}
				break;
			}
			Context.Stop = TokenStream.LT(-1);
			State = 42;
			ErrorHandler.Sync(this);
			_alt = Interpreter.AdaptivePredict(TokenStream,1,Context);
			while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.INVALID_ALT_NUMBER ) {
				if ( _alt==1 ) {
					if ( ParseListeners!=null )
						TriggerExitRuleEvent();
					_prevctx = _localctx;
					{
					{
					_localctx = new BooleanExpressionContext(new ExpressionContext(_parentctx, _parentState));
					((BooleanExpressionContext)_localctx).left = _prevctx;
					PushNewRecursionContext(_localctx, _startState, RULE_expression);
					State = 36;
					if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)");
					State = 37; ((BooleanExpressionContext)_localctx).op = boolean();
					State = 38; ((BooleanExpressionContext)_localctx).right = expression(5);
					}
					} 
				}
				State = 44;
				ErrorHandler.Sync(this);
				_alt = Interpreter.AdaptivePredict(TokenStream,1,Context);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			UnrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}