public Expression GetExpression(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         LsmCommonExpressions.CharMatch(lsmContext, _constant),
         Actions.GetExpression(lsmContext),
         Expression.Empty());
 }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         GetCharacterMatchExpression(lsmContext),
         Actions.GetExpression(lsmContext),
         Expression.Empty());
 }
Esempio n. 3
0
 public Expression GetBodyExpression(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         LsmCommonExpressions.EndOfStream(lsmContext),
         PostStreamActions.GetExpression(lsmContext),
         MatchRules.GetExpression(lsmContext));
 }
 public static Expression AcceptChar(LsmContext lsmContext)
 {
     return Expression.Call(
         lsmContext.tokenTextVariable,
         typeof(StringBuilder).GetMethod("Append", new[] { typeof(char) }),
         lsmContext.currentCharVariable);
 }
 public static Expression AcceptToken(LsmContext lsmContext, int typeID)
 {
     return Expression.Call(
         lsmContext.tokenListVariable,
         typeof(List<LsmToken>).GetMethod("Add", new[] {typeof(LsmToken)}),
         LsmCommonExpressions.NewToken(lsmContext, typeID));
 }
Esempio n. 6
0
        public LsmTokenizeFunction BuildLexerFunction()
        {
            LsmContext context = new LsmContext();
            LabelTarget breakTarget = Expression.Label();

            Expression block = Expression.Block(
                context.GetLocalVariables(),
                context.GetInitializationBlock(StartState.ID),
                Expression.Loop(
                    Expression.Block(
                        LsmCommonExpressions.AssignPeekValue(context),
                        Expression.IfThenElse(
                            LsmCommonExpressions.EndOfStream(context),
                            Expression.Empty(),
                            LsmCommonExpressions.AssignCurrentChar(context)),
                        States.GetExpression(context),
                        LsmCommonExpressions.UpdateCharIndexInState(context),
                        Expression.IfThenElse(
                            LsmCommonExpressions.EndOfStream(context),
                            Expression.Break(breakTarget),
                            Expression.Empty())),
                    breakTarget),
                    context.currentStateVariable);

             Expression<LsmTokenizeFunction> finalExpression
                = Expression.Lambda<LsmTokenizeFunction>(
                    block,
                    context.textReaderParameter,
                    context.tokenListVariable);

            return finalExpression.Compile();
        }
 public static Expression CallCharMatchFunc(LsmContext lsmContext,
     Func<char, bool> func)
 {
     return Expression.Call(
         null,
         func.Method,
         lsmContext.currentCharVariable);
 }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         LsmCommonExpressions.CallCharMatchFunc(
             lsmContext, _matchFunc),
         Actions.GetExpression(lsmContext),
         Expression.Empty());
 }
Esempio n. 9
0
 public Expression GetExpression(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         Expression.Equal(
             lsmContext.currentStateVariable,
             Expression.Constant(this.ID)),
         GetBodyExpression(lsmContext),
         Expression.Empty());
 }
 public static Expression AlphaNumericMatch(LsmContext lsmContext)
 {
     return Expression.Call(
         null,
         typeof(char).GetMethod(
             "IsLetterOrDigit",
             new[] { typeof(char) }),
         lsmContext.currentCharVariable);
 }
 public static Expression AssignCurrentChar(LsmContext lsmContext)
 {
     return Expression.Assign(
         lsmContext.currentCharVariable,
         Expression.Call(
             null,
             typeof(Convert).GetMethod("ToChar", new[] {typeof(int)}),
             LsmCommonExpressions.PeekValue(lsmContext)));
 }
Esempio n. 12
0
 public Expression GetExpression(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         Expression.Equal(
             lsmContext.charIndexInStateVariable,
             Expression.Constant(_charIndex)),
         Actions.GetExpression(lsmContext),
         Expression.Empty());
 }
        public static Expression IfElseChain(IEnumerable<ILsmExpressable> expressableConditions,
            Expression defaultExpression, LsmContext lsmContext)
        {
            List<ILsmExpressable> expressables = expressableConditions.Reverse().ToList();

            ConditionalExpression lastOuterExpression = expressables[0].GetExpression(lsmContext)
                as ConditionalExpression;
            expressables.RemoveAt(0);

            lastOuterExpression = Expression.IfThenElse(
                lastOuterExpression.Test,
                lastOuterExpression.IfTrue,
                defaultExpression);

            while (expressables.Count > 0)
            {
                ConditionalExpression outerExpression = expressables[0].GetExpression(lsmContext)
                    as ConditionalExpression;

                lastOuterExpression = Expression.IfThenElse(outerExpression.Test,
                    outerExpression.IfTrue,
                    lastOuterExpression);

                expressables.RemoveAt(0);
            }

            return lastOuterExpression;
        }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return LsmCommonExpressions.AcceptToken(lsmContext, _tokenTypeID);
 }
 public static Expression WhiteSpaceMatch(LsmContext lsmContext)
 {
     return Expression.Call(
         null,
         typeof(char).GetMethod(
             "IsWhiteSpace",
             new[] { typeof(char) }),
         lsmContext.currentCharVariable);
 }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return LsmCommonExpressions.AcceptChar(lsmContext);
 }
 public static Expression UpdateCharIndexInState(LsmContext lsmContext)
 {
     return Expression.IfThenElse(
         Expression.Equal(
             lsmContext.currentStateVariable,
             lsmContext.lastStateVariable),
         Expression.PreIncrementAssign(lsmContext.charIndexInStateVariable),
         Expression.Block(
             Expression.Assign(
                 lsmContext.charIndexInStateVariable,
                 Expression.Constant(0)),
             Expression.Assign(
                 lsmContext.lastStateVariable,
                 lsmContext.currentStateVariable)));
 }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return LsmCommonExpressions.ChangeState(lsmContext, _newState.ID);
 }
 public static Expression CharMatch(LsmContext lsmContext, char constant)
 {
     return Expression.Equal(
         lsmContext.currentCharVariable,
         Expression.Constant(constant));
 }
Esempio n. 20
0
 public Expression GetExpression(LsmContext lsmContext)
 {
     return Expression.Block(
         LsmCommonExpressions.ReadChar(lsmContext),
         LsmCommonExpressions.IncrementCharIndex(lsmContext));
 }
 public static Expression EndOfStream(LsmContext lsmContext)
 {
     return Expression.Equal(
         lsmContext.peekValueVariable,
         Expression.Constant(-1));
 }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return LsmCommonExpressions.ClearTokenText(lsmContext);
 }
 public static Expression AssignPeekValue(LsmContext lsmContext)
 {
     return Expression.Assign(
         lsmContext.peekValueVariable,
         LsmCommonExpressions.PeekValue(lsmContext));
 }
 public static Expression IncrementCharIndex(LsmContext lsmContext)
 {
     return Expression.PostIncrementAssign(lsmContext.charIndexVariable);
 }
 public static Expression ChangeState(LsmContext context, int stateID)
 {
     return Expression.Assign(
         context.currentStateVariable,
         Expression.Constant(stateID));
 }
 public static Expression MarkTokenStart(LsmContext lsmContext)
 {
     return Expression.Assign(
         lsmContext.tokenStartVariable,
         lsmContext.charIndexVariable);
 }
 public static Expression ClearTokenText(LsmContext lsmContext)
 {
     return Expression.Call(
         lsmContext.tokenTextVariable,
         typeof(StringBuilder).GetMethod("Clear", Type.EmptyTypes));
 }
 public static Expression ReadChar(LsmContext lsmContext)
 {
     return Expression.Call(
         lsmContext.textReaderParameter,
         typeof(TextReader).GetMethod("Read", Type.EmptyTypes));
 }
 public static Expression NewToken(LsmContext lsmContext, int typeID)
 {
     return Expression.New(
         typeof(LsmToken).GetConstructor(
             new [] {typeof(int), typeof(string), typeof(int)}),
         Expression.Constant(typeID),
         LsmCommonExpressions.GetTokenText(lsmContext),
         lsmContext.tokenStartVariable);
 }
 public Expression GetExpression(LsmContext lsmContext)
 {
     return LsmCommonExpressions.MarkTokenStart(lsmContext);
 }