1 / 33

A Tool for Constructing Syntax-Directed Editors

A Tool for Constructing Syntax-Directed Editors. Yung-Shen Chang and Nai-Wei Lin Department of Computer Science and Information Engineering National Chung-Cheng University Taiwan, R.O.C. Outline. Introduction A generator for incremental parsers A simple interface to incremental parsers

joshua-cruz
Download Presentation

A Tool for Constructing Syntax-Directed Editors

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. A Tool for Constructing Syntax-Directed Editors Yung-Shen Chang and Nai-Wei Lin Department of Computer Science and Information Engineering National Chung-Cheng University Taiwan, R.O.C.

  2. Outline • Introduction • A generator for incremental parsers • A simple interface to incremental parsers • Conclusions and future work

  3. Edit Compile Found Bugs Edit Compile Found Bugs Typical Program Development Cycle • Program editing and program compilation are separated. • It is more efficient if we can do program editing and program compilation at the same time.

  4. Syntax-Directed Editors • Syntax-directed editors have the ability to perform program editing and program compilation at the same time. • Syntax-directed editors have become an integral feature for modern integrated development environment.

  5. Incremental Parsing • The main capability of syntax-directed editors is incremental parsing. • Incremental parsing has the ability to only parse the modified portion of a program. • This ability allows us to interleave program editing and program compilation.

  6. Contributions • A generator for incremental parsers that is based on Bison. • A simple interface to incremental parsers to facilitate the integration of editors and incremental parsers to form syntax-directed editors.

  7. Grammar definition (sample.y) Parser (sample.tab.c) Bison Bison

  8. Outline • Introduction • A generator for incremental parsers • A simple interface to incremental parsers • Conclusions

  9. Incremental Parsing Algorithms • The state matching incremental parsing algorithm (Larchêveque) • no need to change Bison parsing table • The sentential-form incremental parsing algorithm (Wagner) • need to change Bison parsing table

  10. Threaded Tree Parsing • Use threaded tree data structure to represent the parse tree • Threaded tree is a combination of parse tree and parse stack • All shift/reduce actions are operated on the threaded tree

  11. Threaded Parse Tree • Each node in the threaded tree has the following fields • symbol • children • state • threading

  12. Shift Action • Shift symbol M at state S • construct a node N (M, S) • set N’s threading to TOS • set TOS (Top of Stack) as N TOS N1 N (M, S)

  13. Reduce Action • Reduce symbol M at State S with k children • construct a node N (M, S) • collect k nodes from TOS • construct connections between N and its children • set N’s threading to leftmost node of its children • set TOS as N M → sr N(M,S) N1 s1 r2 TOS

  14. An Example Input= fghf Action: Shift f2 Shift g6 Reduce G4 Shift h9 Reduce H7 Reduce F3 Shift f6 Reduce S1 S1 TOS f2 F3 f6 BOS G4 H7 g6 h9

  15. Incremental Threaded Tree Parsing • Split previous parse tree into three parts x y z • x and z are unmodified parts • y is the modified part • Let y’ be the modifying content x y z

  16. Incremental Threaded Tree Parsing • Finding initial configuration (x) • Parse exhaustively (y’) • Finding optimal grafting point from candidates (z) • Perform node grafting

  17. Finding Candidates • A grafting point must be a common ancestor of y’ and y • We start searching from nearest common ancestor (NCA)

  18. Proper Grafting Points • A candidate for a grafting point is an NCA n such that • terminal successor of n = current lookahead • symbol of n = symbol of the TOS • predecessor of n = predecessor of the TOS

  19. = deleted node An Example S1 Grafting Point BOS0 F3 f6 f2 F3 G4 x: g5 y: g8 z: h9, f6 H7 G4 g8 TOS NCA g5 h9 lookahead

  20. incparser parser 4 Perform grafting if find suitable grafting point Incremental Parser Modules 3 1 Perform action (shift/reduce) input read manage tree node node 2 node Determine what to do … Parsing table reader read = module Bison Parsing Table = file

  21. Outline • Introduction • A generator for incremental parsers • A simple interface to incremental parsers • Conclusions

  22. Interface to Incremental Parser • Editor calls incparser to get service from incremental parser • Editor passes parameters begin, end, and delta • incparser will store the parsing result in variable err void incparser (POS begin, POS end, conststring& delta, ERR& err);

  23. Flow of an Incremental Parsing Session 6 5 Return parse result Return parse result interface incparser editor 1 Call interface 3 Wrapper call incparser 2 Write delta Temporary file 4 Read input from temporary file

  24. Proper Timing to Trigger Incremental Parsing • By timer • By each key press • By editing model

  25. Editing Model • Editing is a sequence of key presses • Classify key presses into two groups • modikeys–which will cause content change • non-modikeys–which won’t cause content change • Editing causes a state change between pressing modikeys and non-modikeys • Editor should remember BEGIN and END position when a state change occurs

  26. Special Keys • BS (Backspace)/DEL are keys in modikeysthat need special treatments • BS might change theBEGIN position • DEL might change the END position • Editor should perform appropriate action when user pressing BS/DEL • We use a counter to maintain how many modikeys are pressed (except BS/DEL)

  27. An Example • Assume that the cursor is at the position between “ma”, “in”, the editor is atnon-modikey state • User performs the following modifications • press BS two times • press DEL two times • key in “foo_function” • key in any non-modikeys

  28. 01 int main (void) { 02 printf(“Hello, World\n”); 03 return 0; 04 } 01 int in (void) { 02 printf(“Hello, World\n”); 03 return 0; 04 } An Example (cont.) • Initial situation • cursor at (1, 7) • BEGIN and END is N/A • Pressing BS two times • cursor at (1, 5) • BEGIN = (1, 5) • END = (1, 8)

  29. 01 int in (void) { 02 printf(“Hello, World\n”); 03 return 0; 04 } 01 int (void) { 02 printf(“Hello, World\n”); 03 return 0; 04 } An Example (cont.) • Press DEL two times • cursor at (1, 5) • BEGIN = (1, 5) • END = (1, 10)

  30. 01 int (void) { 02 printf(“Hello, World\n”); 03 return 0; 04 } 01 int foo_function (void) { 02 printf(“Hello, World\n”); 03 return 0; 04 } An Example (cont.) • Key in “foo_function” • cursor at (1, 17) • BEGIN = (1, 5) • END = (1, 10) • DELTA = “foo_function” • Press any non-modikeys Call incparser by • BEGIN = (1, 5) • END = (1, 10) • DELTA = “foo_function”

  31. Outline • Introduction • A generator for incremental parsers • A simple interface to incremental parsers • Conclusions

  32. Conclusions • We developed a generator for incremental parsers based on Bison • We introduced a simpleinterfaceto incremental parsers that facilitate integration of an incremental parser and an editor based on editing model

  33. Future Work • A generator for incremental lexers • A generator for incremental semantics analyzers • A generator for syntax-directed editors

More Related