public static PatternCode Scan(string code)
        {
            PatternCode lPatternCode = new PatternCode();
            int         lPosition    = 0;

            PatternToken lPreviousToken = PatternToken.UNKNOWN;

            // tokenize code
            while (lPosition < code.Length)
            {
                string       lTokenString = ReadTokenString(code, ref lPosition);
                PatternToken lToken       = GetToken(lTokenString, lPreviousToken);

                // "*" could also be a variable
                if ((lToken == PatternToken.MULTIPLY) && (lPreviousToken == PatternToken.COMMA || lPreviousToken == PatternToken.OPEN_PARA))
                {
                    lToken = PatternToken.VARIABLE;
                }

                int lParameterCount = (lToken == PatternToken.FUNCTION) ? GetParameterCount(code, lPosition) : 0;

                PatternOperand patternOperand = new PatternOperand(lToken, lTokenString, lParameterCount);

                if (lToken == PatternToken.UNKNOWN)
                {
                    lPatternCode.SetErrorMessage("Unknown Token: " + lTokenString.ToString());
                    return(lPatternCode);
                }
                lPatternCode.Add(patternOperand);

                lPreviousToken = lToken;
            }

            return(lPatternCode);
        }
Esempio n. 2
0
        public static PatternCode Compile(Pattern pattern)
        {
            PatternCode lPatternCode = PatternScanner.Scan(pattern.PatternSourceCode);

            if (!lPatternCode.IsError())
            {
                PatternSyntax lPatternSyntax = new PatternSyntax(lPatternCode);

                if (!lPatternSyntax.SyntaxCheck())
                {
                    lPatternCode.SetErrorMessage(lPatternSyntax);
                    return(lPatternCode);
                }
            }

            return(lPatternCode);
        }
Esempio n. 3
0
        public static PatternCode Scan(string code)
        {
            PatternCode lPatternCode = new PatternCode();
            int lPosition = 0;

            PatternToken lPreviousToken = PatternToken.UNKNOWN;

            // tokenize code
            while (lPosition < code.Length)
            {
                string lTokenString = ReadTokenString(code, ref lPosition);
                PatternToken lToken = GetToken(lTokenString, lPreviousToken);

                // "*" could also be a variable
                if ((lToken == PatternToken.MULTIPLY) && (lPreviousToken == PatternToken.COMMA || lPreviousToken == PatternToken.OPEN_PARA))
                    lToken = PatternToken.VARIABLE;

                int lParameterCount = (lToken == PatternToken.FUNCTION) ? GetParameterCount(code, lPosition) : 0;

                PatternOperand patternOperand = new PatternOperand(lToken, lTokenString, lParameterCount);

                if (lToken == PatternToken.UNKNOWN)
                {
                    lPatternCode.SetErrorMessage("Unknown Token: " + lTokenString.ToString());
                    return lPatternCode;
                }
                lPatternCode.Add(patternOperand);

                lPreviousToken = lToken;
            }

            return lPatternCode;
        }