Beispiel #1
0
        public void addRegExp(int regExpNum)
        {
            if (Options.DEBUG)
            {
                Out.debug("Adding nfa for regexp " + regExpNum + " :" + Out.NL + regExps.getRegExp(regExpNum));
            }

            IntPair nfa = insertNFA(regExps.getRegExp(regExpNum));

            IEnumerator lexStates = regExps.getStates(regExpNum).GetEnumerator();

            if (!lexStates.MoveNext())
            {
                lexStates = scanner.states.getInclusiveStates();
            }

            lexStates.Reset();

            while (lexStates.MoveNext())
            {
                int stateNum = (int)lexStates.Current;

                if (!regExps.isBOL(regExpNum))
                {
                    addEpsilonTransition(2 * stateNum, nfa.start);
                }

                addEpsilonTransition(2 * stateNum + 1, nfa.start);
            }


            if (regExps.getLookAhead(regExpNum) != null)
            {
                IntPair look = insertNFA(regExps.getLookAhead(regExpNum));

                addEpsilonTransition(nfa.end, look.start);

                Action a = regExps.getAction(regExpNum);
                a.setLookAction(true);

                isPushback[nfa.end] = true;
                action[look.end]    = a;
                isFinal[look.end]   = true;
            }
            else
            {
                action[nfa.end]  = regExps.getAction(regExpNum);
                isFinal[nfa.end] = true;
            }
        }
Beispiel #2
0
        /**
         * Performs semantic analysis for all expressions.
         *
         * Currently: illegal lookahead check only
         * [fixme: more checks possible]
         *
         * @param rs   the reg exps to be checked
         * @param m    the macro table (in expanded form)
         * @param max  max character of the used charset (for negation)
         * @param f    the spec file containing the rules [fixme]
         */
        public static void check(RegExps rs, Macros m, char max, File f)
        {
            macros  = m;
            maxChar = max;

            bool errors = false;
            int  num    = rs.getNum();

            for (int i = 0; i < num; i++)
            {
                RegExp r = rs.getRegExp(i);
                RegExp l = rs.getLookAhead(i);

                if (!checkLookAhead(r, l))
                {
                    errors = true;
                    Out.error(f, ErrorMessages.LOOKAHEAD_ERROR, rs.getLine(i), -1);
                }
            }

            if (errors)
            {
                throw new GeneratorException();
            }
        }