ANTLR in SSP Xingzhong Xu Hong Man Aug. 11. 2 Outline ANTLR Abstract Syntax Tree Code Equivalence (Code Re-hosting) Future Work.

Slides:



Advertisements
Similar presentations
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Advertisements

Compilers and Language Translation
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
CPSC Compiler Tutorial 9 Review of Compiler.
SSP Re-hosting System Development: CLBM Overview and Module Recognition SSP Team Department of ECE Stevens Institute of Technology Presented by Hongbing.
Code recognition & CL modeling through AST Xingzhong Xu Hong Man.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Semantic Signal Processing for Re-hosting CR/SDR Implementations SP/Radio Primitive Recognition Jiadi Yu, Yingying Chen 1.
1 Terminology l Statement ( 敘述 ) »declaration, assignment containing expression ( 運算式 ) l Grammar ( 文法 ) »a set of rules specify the form of legal statements.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
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.
ANTLR.
Invitation to Computer Science 5th Edition
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
Getting Started with ANTLR Chapter 1. Domain Specific Languages DSLs are high-level languages designed for specific tasks DSLs include data formats, configuration.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
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.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
CSC 338: Compiler design and implementation
Compiler Construction1 COMP Compiler Construction Lecturer: Dr. Arthur Cater Teaching Assistant:
ISBN Chapter 3 Describing Syntax and Semantics.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
Towards the better software metrics tool motivation and the first experiences Gordana Rakić Zoran Budimac.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow.
CPS 506 Comparative Programming Languages Syntax Specification.
Daisy Arias Math 382/Lab November 16, 2010 Fall 2010.
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Duplicate code detection using anti-unification Peter Bulychev Moscow State University Marius Minea Institute eAustria, Timisoara.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 3: Introduction to Syntactic Analysis.
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
YACC. Introduction What is YACC ? a tool for automatically generating a parser given a grammar written in a yacc specification (.y file) YACC (Yet Another.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Programming Language Descriptions. What drives PL Development? Computers are “in charge” of extremely important issues Execute a program literally. Exercise.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
Compilers Computer Symbol Table Output Scanner (lexical analysis)
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
More yacc. What is yacc – Tool to produce a parser given a grammar – YACC (Yet Another Compiler Compiler) is a program designed to compile a LALR(1) grammar.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Comp 411 Principles of Programming Languages Lecture 3 Parsing
CS 3304 Comparative Languages
Chapter 3 – Describing Syntax
Compiler Design (40-414) Main Text Book:
CS 3304 Comparative Languages
Programming Languages Translator
Introduction to Parsing (adapted from CS 164 at Berkeley)
What does it mean? Notes from Robert Sebesta Programming Languages
Compiler Lecture 1 CS510.
Basic Program Analysis: AST
Compilers B V Sai Aravind (11CS10008).
CS 3304 Comparative Languages
CS 3304 Comparative Languages
High-Level Programming Language
Chapter 10: Compilers and Language Translation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Faculty of Computer Science and Information System
Presentation transcript:

ANTLR in SSP Xingzhong Xu Hong Man Aug. 11

2 Outline ANTLR Abstract Syntax Tree Code Equivalence (Code Re-hosting) Future Work

3 What is ANTLR? ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical description containing actions in variety of target languages. -- antlr.org

4 Why use ANTLR? SSP –Looking for a framework to understanding the signal processing source code semantically. Classical analysis method in CS –Code Recognizer: Lexer & Parser –Interpreter: Cognitive Linguistic Modeling & other syntax tree –Translator: code re-hosting, different target

5 How ANTLR Work? - I Lexer –Converting a sequence of characters into a sequence of tokens. Parser –Converting a sequence of tokens which generated from the Lexer to determine its grammatical structure. Abstract Syntax Tree –Tree representation of the abstract syntactic structure of source code. –The syntax is ‘abstract’ which means it does not represent every detail of the real syntax.

6 Example

7 How ANTLR Work? - II In order to generate the Lexer, Parser and AST. We need analyze the structure of the target code and write related ANTLR grammar. Example: Matrix Declaration in Matlab M1 = [1 2 3; 4 5 6]; M2 = [1,2,3;4,5,6]; M3 = [M1;M2]; M4 = 1;

8 ANTLR Grammar - I M1 = [1 2 3; 4 5 6]; Statement –[Variable] [Equal] [Expression] [Semicolon] (optional) Expression –[Left Square Bracket] [Matrix] [Right Square Bracket] or [one digit] Matrix –[Line] [Semicolon] [Line] [Semicolon] …. Line –[digit] [comma] (optional) [digit] [comma] (optional) …

9 ANTLR Grammar - II

10 Abstract Syntax Tree M1 = [1 2 3; 4 5 6];

11 Abstract Syntax Tree 11 M2 = [1,2,3;4,5,6];

12 Abstract Syntax Tree M3 = [M1;M2];

13 Abstract Syntax Tree M4 = 1;

14 AST Example from GNU-Radio Using ANTLR, some example from GNU-Radio code has been tested.

15 Code Equivalence In order to re-hosting the code –The proper rule to abstract the code. –The functionality of the code segment. Methodology –Abstraction –Code Segmentation –Functionality Analysis –Replace the segment by equivalence code.

16 Current Method in CS Syntax Tree based Comparison –Generate AST or other related abstract tree, perform tree-matching algorithm. –Use hash function to mapping the tree structure and simplify the algorithm. Radom Test Comparison –Code Chopper, segment the code. –Randomly test the Input/Output behavior. –Schwartz-Zippel lemma, enough time of the test can derive the functionality.

17 Simplest Filter Example Take the simplest filter as an example, following code segments have exactly same functionality. for (i = 0; i < n; i++) acc0 += d_taps[i] * input[i]; for (i = 0; i < n ; ) acc0 += d_taps[i] * input[i++]; i = 0; while ( i < n ) acc0 += d_taps[i] * input[i++]; i = 0; for ( ; i < n ; ) acc0 += d_taps[i] * input[i++];

18 Ordinary AST for (i = 0; i < n; i++) acc0 += d_taps[i] * input[i];

19 Modified AST The ordinary AST is derived from the programming grammar level. Following the idea of the semantic signal processing. For example, in signal processing domain abstraction: –‘For’, ‘While’, ‘do … while’ -> ‘LOOP’ –‘+=’, ‘VAR = VAR + whatever’ -> ‘ACCUMLATE’

20 Simplest Filter Example for (i = 0; i < n; i++) acc0 += d_taps[i] * input[i];

21 Simplest Filter Example for (i = 0; i < n; ) acc0 += d_taps[i] * input[i++];

22 Simplest Filter Example i = 0; while ( i < n ) acc0 += d_taps[i] * input[i++]; i = 0; for ( ; i < n ; ) acc0 += d_taps[i] * input[i++];

23 Code Equivalence Objection: From the syntax tree to determine the code segments are equivalence. –Abstraction –Tree matching. Perform code re-hosting.

24 Simplest Filter Example for (int i = 0; i < noutput_items; i++) { gr_complex sum(0.0, 0.0); for (k = 0; k < l; k++) sum += d_taps[l-k-1]*in[j+k]; out[i] = sum; } From gr_adaptive_fir_ccf.cc

25 Abstraction The basic element for the simplest filter include: –LOOP –ACCUMLATION –MULTIPLY –ARRAY –MOVING INDEX

26 Similarity Tree Pattern No abstraction can guarantee the same functional code have precisely same abstraction form. Therefore, we need perform a similarity tree pattern recognition. Similar enough to determine the equivalence

27 Future Work Using ANTLR generate other language Lexer and Parser for language recognition. Abstract the language into Cognitive Linguistic Modeling. Find proper method to perform a similarity tree pattern recognition.

28 Reference 1.Terence Parr, The Definitive Antlr Reference: Building Domain-Specific Language (Pragmatic Programmers), Jiang L. and Su, Z Automatic Mining of functionally equivalent code fragments via random testing. In Proceedings of the Eighteenth international Symposium on Software Testing and Analysis 5.Gabel, M., Jiang, L., and Su, Z Scalable detection of semantic clones. In Proceedings of the 30 th international Conference on Software Engineering 6.C.K. Roy, J.R. Cordy and R. Koschke B Comparison and Evaluation of code Clone Detection Techniques and Tools: A Qualitative Approach. Science of Computer Programming 7.Bertran, M., Babot, F., and Climent, A An Input/Output Semantics for Distributed Program Equivalence Reasoning. Electron. Notes Theor. Comput. Sci. 137, 1 (Jul. 2005)