Click here to Skip to main content
15,887,596 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I'm feeling "diverse" today Pin
megaadam10-Jun-22 6:13
professionalmegaadam10-Jun-22 6:13 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch10-Jun-22 6:29
mvahoney the codewitch10-Jun-22 6:29 
AnswerRe: I'm feeling "diverse" today Pin
klinkenbecker10-Jun-22 7:40
klinkenbecker10-Jun-22 7:40 
GeneralRe: I'm feeling "diverse" today Pin
Daniel Pfeffer10-Jun-22 4:17
professionalDaniel Pfeffer10-Jun-22 4:17 
GeneralRe: I'm feeling "diverse" today Pin
Member 916705712-Jun-22 20:30
Member 916705712-Jun-22 20:30 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch12-Jun-22 20:46
mvahoney the codewitch12-Jun-22 20:46 
GeneralRe: I'm feeling "diverse" today Pin
Member 916705712-Jun-22 21:59
Member 916705712-Jun-22 21:59 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch12-Jun-22 22:04
mvahoney the codewitch12-Jun-22 22:04 
I'm just basically using C# to generate an array for my C++ code to traverse. The C# code is a console application.

I feed it a regular expression on the command line and it produces a small amount of C++ code to declare an array as its output - for example:

C++
int16_t dfa_table[] = {
        -1, 1, 6, 1, 34, 34, -1, 1, 12, 1, 117, 117, -1, 1, 18,
        1, 110, 110, -1, 1, 24, 1, 105, 105, -1, 1, 30, 1, 120, 120,
        -1, 1, 36, 1, 116, 116, -1, 1, 42, 1, 105, 105, -1, 1, 48,
        1, 109, 109, -1, 1, 54, 1, 101, 101, -1, 1, 60, 1, 34, 34,
        -1, 1, 66, 1, 58, 58, 0, 0
};


That's a DFA table. What it is is a state machine encoded into an array. I have C++ code that can walk it in order to run the regular expression. The walking code is easy and efficient. Generating the array is not easy.

That C# console application uses a regular expression engine I wrote (in C#) in order to generate that C++ array. The code to run the regular expression is simple and is in C++:

C++
bool match(const int16_t* dfa, int16_t(read_cb)(void*), void* cb_state = nullptr) {
    int tlen;
    int tto;
    int prlen;
    int pmin;
    int pmax;
    int i;
    int j;
    int ch;
    int state = 0;
    bool done;
    bool found = false;
    int acc = -1;
    ch = read_cb(cb_state);
    while (ch != -1) {
        acc = -1;
        done = false;
        while (!done) {
        start_dfa:
            done = true;
            acc = dfa[state++];
            tlen = dfa[state++];
            for (i = 0; i < tlen; ++i) {
                tto = dfa[state++];
                prlen = dfa[state++];
                for (j = 0; j < prlen; ++j) {
                    pmin = dfa[state++];
                    pmax = dfa[state++];
                    if (ch < pmin) break;
                    if (ch <= pmax) {
                        found = true;
                        ch = read_cb(cb_state);
                        state = tto;
                        done = false;

                        goto start_dfa;
                    }
                }
            }
        }
        if (acc != -1) {
            return found;
        }
        ch = read_cb(cb_state);
        state = 0;
    }
    return false;
}

To err is human. Fortune favors the monsters.

GeneralRe: I'm feeling "diverse" today Pin
Member 916705712-Jun-22 22:06
Member 916705712-Jun-22 22:06 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch12-Jun-22 22:19
mvahoney the codewitch12-Jun-22 22:19 
GeneralRe: I'm feeling "diverse" today Pin
Member 916705712-Jun-22 22:30
Member 916705712-Jun-22 22:30 
GeneralRe: I'm feeling "diverse" today Pin
honey the codewitch12-Jun-22 22:32
mvahoney the codewitch12-Jun-22 22:32 
GeneralRe: I'm feeling "diverse" today Pin
maze313-Jun-22 0:06
professionalmaze313-Jun-22 0:06 
RantI may never understand crypto-folk Pin
Kent Sharkey9-Jun-22 10:29
staffKent Sharkey9-Jun-22 10:29 
GeneralRe: I may never understand crypto-folk Pin
Nelek9-Jun-22 10:45
protectorNelek9-Jun-22 10:45 
GeneralRe: I may never understand crypto-folk Pin
theoldfool9-Jun-22 11:25
professionaltheoldfool9-Jun-22 11:25 
GeneralRe: I may never understand crypto-folk Pin
Dan Neely10-Jun-22 3:21
Dan Neely10-Jun-22 3:21 
General"We GOT your payment..." Pin
Marc Clifton9-Jun-22 6:33
mvaMarc Clifton9-Jun-22 6:33 
GeneralRe: "We GOT your payment..." Pin
Richard MacCutchan9-Jun-22 6:45
mveRichard MacCutchan9-Jun-22 6:45 
GeneralRe: "We GOT your payment..." Pin
PIEBALDconsult9-Jun-22 6:47
mvePIEBALDconsult9-Jun-22 6:47 
GeneralRe: "We GOT your payment..." Pin
RickZeeland9-Jun-22 6:52
mveRickZeeland9-Jun-22 6:52 
GeneralRe: "We GOT your payment..." Pin
User 49097410-Jun-22 1:18
User 49097410-Jun-22 1:18 
RantRe: "We GOT your payment..." PinPopular
Greg Utas9-Jun-22 7:03
professionalGreg Utas9-Jun-22 7:03 
GeneralRe: "We GOT your payment..." Pin
Wizard of Sleeves9-Jun-22 20:31
Wizard of Sleeves9-Jun-22 20:31 
GeneralRe: "We GOT your payment..." Pin
MarkTJohnson9-Jun-22 7:22
professionalMarkTJohnson9-Jun-22 7:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.