示例#1
0
 private bool Match(SetTokenType type)
 {
     if (m_curToken.Type == type) {
         m_curToken = NextToken ();
         return true;
     } else
         throw new Exception (string.Format ("Invalid token - Expecting : {0}", type));
 }
示例#2
0
        public void ParseToSetList(List <SetToken> tokens)
        {
            m_Tokens   = tokens;
            m_iTP      = 0;
            m_curToken = null;

            m_llSetList = new LinkedList <Set> ();

            SetParse();
        }
示例#3
0
        public void ParseToSetList(List<SetToken> tokens)
        {
            m_Tokens = tokens;
            m_iTP = 0;
            m_curToken = null;

            m_llSetList = new LinkedList<Set> ();

            SetParse ();
        }
示例#4
0
 private bool Match(SetTokenType type)
 {
     if (m_curToken.Type == type)
     {
         m_curToken = NextToken();
         return(true);
     }
     else
     {
         throw new Exception(string.Format("Invalid token - Expecting : {0}", type));
     }
 }
示例#5
0
        /// <summary>
        /// Parse SetToken list matching the following BNF:
        /// SetList ::= Integer Mult Integer Interval Stroke {Comment}
        /// Interval ::= {{Digit} Digit : } {Digit} Digit : Digit Digit
        /// Stroke  ::= Word
        /// Comment ::= {Word} | {{Word} Word}
        /// Word	::= Letter | Word Letter
        /// Letter  ::= {any latin letter}
        /// Integer ::= Digit | Integer Digit
        /// Digit   ::= 0|1| ... | 9
        /// Mult	::= x|X
        /// </summary>
        private void SetParse()
        {
            int    number, distance;
            string interval, stroke, comment;

            m_curToken = NextToken();
            while (m_curToken != null && m_curToken.Type != SetTokenType.EOF)
            {
                comment = "";                 // reset comment

                number = int.Parse(m_curToken.Value);
                Match(SetTokenType.INTEGER);

                Match(SetTokenType.MULT);

                distance = int.Parse(m_curToken.Value);
                Match(SetTokenType.INTEGER);

                interval = m_curToken.Value;
                Match(SetTokenType.INTERVAL);

                stroke = m_curToken.Value;
                Match(SetTokenType.WORD);

                // Comments are optional
                if (m_curToken.Type == SetTokenType.WORD)
                {
                    // Comments
                    int curLine = m_curToken.LineNumber;
                    for (; m_curToken != null && m_curToken.Type != SetTokenType.EOF &&
                         m_curToken.LineNumber != curLine + 1; Match(SetTokenType.WORD))
                    {
                        comment += m_curToken.Value + " ";
                    }
                }         // if
                m_llSetList.AddLast(new Set(number, distance, stroke, comment, interval));
            }             // main loop
        }
示例#6
0
        /// <summary>
        /// Convert string into list of SetTokens
        /// </summary>
        /// <param name="setfile">Setfile.</param>
        public void TokenizeString(string setfile)
        {
            m_sRawFile = setfile;

            // Split raw file into "words" or "blocks"
            m_lsLines.AddRange(m_sRawFile.Split(new [] { Environment.NewLine }, StringSplitOptions.None));

            int iLineCount = -1;

            // Loop through lines
            foreach (string line in m_lsLines)
            {
                iLineCount++;

                // skip line if empty
                if (line.Length == 0)
                {
                    continue;
                }
                // skip comment lines
                if (line [0] == '#')
                {
                    continue;
                }

                // Loop through blocks in each line
                foreach (string s in line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    SetToken st;
                    int      temp = 0;
                    // comment reached, goto next line
                    if (s.Contains("#"))
                    {
                        break;
                    }

                    // MULT
                    if (s.ToString().ToUpper() [0] == 'X' && s.Length == 1)
                    {
                        st = new SetToken(SetTokenType.MULT, s, iLineCount);
                    }

                    // INTEGER
                    else if (int.TryParse(s, out temp))
                    {
                        st = new SetToken(SetTokenType.INTEGER, s, iLineCount);
                    }

                    // INTERVAL
                    else if (Regex.IsMatch(s, "[0-9]*[0-9]*:*[0-9]*[0-9]:[0-9][0-9]"))
                    {
                        st = new SetToken(SetTokenType.INTERVAL, s, iLineCount);
                    }

                    // WORD, assume anything else is a word
                    else
                    {
                        st = new SetToken(SetTokenType.WORD, s, iLineCount);
                    }

                    m_ltTokens.Add(st);
                }         // foreach block
            }             // foreach line
            m_ltTokens.Add(new SetToken(SetTokenType.EOF, "EOF", iLineCount));
        }
示例#7
0
        /// <summary>
        /// Convert string into list of SetTokens
        /// </summary>
        /// <param name="setfile">Setfile.</param>
        public void TokenizeString(string setfile)
        {
            m_sRawFile = setfile;

            // Split raw file into "words" or "blocks"
            m_lsLines.AddRange (m_sRawFile.Split (new [] { Environment.NewLine }, StringSplitOptions.None));

            int iLineCount = -1;

            // Loop through lines
            foreach (string line in m_lsLines) {
                iLineCount++;

                // skip line if empty
                if (line.Length == 0)
                    continue;
                // skip comment lines
                if (line [0] == '#')
                    continue;

                // Loop through blocks in each line
                foreach (string s in line.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries)) {
                    SetToken st;
                    int temp = 0;
                    // comment reached, goto next line
                    if (s.Contains ("#"))
                        break;

                    // MULT
                    if (s.ToString ().ToUpper() [0] == 'X' && s.Length == 1)
                        st = new SetToken (SetTokenType.MULT, s, iLineCount);

                    // INTEGER
                    else if (int.TryParse (s, out temp))
                        st = new SetToken (SetTokenType.INTEGER, s, iLineCount);

                    // INTERVAL
                    else if (Regex.IsMatch (s, "[0-9]*[0-9]*:*[0-9]*[0-9]:[0-9][0-9]"))
                        st = new SetToken (SetTokenType.INTERVAL, s, iLineCount);

                    // WORD, assume anything else is a word
                    else
                        st = new SetToken (SetTokenType.WORD, s, iLineCount);

                    m_ltTokens.Add (st);
                } // foreach block
            } // foreach line
            m_ltTokens.Add (new SetToken (SetTokenType.EOF, "EOF", iLineCount));
        }
示例#8
0
        /// <summary>
        /// Parse SetToken list matching the following BNF:
        /// SetList ::= Integer Mult Integer Interval Stroke {Comment}
        /// Interval ::= {{Digit} Digit : } {Digit} Digit : Digit Digit
        /// Stroke  ::= Word
        /// Comment ::= {Word} | {{Word} Word}
        /// Word	::= Letter | Word Letter
        /// Letter  ::= {any latin letter}
        /// Integer ::= Digit | Integer Digit
        /// Digit   ::= 0|1| ... | 9
        /// Mult	::= x|X
        /// </summary>
        private void SetParse()
        {
            int number, distance;
            string interval, stroke, comment;

            m_curToken = NextToken ();
            while ( m_curToken != null && m_curToken.Type != SetTokenType.EOF) {
                comment = ""; // reset comment

                number = int.Parse (m_curToken.Value);
                Match (SetTokenType.INTEGER);

                Match (SetTokenType.MULT);

                distance = int.Parse (m_curToken.Value);
                Match (SetTokenType.INTEGER);

                interval = m_curToken.Value;
                Match (SetTokenType.INTERVAL);

                stroke = m_curToken.Value;
                Match (SetTokenType.WORD);

                // Comments are optional
                if (m_curToken.Type == SetTokenType.WORD) {
                    // Comments
                    int curLine = m_curToken.LineNumber;
                    for (; m_curToken != null && m_curToken.Type != SetTokenType.EOF &&
                        m_curToken.LineNumber != curLine + 1; Match (SetTokenType.WORD))
                        comment += m_curToken.Value + " ";
                } // if
                m_llSetList.AddLast (new Set (number, distance, stroke, comment, interval));
            } // main loop
        }