A Tool for Constructing Syntax-Directed Editors Yung-Shen Chang and Nai-Wei Lin Department of Computer Science and Information Engineering National Chung-Cheng.

Slides:



Advertisements
Similar presentations
Compiler Construction
Advertisements

CPSC 388 – Compiler Design and Construction
Symbol Table.
Grammar and Algorithm }
A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Lesson 8 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
ISBN Chapter 10 Implementing Subprograms.
Syntax Trees MathWorks Compiler Course – Day 5. Syntax Trees MathWorks Compiler Course – Day 5 Parser lexemes shift/reduce seq. Cfg tables Tree Symbols.
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
6/12/2015Prof. Hilfinger CS164 Lecture 111 Bottom-Up Parsing Lecture (From slides by G. Necula & R. Bodik)
Top-Down Parsing.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
ISBN Chapter 4 Lexical and Syntax Analysis The Parsing Problem Recursive-Descent Parsing.
Prof. Fateman CS 164 Lecture 91 Bottom-Up Parsing Lecture 9.
Professor Yihjia Tsai Tamkang University
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
9/27/2006Prof. Hilfinger, Lecture 141 Parsing Odds and Ends Lecture 14 (P. N. Hilfinger, plus slides adapted from R. Bodik)
CSC3315 (Spring 2009)1 CSC 3315 Lexical and Syntax Analysis Hamid Harroud School of Science and Engineering, Akhawayn University
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
Invitation to Computer Science 5th Edition
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
LR Parsing Compiler Baojian Hua
Semantic Analysis (Generating An AST) CS 471 September 26, 2007.
1 Week 4 Questions / Concerns Comments about Lab1 What’s due: Lab1 check off this week (see schedule) Homework #3 due Wednesday (Define grammar for your.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Top-Down Parsing - recursive descent - predictive parsing
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
LANGUAGE TRANSLATORS: WEEK 3 LECTURE: Grammar Theory Introduction to Parsing Parser - Generators TUTORIAL: Questions on grammar theory WEEKLY WORK: Read.
Lesson 10 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
RELATIONAL FAULT TOLERANT INTERFACE TO HETEROGENEOUS DISTRIBUTED DATABASES Prof. Osama Abulnaja Afraa Khalifah
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Lexical and Syntax Analysis
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
CMSC 331, Some material © 1998 by Addison Wesley Longman, Inc. 1 Chapter 4 Chapter 4 Bottom Up Parsing.
Syntactic Analysis Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
Lesson 5 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Dependency Parser for Swedish Project for EDA171 by Jonas Pålsson Marcus Stamborg.
Towards the better software metrics tool motivation and the first experiences Gordana Rakić Zoran Budimac.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
Prof. Necula CS 164 Lecture 8-91 Bottom-Up Parsing LR Parsing. Parser Generators. Lecture 6.
1 Using Yacc. 2 Introduction Grammar –CFG –Recursive Rules Shift/Reduce Parsing –See Figure 3-2. –LALR(1) –What Yacc Cannot Parse It cannot deal with.
111 Chapter 6 LR Parsing Techniques Prof Chung. 1.
Chapter 1 Introduction Major Data Structures in Compiler
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Bottom-Up Parsing David Woolbright. The Parsing Problem Produce a parse tree starting at the leaves The order will be that of a rightmost derivation The.
Concepts and Realization of a Diagram Editor Generator Based on Hypergraph Transformation Author: Mark Minas Presenter: Song Gu.
COMPILERS 4 TH SEPTEMBER 2013 WEDNESDAY 11CS10045 SRAJAN GARG.
Chap. 7, Syntax-Directed Compilation J. H. Wang Nov. 24, 2015.
Bottom Up Parsing CS 671 January 31, CS 671 – Spring Where Are We? Finished Top-Down Parsing Starting Bottom-Up Parsing Lexical Analysis.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
CS 154 Formal Languages and Computability March 22 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
COMPILER CONSTRUCTION
CS 2130 Lecture 18 Bottom-Up Parsing or Shift-Reduce Parsing Warning: The precedence table given for the Wff grammar is in error.
Chapter4 Syntax-Directed Translation Introduction : 1.In the lexical analysis step, each token has its attribute , e.g., the attribute of an id is a pointer.
Lecture 9 Symbol Table and Attributed Grammars
Announcements/Reading
Introduction to Compiler Construction
Constructing Precedence Table
Programming Languages Translator
Lexical and Syntax Analysis
Introduction CI612 Compiler Design CI612 Compiler Design.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Subject: Language Processor
High-Level Programming Language
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

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 Introduction A generator for incremental parsers A generator for incremental parsers A simple interface to incremental parsers A simple interface to incremental parsers Conclusions and future work Conclusions and future work

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

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 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. 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. The main capability of syntax-directed editors is incremental parsing. Incremental parsing has the ability to only parse the modified portion of a program. 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. This ability allows us to interleave program editing and program compilation.

6 Contributions A generator for incremental parsers that is based on Bison. 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. A simple interface to incremental parsers to facilitate the integration of editors and incremental parsers to form syntax- directed editors.

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

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

9 Incremental Parsing Algorithms The state matching incremental parsing algorithm (Larchêveque) The state matching incremental parsing algorithm (Larchêveque) –no need to change Bison parsing table The sentential-form incremental parsing algorithm (Wagner) 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 Use threaded tree data structure to represent the parse tree Threaded tree is a combination of parse tree and parse stack Threaded tree is a combination of parse tree and parse stack All shift/reduce actions are operated on the threaded tree All shift/reduce actions are operated on the threaded tree

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

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

13 Reduce Action Reduce symbol M at State S with k children Reduce symbol M at State S with k children 1.construct a node N (M, S) 2.collect k nodes from TOS 3.construct connections between N and its children 4.set N ’s threading to leftmost node of its children 5.set TOS as N N1N1 N(M,S) s1s1 r2r2 TOS → M → sr

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

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

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

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

18 Proper Grafting Points A candidate for a grafting point is an NCA n such that 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 An Example S1S1 BOS 0 f2f2 g5g5 G4G4 h9h9 H7H7 F3F3 f6f6 g8g8 G4G4 TOS NCA lookahead Grafting Point F3F3 = deleted node x : g 5 y : g 8 z : h 9, f 6

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

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

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

23 Flow of an Incremental Parsing Session incparser interface editor Write delta Return parse result Read input from temporary file Call interface Wrapper call incparser Temporary file

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

25 Editing Model Editing is a sequence of key presses Editing is a sequence of key presses Classify key presses into two groups 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 Editing causes a state change between pressing modikeys and non-modikeys Editor should remember BEGIN and END position when a state change occurs Editor should remember BEGIN and END position when a state change occurs

26 Special Keys BS (Backspace)/DEL are keys in modikeys that need special treatments BS (Backspace)/DEL are keys in modikeys that need special treatments BS might change the BEGIN position BS might change the BEGIN position DEL might change the END position DEL might change the END position Editor should perform appropriate action when user pressing BS/DEL Editor should perform appropriate action when user pressing BS/DEL We use a counter to maintain how many modikeys are pressed (except 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 at non- modikey state Assume that the cursor is at the position between “ ma ”, “ in ”, the editor is at non- modikey state User performs the following modifications User performs the following modifications –press BS two times –press DEL two times –key in “ foo_function ” –key in any non-modikeys

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

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

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

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

32 Conclusions We developed a generator for incremental parsers based on Bison We developed a generator for incremental parsers based on Bison We introduced a simple interface to incremental parsers that facilitate integration of an incremental parser and an editor based on editing model We introduced a simple interface to 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 lexers A generator for incremental semantics analyzers A generator for incremental semantics analyzers A generator for syntax-directed editors A generator for syntax-directed editors