skvadrik / re2c

Lexer generator for C, C++, Go and Rust.
https://re2c.org
Other
1.06k stars 168 forks source link

Pure C API for generating DFA #479

Open whisper-bye opened 2 months ago

whisper-bye commented 2 months ago

Is there a C API that can be called directly to generate the data structures for the DFA? For example, take some regular expressions and generate a state transition diagram of a state machine

skvadrik commented 2 months ago

If you mean linking with re2c as a library, there's no API.

For state transition diagram you can use the DOT backend to generate a graph in .dot format (-D option).

There are also various debug options --dump-nfa, --dump-dfa-raw etc., see https://re2c.org/manual/manual_c.html#options. They only work if re2c was built in debug mode.

Finally, you may be able to generate some custom output using syntax files (they are primarily meant for adding new language backends). There is ongoing work on the syntax-files branch, see #450.

whisper-bye commented 2 months ago

Thank you for your reply. I think this is a useful feature that allows generating a state machine without having to write RE files. When Manually writing the lexer, I can effortlessly obtain a minimized DFA to guide the process.