Esempio n. 1
0
        string TransitionFunction(char c)
        {
            string ret = STATE_INIT;

            if (mode_stream)
            {
                AccumulateStream(c);
            }

            PdfStateTransition transition = FindTransition(c);

            if (transition != null)
            {
                if (transition.back == 0)
                {
                    Accumulate(c);
                    this.current_token.type = transition.state_out;
                }

                this.current_state = transition.state_out;
                this.read_offset  -= transition.back;

                if (transition.acceptance)
                {
                    if (this.current_token.lexeme == "stream")
                    {
                        mode_stream       = true;
                        stream_token      = new PdfToken();
                        stream_token.type = "STREAM";
                    }

                    if (this.current_token.lexeme == "endstream")
                    {
                        mode_stream = false;
                        this.tokens.Add(this.stream_token);
                    }

                    this.tokens.Add(this.current_token);
                    this.current_token = new PdfToken();
                    this.current_state = STATE_INIT;
                }
            }

            return(ret);
        }
Esempio n. 2
0
        public PdfLexer()
        {
            this.current_state = STATE_INIT;
            this.read_offset   = 0;
            this.current_token = new PdfToken();
            this.tokens        = new List <PdfToken>();

            this.transition_table = new List <PdfStateTransition>();

            this.AddStateTransition(STATE_INIT, "%", "COMMENT");
            this.AddStateTransition("COMMENT", "[^\r]", "COMMENT");
            this.AddStateTransition("COMMENT", "\r", "COMMENT", acceptance: true, back: 1);

            this.AddStateTransition(STATE_INIT, PATTERN_NUMBER, "NUMBER");
            this.AddStateTransition("NUMBER", PATTERN_NUMBER, "NUMBER");
            this.AddStateTransition("NUMBER", PATTERN_NO_NUMBER, "NUMBER", acceptance: true, back: 1);

            // TODO, probablement elsigno + y menos solo podrá estar en primre lugar al ser números

            this.AddStateTransition(STATE_INIT, "<", "<");
            this.AddStateTransition("<", "<", "<<", acceptance: true);

            this.AddStateTransition("<", PATTERN_HEXA, "HEXA");
            this.AddStateTransition("HEXA", PATTERN_HEXA, "HEXA");
            this.AddStateTransition("HEXA", ">", "HEXA", acceptance: true);


            this.AddStateTransition(STATE_INIT, ">", ">");
            this.AddStateTransition(">", ">", ">>", acceptance: true);

            this.AddStateTransition(STATE_INIT, "\\(", "STRING");
            this.AddStateTransition("STRING", "[^\\)]", "STRING");
            this.AddStateTransition("STRING", "\\)", "STRING", acceptance: true);


            this.AddStateTransition(STATE_INIT, @"\[", "[", acceptance: true);
            this.AddStateTransition(STATE_INIT, @"\]", "]", acceptance: true);

            this.AddStateTransition(STATE_INIT, "/", "NAME");
            this.AddStateTransition("NAME", PATTERN_NO_SEPARATOR, "NAME");
            this.AddStateTransition("NAME", PATTERN_SEPARATOR, "NAME", acceptance: true, back: 1);

            this.AddStateTransition(STATE_INIT, "t", "t");
            this.AddStateTransition("t", "r", "tr");
            this.AddStateTransition("tr", "u", "tru");
            this.AddStateTransition("tru", "e", "BOOLEAN", acceptance: true);

            this.AddStateTransition(STATE_INIT, "f", "f");
            this.AddStateTransition("f", "a", "fa");
            this.AddStateTransition("fa", "l", "fal");
            this.AddStateTransition("fal", "s", "fals");
            this.AddStateTransition("fals", "e", "BOOLEAN", acceptance: true);

            this.AddStateTransition(STATE_INIT, "o", "o");
            this.AddStateTransition("o", "b", "ob");
            this.AddStateTransition("ob", "j", STATE_KEYWORD, acceptance: true);

            this.AddStateTransition(STATE_INIT, "e", "e");
            this.AddStateTransition("e", "n", "en");
            this.AddStateTransition("en", "d", "end");
            this.AddStateTransition("end", "o", "endo");
            this.AddStateTransition("endo", "b", "endob");
            this.AddStateTransition("endob", "j", STATE_KEYWORD, acceptance: true);

            this.AddStateTransition(STATE_INIT, "s", "s");
            this.AddStateTransition("s", "t", "st");
            this.AddStateTransition("st", "r", "str");
            this.AddStateTransition("str", "e", "stre");
            this.AddStateTransition("stre", "a", "strea");
            this.AddStateTransition("strea", "m", STATE_KEYWORD, acceptance: true);

            this.AddStateTransition("end", "s", "ends");
            this.AddStateTransition("ends", "t", "endst");
            this.AddStateTransition("endst", "r", "endstr");
            this.AddStateTransition("endstr", "e", "endstre");
            this.AddStateTransition("endstre", "a", "endstrea");
            this.AddStateTransition("endstrea", "m", STATE_KEYWORD, acceptance: true);
        }