1 / 8

NPEG - .NET Parsing Expression Grammar

NPEG - .NET Parsing Expression Grammar. Leblanc Meneses Robust Haven Inc. What is it?. Implements PEG Bryan Ford – PEG @ MIT 2004 Martin.Holzherr – 2008 codeproject Other Comparable Frameworks: LL(*) ANTLR , LALR(1) Irony

lisbet
Télécharger la présentation

NPEG - .NET Parsing Expression Grammar

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NPEG - .NET Parsing Expression Grammar Leblanc Meneses Robust Haven Inc.

  2. What is it? • Implements PEG • Bryan Ford – PEG @ MIT 2004 • Martin.Holzherr – 2008 codeproject • Other Comparable Frameworks: LL(*) ANTLR , LALR(1) Irony • How do they handle predicates (lookahead/lookbehind) how far? • How they handle ambiguity • ScannerlessParser (no need for scanner or parser code generation) – run in memory • Infinite lookahead, doesn’t care about ambiguity – prioritized choice. • Today: Can be deployed natively to C, C++, C#, and Java • Embedded, Mobile, Desktop • TDD Built – so the framework has a solid regression harness. To continue it’s up keep. • Can READ and WRITE itself! – DSL is written with NPEG.

  3. Where is it used? • Custom DSL (NPEG) – Domain Specific Languages • Parse any proprietary format (Gerber files) • Flexibleconfig • Configuration based on product, branch, developer, environment, task • Staging, production, production snapshot, disaster recovery environments • When web.config transformations become cumbersome • SqlObfuscate • Production data back to development – RegexObfuscateStrategy • Content Management System

  4. Backlog Items • Language Workbench *** • Unit test terminals/nonterminals • Output to all supported languages • Better error reporting and debugging rules • Save Memory - remove “Value” from the AstNode • Should be using iterator->Text(node.Start, node.End) • Build a grammar optimizer • Collapse rules -> “x” “x” “x” -> “x”{3} • De Morgans Theorem • Upcoming: Javascript & PHP (already started) implementation • Browser – example: knockoutjs clone. • Research: • Language Implementation

  5. How to start? • Terminals, Non Terminals – Predicates ***

  6. Hello world string input = "hello world"; AExpressionparseTree= PEGrammar.Load(@"(?<Expression>): 'Hello World'\i;"); visitor = new NpegParserVisitor(new StringInputIterator(input)); parseTree.Accept(visitor); Assert.IsTrue(visitor.IsMatch); AstNodenode = visitor.AST; Assert.IsTrue(node.Token.Name == "Expression"); Assert.IsTrue(node.Token.Value == input);

  7. Boolean Algebra S: [\s]+; (?<Gate>): ('*' / 'AND') / ('~*' / 'NAND') / ('+' / 'OR') / ('~+' / 'NOR') / ('^' / 'XOR') / ('~^' / 'XNOR'); ValidVariable: '""' (?<Variable>[a-zA-Z0-9]+) '""' / '\'' (?<Variable>[a-zA-Z0-9]+) '\'' / (?<Variable>[a-zA-Z]); VarProjection1: ValidVariable / (?<Invertor>'!' ValidVariable); VarProjection2: VarProjection1 / '(' Expression ')' / (?<Invertor>'!' '(' Expression ')'); Expression: S? VarProjection2 S? (Gate S? VarProjection2 S?)*; (?<BooleanEquation>): Expression !.; • ((A)*(!(B))+(!(A))*(B)) • ((((!X*Y*Z)+(!X*Y*!Z)+(X*Z)))) • 'aA'*!'bB'+!'aA'*'bB'

  8. Feedback • Leblanc Meneses • @leblancmeneses • http://about.me/leblancmeneses • https://github.com/leblancmeneses • leblanc@robusthaven.com

More Related