Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie EMFText Meeting, Dresden, 30.11.2009 EMFText Code Completion.

Slides:



Advertisements
Similar presentations
JavaCUP JavaCUP (Construct Useful Parser) is a parser generator
Advertisements

Aspect Orientation for Your Language of Choice Florian Heidenreich, Jendrik Johannes, Steffen Zschaler Workshop on Aspect-Oriented Modelling 30 September,
Integrating OCL and Model Transformations in Fujaba Mirko Stölzel, Steffen Zschaler, and Leif Geiger OCLApps 2006, October 2, 2006.
Giancarlo Guizzardi Ontological Foundations for Structural Conceptual Models Kapitel 1–3, vorgestellt von Steffen Zschaler am
fakultät für informatik informatik 12 technische universität dortmund Additional compiler optimizations Peter Marwedel TU Dortmund Informatik 12 Germany.
A Close Look at Composition Languages Florian Heidenreich, Jendrik Johannes, Steffen Zschaler, and Uwe Aßmann ACoMM 2008.
Eiffel: Analysis, Design and Programming Bertrand Meyer (Nadia Polikarpova) Chair of Software Engineering.
Compiler construction in4020 – lecture 2 Koen Langendoen Delft University of Technology The Netherlands.
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
The Web Warrior Guide to Web Design Technologies
2440: 211 Interactive Web Programming JavaScript Fundamentals.
NaLIX: A Generic Natural Language Search Environment for XML Data Presented by: Erik Mathisen 02/12/2008.
1 Chapter 5: Bottom-Up Parsing (Shift-Reduce). 2 - attempts to construct a parse tree for an input string beginning at the leaves (the bottom) and working.
Top-Down Parsing.
1 Contents Introduction A Simple Compiler Scanning – Theory and Practice Grammars and Parsing LL(1) Parsing LR Parsing Lex and yacc Semantic Processing.
Parsing III (Eliminating left recursion, recursive descent parsing)
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Oracle Enterprise Data Quality CDEP: Tailoring Parser Configuration.
MIT Top-Down Parsing Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
Inheritance and Polymorphism CS351 – Programming Paradigms.
(2.1) Grammars  Definitions  Grammars  Backus-Naur Form  Derivation – terminology – trees  Grammars and ambiguity  Simple example  Grammar hierarchies.
- 1 - Strategic Information Technology Ltd PUG Challenge Americas 2013 “XML Data Services” for the Business Developer William MacDonald Architect.
ANTLR with ASTs. Abstract Syntax Trees ANTLR can be instructed to produce ASTs for the output of the parser ANTLR uses a prefix notation for representing.
Syntax Analysis – Part II Quick Look at Using Bison Top-Down Parsers EECS 483 – Lecture 5 University of Michigan Wednesday, September 20, 2006.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Stacks & Recursion. Stack pushpop LIFO list - only top element is visible top.
Top-Down Parsing - recursive descent - predictive parsing
1 Top Down Parsing. CS 412/413 Spring 2008Introduction to Compilers2 Outline Top-down parsing SLL(1) grammars Transforming a grammar into SLL(1) form.
Syntax Directed Translation. Tokens Parser Semantic checking TAC Peephole, pipeline, …… TAC  assembly code/mc Cmm subexpression,……
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Object-Oriented Analysis and Design Feb 11, 2009.
Chapter 5: Bottom-Up Parsing (Shift-Reduce)
CPS 506 Comparative Programming Languages Syntax Specification.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
Comp 311 Principles of Programming Languages Lecture 3 Parsing Corky Cartwright August 28, 2009.
1 Parsers and Grammar. 2 Categories of Grammar Rules  Declarations or definitions. AttributeDeclaration ::= [ final ] [ static ] [ access ] datatype.
Chapter 1 Introduction Major Data Structures in Compiler
ICOM 4035 – Data Structures Lecture 4 – Set ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Top-down Parsing lecture slides from C OMP 412 Rice University Houston, Texas, Fall 2001.
Top-down Parsing. 2 Parsing Techniques Top-down parsers (LL(1), recursive descent) Start at the root of the parse tree and grow toward leaves Pick a production.
1 Object-Oriented Software Engineering CS Java OO Fundamentals Contents Classes and Objects Making new objects Method declarations Encapsulating.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
LECTURE 11 Semantic Analysis and Yacc. REVIEW OF LAST LECTURE In the last lecture, we introduced the basic idea behind semantic analysis. Instead of merely.
1 Topic #4: Syntactic Analysis (Parsing) CSC 338 – Compiler Design and implementation Dr. Mohamed Ben Othman ( )
Bernd Fischer COMP2010: Compiler Engineering Abstract Syntax Trees.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Lecture 5: LR Parsing CS 540 George Mason University.
Conflicts in Simple LR parsers A SLR Parser does not use any lookahead The SLR parsing method fails if knowing the stack’s top state and next input token.
Error recovery in predictive parsing An error is detected during the predictive parsing when the terminal on top of the stack does not match the next input.
Comp 411 Principles of Programming Languages Lecture 3 Parsing
Fundamental of Java Programming
Chapter 4 Top-Down Parsing Part-1 September 8, 2018
Parsing Techniques.
Programming Language Syntax 6
CPSC 388 – Compiler Design and Construction
Syntax-Directed Definition
Programming Language Syntax 2
Lecture 8: Top-Down Parsing
Programming Language Syntax 5
LL and Recursive-Descent Parsing
Chapter 4 Action Routines.
Kanat Bolazar February 16, 2010
Quiz Points 2 Rules Raise your hand if you know the question
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Predictive Parsing Program
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
Presentation transcript:

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie EMFText Meeting, Dresden, EMFText Code Completion (All the ugly details)

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie How does Code Completion work (conceptually)? Parse an incomplete document (up to the cursor position) Provide a list of strings that may appear next (or that complete the current incomplete element) Why is this complicated? 1.How to (statically) compute what may appear next 2.How to collect the may be next items during parsing 3.ANTLR uses predictive parsing (lookahead) 4.How to derive concrete proposals (strings) from the list of next elements (terminals) 2

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie 1.How to (statically) compute what may appear next Class ExpectationComputer can compute FIRST and FOLLOW sets for syntax definitions FIRST is the set of terminals that a syntax element can start with, e.g.: M1 ::= (a)? b cFIRST(M1) = {a,b} FOLLOW is the set of terminals that can follow right after a syntax element, e.g.: M2 ::= d (e)? fFOLLOW(d) = {e, f} 3

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie 2. How to collect the may be next items during parsing Add some code in the semantic action sections After each matched token the list of FOLLOW terminals is added via addExpectedElement(new ExpectedTerminal(...)) 4

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie 3. ANTLR uses predictive parsing (lookahead) ANTLR discards some parse paths depending on the lookahead, e.g.,: Field ::= visibility[] type[] name[] ;; Method::= visibility[] void name[] ;; public class C1 { public } (instance of org.emftext.test.cct1) Problem: Generated parser does never eat the second public token, because the lookahead can find neither a type not a void token. The expected elements (type and void) are never added. 5

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie 3. ANTLR uses predictive parsing (lookahead) Solution: Let generated parser run up to the position in the document where the text is complete (i.e., before the second public) The remaining tokens are parsed manually but reducing the FOLLOW set iteratively public class C1 { public void m1() {} | public } 6 public, } TypedElement.type, void TEXT } ANTLR Parsing stops here …

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie 4. How to derive concrete text proposals from the list of next elements (terminals) Must consider prefix –Determine prefix using token positions (see setPositions()) –Match using startsWith() and StringUtil.match() –ReferenceResolver should use those methods as well to allow camel case code completion (c4) Keywords (CsStrings) are easy StructuralFeatures –Attributes (Pick default value depending on type) –Non-containment references (Call ReferenceResolverSwitch) 7

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie Open Issues Static Computation of FOLLOW sets yield overapproximation (e.g., if a rule is contained in multiple others) –Dynamic context needed! Interface of ReferenceResolvers needs to be changed for fuzzy resolving (Parameter 'resource' instead of 'container', because 'container' does often not exist) –Introduce IReferenceResolver2? Computation of FIRST and FOLLOW set could be faster (some sets are computed multiple times) –Add cache If the cursor is at the end of a document some proposals are missing because the LocationMap is wrong 8

Fakultät Informatik Institut Software- und Multimediatechnik, Lehrstuhl Softwaretechnologie Thank you! Questions? 9