Пример #1
0
        /**
         * Gets the list of lexical tokens using the generated lexical analyzer
         *
         * @return the list of tokens
         * @exception FormulaException if an error occurs
         */
        private IList <ParseItem> getTokens()
        {
            List <ParseItem> tokens = new List <ParseItem>();

            // since a StringReader is not a Stream and cannot be wrapped by StreamReader -- brilliant Microsoft!  Brilliant!
            StreamReader reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(formula)));

//			StringReader sr = new StringReader(formula);
            Yylex lex = new Yylex(reader);

            lex.setExternalSheet(externalSheet);
            lex.setNameTable(nameTable);
            try
            {
                ParseItem pi = lex.yylex();
                while (pi != null)
                {
                    tokens.Add(pi);
                    pi = lex.yylex();
                }
            }
            catch (IOException e)
            {
                //logger.warn(e.ToString());
            }
            catch (Exception e)
            {
                throw new FormulaException(FormulaException.LEXICAL_ERROR, formula + " at char  " + lex.getPos());
            }

            return(tokens);
        }
        /**
         * Gets the list of lexical tokens using the generated lexical analyzer
         *
         * @return the list of tokens
         * @exception FormulaException if an error occurs
         */
        private IList<ParseItem> getTokens()
        {
            List<ParseItem> tokens = new List<ParseItem>();

            // since a StringReader is not a Stream and cannot be wrapped by StreamReader -- brilliant Microsoft!  Brilliant!
            StreamReader reader = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(formula)));

            //			StringReader sr = new StringReader(formula);
            Yylex lex = new Yylex(reader);
            lex.setExternalSheet(externalSheet);
            lex.setNameTable(nameTable);
            try
                {
                ParseItem pi = lex.yylex();
                while (pi != null)
                    {
                    tokens.Add(pi);
                    pi = lex.yylex();
                    }
                }
            catch (IOException e)
                {
                //logger.warn(e.ToString());
                }
            catch (Exception e)
                {
                throw new FormulaException(FormulaException.LEXICAL_ERROR,formula + " at char  " + lex.getPos());
                }

            return tokens;
        }