http://www.perlmonks.org?node_id=1058445


in reply to Lexing: how to define tokens based on "context"

That looks like a really nice Lexer, but I must admit that I have become very fond of Parse::RecDescent.   Yes, a full-on parser, driven by a grammar.   I’ve asked that tool to do fairly-ridiculous things, like parsing a conglomeration of SAS programs, Korn shell scripts and Tivoli schedule files ... hundreds of ’em ... and it Just Did It™ with style and grace.   I would basically take that approach instead of building my own program to navigate through the file’s semantic structure, even with a good Lexer by my side.

Furthermore, you can find an EBNF grammar-description for the Sudoers file here:   http://www.sudo.ws/sudoers.man.html.   No, P::RD does not handle such grammars directly (although other Perl parsers do ...), but it shows you outright what the proper grammar structure ought to be.   I think that this might save you a lot of messy coding.

  • Comment on Re: Lexing: how to define tokens based on "context"

Replies are listed 'Best First'.
Re^2: Lexing: how to define tokens based on "context"
by three18ti (Monk) on Oct 17, 2013 at 07:14 UTC

    >> but I must admit that I have become very fond of Parse::RecDescent

    Wow... that looks. complicated... I'm sure if I study the manual long enough I can figure it out. Looks fairly powerful though. Thanks for the link.

    >> Furthermore, you can find an EBNF grammar-description for the Sudoers file here: http://www.sudo.ws/sudoers.man.html.

    You know... when I first started on this project, I found that page but had no idea what an EBNF was. Thanks for pointing that out again, it certainly does help me define my rules.