[Datadraw-user] BNF in 42
Brought to you by:
smilindog2000
From: Bill C. <bi...@bi...> - 2008-12-28 10:41:57
|
Hi, Richard. I've written a ton of lex/yacc flex/bison based parsers. Here's one thing I've found. Most formats are context sensitive. You just can't parse them the easy way, but have to build a parse tree and then traverse it manually to extract data. Icky, but true. This is massively true for VHDL, even thought the Preface of the VHDL Language Reference says it's not. It's even true for Verilog. Simple formats, like Synopsys Liberty format, are massively context dependent. In 42, I figured I'd give up on allowing generic code to execute for each matched rule, and just go ahead and build a parse tree for the user. That separates all the application specific code from the grammar definition, and should help make the grammars more reusable and easier to read. I allow strings in the grammar rules to be lex-style regular expressions. What do you think? The attached file is a grammar that I currently parse to build a parser rule database. Then, I'm planning to write a BNF interpreter and re-parse this file using the rules defined in the file. Once that works, I was planning to start writing the rest of the core 42 parser in 42 directly, and then start on the interpreter for it. When the interpreter is running, I can start writing libraries to compile more advanced 42 constructs into simpler code which can be directly written out in C. Anyway, that's the plan... too bad the holidays wont last forever - I'll probably have to get too focused on real work to make much progress come January. Regards, Bill Regards, Bill |