1 / 22

Extensible syntax analyzers

Extensible syntax analyzers. Pavel Egorov pe@skbkontur.ru. Problem statements. L – some formal language; T : L  R – it’s translator; L ext  L – some extended language; T ext : L ext  R ext – it’s extended translator.    L T ext (  ) = T( ) We want compatibility!.

mercia
Download Presentation

Extensible syntax analyzers

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. Extensible syntax analyzers Pavel Egorov pe@skbkontur.ru

  2. Problem statements L – some formal language; T : L  R – it’s translator; Lext L – some extended language; Text : Lext Rext – it’s extended translator. L Text () = T() We want compatibility!

  3. Disclaimer • Consider syntax analyzers only. • Fixed algorithm of syntax analysis. • Extension due to modification of the grammar only.

  4. What is syntax analyzer? • SA converts a word to a syntax tree. • What is syntax tree? • Root is labeled by the axiom of the grammar • Inner nodes are labeled by non-terminals • Leaf nodes are labeled by terminals or non-terminals or e

  5. Classic parse tree A Grammar: AaBd B  b B  A Word: “aabdd” Derivation: A aBd  aAd   aaBdd  aabdd a B d A a B d b

  6. Classic parse treeIs it good enough? G1: Aabc Extended G2: AaBc Bb Word: “abc” A a b c They are different! A a B c b

  7. Classic parse treeIs it good enough? G1: Aa Extended G2: AaE Ee Word: “a” A a They are different! A a E e

  8. Cancelled tree • Driven by labeled grammar • Cut off some inner nodes from parse tree • Cut off e-leafs from parse tree Is much better for parser extension!

  9. Cancelled tree example parse tree A Labeled grammar: A a1B0d0B1 B b1E0 B  x1 E  e0 • Symbols labeled by 0 are not present in tree • e-leafs are always labeled by 0 B a B d x b E e A B a b cancelled tree x

  10. Intermediate results • Labeled grammar • Syntax analyzer driven by labeled grammar • Canceled tree as a result of syntax analysis So how can we extend grammars without breaking compatibility? Compatibility:L SAext () = SA ()

  11. Extending transformations of grammars f – extending grammar transformation G - grammar L(f(G))L(G)

  12. Extending transformations • ADD-transform adds some fixed new production to a grammar. • EXTRACT-transform: before: Aaxbygz after: AaxB0gz Bby

  13. Extending transformations AE* all transforms, composed from arbitrary number of ADD- and EXTRACT-transforms.

  14. Results

  15. Compatibility • Any transform from AE* doesn’t break compatibility of corresponding syntax analyzers. • A grammar extended by AE* transform has the same production labeling as initial grammar has on the common productions. (AE* doesn’t change labeling of unchanged productions)

  16. Independent transforms G y1, y2AE* y1 y2 G2 Domain(y1) ? G1 Domain(y2) ? G1 G2 G12??? When it is possible? How can we do it?

  17. Independent transforms What if G1 Domain(y2)? Sometimes we can solve this problem! Aabgd y1: AabCd; C  g y2: AaBd; Bbg y2/y1: A  aBd; BbC Conflict! Decision!

  18. y/f - afixed transform • y/f - “fixed” y, which can be applied after f • Sometimes we can’t fix y...  Aabg y: AXg; X ab f: AaY; Y bg • Recursive definition of the function y/f for y and f from AE*. • Sometimes y/f is not defined.

  19. Independent transforms G y1 y2 G1 G2 y2/ y1 y1/ y2 ? G12 G21 y2/ y1y1? y1/ y2y2

  20. Independent transforms G y1 y2 G1 G2 y2/ y1 y1/ y2 G12 y2/ y1y1 = y1/ y2y2

  21. Conclusion • Syntax analyzers • driven by labeled grammars • cancelled trees as a result • AE* - a way to extend grammars safelly • y/f – a way to compose independent grammar transforms • Order of application of the extending transforms doesn’t matter!

  22. Thank you!Questions?

More Related