Download
npeg net parsing expression grammar n.
Skip this Video
Loading SlideShow in 5 Seconds..
NPEG - .NET Parsing Expression Grammar PowerPoint Presentation
Download Presentation
NPEG - .NET Parsing Expression Grammar

NPEG - .NET Parsing Expression Grammar

196 Vues Download Presentation
Télécharger la présentation

NPEG - .NET Parsing Expression Grammar

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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