The document discusses various patterns for generative programming including parser generation. It describes using a context-free grammar as input to automatically generate a parser. The key steps are:
1. Define regular expressions for tokens and context-free productions for nonterminals
2. Generate code for the parser from the grammar
3. Write boilerplate code to execute the generated parser and feed it a token stream.
The overall approach is to specify language structure through a grammar and then generate artifacts like lexers and parsers that can recognize or operate on that language.
An introduction on language processingRalf Laemmel
This document introduces language processing components for a simple imperative language called Pico. It describes the abstract syntax, concrete syntax, recognizer, parser, type checker, interpreter, assembly code generator, compiler, machine, flow charts, and visualizer implemented in Haskell. The language processors leverage parser combinators, natural semantics, and code generation approaches.
The document provides an overview of software languages and language processors. It discusses natural languages, controlled languages, and artificial languages. It then covers software languages which are used to engineer software. Different types of language processors like compilers, interpreters, scanners and parsers are described. Traditional compiler architecture and compilation by transformation are summarized. Modern compilers used in integrated development environments are also discussed. The document concludes by covering compiler construction and language workbenches.
1. The document discusses the phases of a compiler including lexical analysis, syntax analysis, and semantic analysis.
2. Lexical analysis breaks input into tokens which are passed to the parser, syntax analysis builds an abstract syntax tree by applying grammar rules to check structure, and semantic analysis ensures correct meaning.
3. Key aspects covered include context-free grammars, symbol tables for storing token information, and error detection and reporting across compiler phases.
Declare Your Language: What is a Compiler?Eelco Visser
The document provides an overview of the course on compiler construction, including information on the course organization, website, assignments, and deadlines, as well as introducing the concept of what a compiler is and the different types of compilers. It also discusses how linguistic abstractions can be used to build domain-specific languages and language workbenches that support the design and implementation of programming languages through the use of declarative meta-languages.
The document describes a compiler design lab manual. It contains 12 experiments related to compiler design topics like lexical analysis, parsing, syntax analysis, code generation etc. It also lists the program outcomes and program specific outcomes attained through each experiment. The objective of the lab is to provide students hands-on experience with basic compiler construction techniques and tools.
The document describes language processing patterns for analyzing text at the lexical and syntactic levels. It introduces the Chopper Pattern, which approximates lexical analysis by chopping text into pieces, and the Lexer Pattern, which fixes this by recognizing token-lexeme pairs. The Copy/Replace Pattern builds on the Lexer Pattern to transform text by copying or replacing lexemes. The Acceptor Pattern builds further by using the Lexer Pattern and recursive descent parsing to verify syntactic correctness through matching terminals and invoking procedures for nonterminals.
Python was created in the late 1980s by Guido van Rossum. It draws influence from many other languages like ABC, Modula-3, C, C++, Algol68, SmallTalk, and Unix shell scripting languages. Python is an interpreted, interactive, object-oriented scripting language that is highly readable and easy to maintain. It has a large standard library and supports features like being interactive, object-oriented programming, databases, GUI programming, and is portable across platforms.
This document provides an overview of a compiler engineering lab at the University of Dammam Girls' College of Science. It discusses what a compiler is, the different phases and parts of compilation including lexical analysis, syntax analysis, and code generation. It also describes some common compiler construction tools like scanner generators, parser generators, and code optimizers that can automate parts of the compiler development process. The document serves as an introduction to the concepts and processes involved in building compilers.
An introduction on language processingRalf Laemmel
This document introduces language processing components for a simple imperative language called Pico. It describes the abstract syntax, concrete syntax, recognizer, parser, type checker, interpreter, assembly code generator, compiler, machine, flow charts, and visualizer implemented in Haskell. The language processors leverage parser combinators, natural semantics, and code generation approaches.
The document provides an overview of software languages and language processors. It discusses natural languages, controlled languages, and artificial languages. It then covers software languages which are used to engineer software. Different types of language processors like compilers, interpreters, scanners and parsers are described. Traditional compiler architecture and compilation by transformation are summarized. Modern compilers used in integrated development environments are also discussed. The document concludes by covering compiler construction and language workbenches.
1. The document discusses the phases of a compiler including lexical analysis, syntax analysis, and semantic analysis.
2. Lexical analysis breaks input into tokens which are passed to the parser, syntax analysis builds an abstract syntax tree by applying grammar rules to check structure, and semantic analysis ensures correct meaning.
3. Key aspects covered include context-free grammars, symbol tables for storing token information, and error detection and reporting across compiler phases.
Declare Your Language: What is a Compiler?Eelco Visser
The document provides an overview of the course on compiler construction, including information on the course organization, website, assignments, and deadlines, as well as introducing the concept of what a compiler is and the different types of compilers. It also discusses how linguistic abstractions can be used to build domain-specific languages and language workbenches that support the design and implementation of programming languages through the use of declarative meta-languages.
The document describes a compiler design lab manual. It contains 12 experiments related to compiler design topics like lexical analysis, parsing, syntax analysis, code generation etc. It also lists the program outcomes and program specific outcomes attained through each experiment. The objective of the lab is to provide students hands-on experience with basic compiler construction techniques and tools.
The document describes language processing patterns for analyzing text at the lexical and syntactic levels. It introduces the Chopper Pattern, which approximates lexical analysis by chopping text into pieces, and the Lexer Pattern, which fixes this by recognizing token-lexeme pairs. The Copy/Replace Pattern builds on the Lexer Pattern to transform text by copying or replacing lexemes. The Acceptor Pattern builds further by using the Lexer Pattern and recursive descent parsing to verify syntactic correctness through matching terminals and invoking procedures for nonterminals.
Python was created in the late 1980s by Guido van Rossum. It draws influence from many other languages like ABC, Modula-3, C, C++, Algol68, SmallTalk, and Unix shell scripting languages. Python is an interpreted, interactive, object-oriented scripting language that is highly readable and easy to maintain. It has a large standard library and supports features like being interactive, object-oriented programming, databases, GUI programming, and is portable across platforms.
This document provides an overview of a compiler engineering lab at the University of Dammam Girls' College of Science. It discusses what a compiler is, the different phases and parts of compilation including lexical analysis, syntax analysis, and code generation. It also describes some common compiler construction tools like scanner generators, parser generators, and code optimizers that can automate parts of the compiler development process. The document serves as an introduction to the concepts and processes involved in building compilers.
Ch07 Programming for Security Professionalsphanleson
The document provides an introduction to computer programming concepts such as branching, looping, testing, functions, variables, data types, operators, and object-oriented programming. It then discusses specific programming languages like C, HTML, Perl, and how to set up programming environments in Ubuntu Linux. Examples are provided for basic programs in C and how HTML is used to create web pages.
The document discusses translating .NET bytecode to run on the Parrot virtual machine (VM). It describes:
1) Choosing bytecode translation over other options like modifying compilers or embedding VMs, as it provides better performance and independence from programming languages.
2) The challenges of translating between the stack-based .NET bytecode and register-based Parrot bytecode.
3) The architecture developed to make the translation pluggable and declarative, including a metadata translator, instruction translator, and stack to register mapping modules.
This document provides an introduction and overview of the Python programming language. It discusses that Python was created by Guido Van Rossum in 1991 and named after Monty Python. Python can be used for both procedural and object-oriented programming approaches. It is an interpreted language that is free to use, easy to learn, and has a simple syntax. Python is popular for web development, data analysis, science/engineering, and more. The document then covers Python syntax and provides examples of using variables, data types, and the interactive mode versus script mode of writing Python code.
This document discusses flex and bison tools for lexical analysis and parsing. It covers:
1. How flex returns tokens with values and bison assigns token numbers starting from 258.
2. The basics of writing flex rules and scanners, and bison grammars, rules, and parsers.
3. An example bison calculator grammar and combining the flex scanner and bison parser.
This document discusses pointers, file handling, and C preprocessors. It covers:
- Defining and declaring pointers, and examples of pointer usage
- Opening, reading, writing, and closing files
- Preprocessor directives like #include, #define, and #if that are used to define macros and conditionally compile code
The document provides information on the history and design of the C programming language. It was developed between 1969-1973 along with Unix and was designed for systems programming tasks like operating systems and compilers. Key aspects of C's design included producing efficient code, being portable across different processors/systems, and using less memory. C introduced many features still used in modern languages today like functions, variables, arrays, structures, pointers, and libraries.
TransCoder is an unsupervised machine translation system that converts source code from one programming language to another using a seq2seq model with attention. It is trained using three principles: 1) cross-programming language model pretraining to map similar tokens across languages, 2) denoising auto-encoding to generate valid sequences, and 3) back-translation to generate parallel data for training. Evaluation shows TransCoder understands language-specific syntax and aligns libraries across languages.
Brief introduction to the c programming languageKumar Gaurav
The document provides an introduction to the C programming language. It discusses that C was created in the 1970s and was influenced by other languages. It describes standardization of C in 1989 and later updates. It also covers basic elements of a C program like main functions, header files, simple programs, passing command line arguments, and pointers. The document uses examples to explain concepts like arrays, macros, and conditional compilation using the preprocessor.
The C programming language was created in the early 1970s by Dennis Ritchie at Bell Labs. It was influenced by an earlier language called B that was created by Ken Thompson. C was designed to be a general-purpose programming language with features like data types and structures that made it more powerful than B. It became widely popular due to its use in the UNIX operating system. The book "The C Programming Language" helped define the language and became a standard. C has since been standardized by ANSI and ISO and remains widely used today due to its efficiency, portability, and ability to access hardware.
The document discusses code generation in compilers. It describes the code generator as taking an intermediate representation as input and producing target code. Key issues addressed include memory management, instruction selection and scheduling, and register allocation. The document also covers common compiler errors like lexical, syntactic, semantic and logical errors. It discusses different error recovery strategies used by parsers like panic mode, statement mode, and use of error productions.
File Operation such as
Reading the file content
Writing the content to the file
Copying the content from one file to another file
Counting the number of character, words and lines of the file
This document provides an introduction to the Perl programming language. It begins with an overview of Perl, including what Perl is, its history and key features. It then discusses Perl syntax, variables types (scalars, arrays and hashes), and other important Perl concepts like variable scoping and context. The document also provides examples of basic Perl programs and commands.
The document provides an introduction to the Python programming language. It discusses the history and overview of Python, including that it is an interpreted, interactive, and object-oriented scripting language. It then covers Python features such as being easy to learn and read, having a broad standard library, and being portable. The document also demonstrates basic Python concepts like data types, variables, conditional statements, and functions.
Language-agnostic data analysis workflows and reproducible researchAndrew Lowe
This was a talk that I gave at CERN at the Inter-experimental Machine Learning (IML) Working Group Meeting in April 2017 about language-agnostic (or polyglot) analysis workflows. I show how it is possible to work in multiple languages and switch between them without leaving the workflow you started. Additionally, I demonstrate how an entire workflow can be encapsulated in a markdown file that is rendered to a publishable paper with cross-references and a bibliography (and with raw LaTeX file produced as a by-product) in a simple process, making the whole analysis workflow reproducible. For experimental particle physics, ROOT is the ubiquitous data analysis tool, and has been for the last 20 years old, so I also talk about how to exchange data to and from ROOT.
The document provides an overview of the Pascal programming language. It discusses [1] the early history and development of Pascal by Niklaus Wirth from 1968-1970, [2] the key features and structure of Pascal programs including the basic parts of a program and main data types, and [3] how Pascal combined features from other languages like ALGOL, COBOL and FORTRAN to create a structured and teachable language.
A compiler is a program that translates a program written in a source language into an equivalent program in a target language. It has two main parts - a front end that handles language-dependent tasks like lexical analysis, syntax analysis, and semantic analysis, and a back end that handles language-independent tasks like code optimization and final code generation. Compiler design involves techniques from programming languages, theory, algorithms, and computer architecture. Regular expressions are used to describe the tokens in a programming language.
ZENUS INFOTECH is best Python Training institute in Roorkee and an ISO 9001:2008 Certified Engineer’s Training Company in Roorkee & provides training to the B.E./B.TECH/DIPLOMA/MCA/BCA and related field students in 35+ cutting-edge technologies like AutoCAD, Solid-Works, CATIA, REVIT, Pro-E, UG-NX .NET, JAVA, PHP, GST Tally and Wireless & Telecommunication and many more.
The document discusses the phases of a compiler including lexical analysis. It provides questions and answers related to compilers and lexical analysis. Specifically:
- It defines key terms related to compilers like translators, compilers, interpreters, and the phases of compilation.
- Questions cover topics like regular expressions, finite automata, lexical analysis issues, and the role of lexical analyzers.
- The role of the lexical analyzer is to read the source program and group it into tokens that are then passed to the parser.
- Regular expressions are used to specify patterns for tokens and can be represented by finite automata like NFAs and DFAs.
The document discusses different programming paradigms like procedural, modular, and object-oriented programming. It also provides a brief history of the C language, noting it was developed in the 1970s and derived from B and BCPL. The document lists some features of C like it being a middle-level language, case-sensitive, using compilers, and teaching basic programming skills.
Generative Programming In The Large - Applied C++ meta-programmingSchalk Cronjé
Digs into the details of effective generative programming in C++. Major focus on using meta-programming techniques to create efficient, low cyclomatic complexity in artefacts.
The document discusses practical meta-programming using C++ templates. It explains how template specialization and partial specialization allow recursive instantiation of templates to transform types and data at compile-time in a functional programming-like manner. Examples are provided to demonstrate summing values, checking type traits, approximating mathematical functions, and creating heterogeneous tuples through recursive templates. SFINAE (substitution failure is not an error) is also introduced as a way to selectively overload functions based on type traits.
Ch07 Programming for Security Professionalsphanleson
The document provides an introduction to computer programming concepts such as branching, looping, testing, functions, variables, data types, operators, and object-oriented programming. It then discusses specific programming languages like C, HTML, Perl, and how to set up programming environments in Ubuntu Linux. Examples are provided for basic programs in C and how HTML is used to create web pages.
The document discusses translating .NET bytecode to run on the Parrot virtual machine (VM). It describes:
1) Choosing bytecode translation over other options like modifying compilers or embedding VMs, as it provides better performance and independence from programming languages.
2) The challenges of translating between the stack-based .NET bytecode and register-based Parrot bytecode.
3) The architecture developed to make the translation pluggable and declarative, including a metadata translator, instruction translator, and stack to register mapping modules.
This document provides an introduction and overview of the Python programming language. It discusses that Python was created by Guido Van Rossum in 1991 and named after Monty Python. Python can be used for both procedural and object-oriented programming approaches. It is an interpreted language that is free to use, easy to learn, and has a simple syntax. Python is popular for web development, data analysis, science/engineering, and more. The document then covers Python syntax and provides examples of using variables, data types, and the interactive mode versus script mode of writing Python code.
This document discusses flex and bison tools for lexical analysis and parsing. It covers:
1. How flex returns tokens with values and bison assigns token numbers starting from 258.
2. The basics of writing flex rules and scanners, and bison grammars, rules, and parsers.
3. An example bison calculator grammar and combining the flex scanner and bison parser.
This document discusses pointers, file handling, and C preprocessors. It covers:
- Defining and declaring pointers, and examples of pointer usage
- Opening, reading, writing, and closing files
- Preprocessor directives like #include, #define, and #if that are used to define macros and conditionally compile code
The document provides information on the history and design of the C programming language. It was developed between 1969-1973 along with Unix and was designed for systems programming tasks like operating systems and compilers. Key aspects of C's design included producing efficient code, being portable across different processors/systems, and using less memory. C introduced many features still used in modern languages today like functions, variables, arrays, structures, pointers, and libraries.
TransCoder is an unsupervised machine translation system that converts source code from one programming language to another using a seq2seq model with attention. It is trained using three principles: 1) cross-programming language model pretraining to map similar tokens across languages, 2) denoising auto-encoding to generate valid sequences, and 3) back-translation to generate parallel data for training. Evaluation shows TransCoder understands language-specific syntax and aligns libraries across languages.
Brief introduction to the c programming languageKumar Gaurav
The document provides an introduction to the C programming language. It discusses that C was created in the 1970s and was influenced by other languages. It describes standardization of C in 1989 and later updates. It also covers basic elements of a C program like main functions, header files, simple programs, passing command line arguments, and pointers. The document uses examples to explain concepts like arrays, macros, and conditional compilation using the preprocessor.
The C programming language was created in the early 1970s by Dennis Ritchie at Bell Labs. It was influenced by an earlier language called B that was created by Ken Thompson. C was designed to be a general-purpose programming language with features like data types and structures that made it more powerful than B. It became widely popular due to its use in the UNIX operating system. The book "The C Programming Language" helped define the language and became a standard. C has since been standardized by ANSI and ISO and remains widely used today due to its efficiency, portability, and ability to access hardware.
The document discusses code generation in compilers. It describes the code generator as taking an intermediate representation as input and producing target code. Key issues addressed include memory management, instruction selection and scheduling, and register allocation. The document also covers common compiler errors like lexical, syntactic, semantic and logical errors. It discusses different error recovery strategies used by parsers like panic mode, statement mode, and use of error productions.
File Operation such as
Reading the file content
Writing the content to the file
Copying the content from one file to another file
Counting the number of character, words and lines of the file
This document provides an introduction to the Perl programming language. It begins with an overview of Perl, including what Perl is, its history and key features. It then discusses Perl syntax, variables types (scalars, arrays and hashes), and other important Perl concepts like variable scoping and context. The document also provides examples of basic Perl programs and commands.
The document provides an introduction to the Python programming language. It discusses the history and overview of Python, including that it is an interpreted, interactive, and object-oriented scripting language. It then covers Python features such as being easy to learn and read, having a broad standard library, and being portable. The document also demonstrates basic Python concepts like data types, variables, conditional statements, and functions.
Language-agnostic data analysis workflows and reproducible researchAndrew Lowe
This was a talk that I gave at CERN at the Inter-experimental Machine Learning (IML) Working Group Meeting in April 2017 about language-agnostic (or polyglot) analysis workflows. I show how it is possible to work in multiple languages and switch between them without leaving the workflow you started. Additionally, I demonstrate how an entire workflow can be encapsulated in a markdown file that is rendered to a publishable paper with cross-references and a bibliography (and with raw LaTeX file produced as a by-product) in a simple process, making the whole analysis workflow reproducible. For experimental particle physics, ROOT is the ubiquitous data analysis tool, and has been for the last 20 years old, so I also talk about how to exchange data to and from ROOT.
The document provides an overview of the Pascal programming language. It discusses [1] the early history and development of Pascal by Niklaus Wirth from 1968-1970, [2] the key features and structure of Pascal programs including the basic parts of a program and main data types, and [3] how Pascal combined features from other languages like ALGOL, COBOL and FORTRAN to create a structured and teachable language.
A compiler is a program that translates a program written in a source language into an equivalent program in a target language. It has two main parts - a front end that handles language-dependent tasks like lexical analysis, syntax analysis, and semantic analysis, and a back end that handles language-independent tasks like code optimization and final code generation. Compiler design involves techniques from programming languages, theory, algorithms, and computer architecture. Regular expressions are used to describe the tokens in a programming language.
ZENUS INFOTECH is best Python Training institute in Roorkee and an ISO 9001:2008 Certified Engineer’s Training Company in Roorkee & provides training to the B.E./B.TECH/DIPLOMA/MCA/BCA and related field students in 35+ cutting-edge technologies like AutoCAD, Solid-Works, CATIA, REVIT, Pro-E, UG-NX .NET, JAVA, PHP, GST Tally and Wireless & Telecommunication and many more.
The document discusses the phases of a compiler including lexical analysis. It provides questions and answers related to compilers and lexical analysis. Specifically:
- It defines key terms related to compilers like translators, compilers, interpreters, and the phases of compilation.
- Questions cover topics like regular expressions, finite automata, lexical analysis issues, and the role of lexical analyzers.
- The role of the lexical analyzer is to read the source program and group it into tokens that are then passed to the parser.
- Regular expressions are used to specify patterns for tokens and can be represented by finite automata like NFAs and DFAs.
The document discusses different programming paradigms like procedural, modular, and object-oriented programming. It also provides a brief history of the C language, noting it was developed in the 1970s and derived from B and BCPL. The document lists some features of C like it being a middle-level language, case-sensitive, using compilers, and teaching basic programming skills.
Generative Programming In The Large - Applied C++ meta-programmingSchalk Cronjé
Digs into the details of effective generative programming in C++. Major focus on using meta-programming techniques to create efficient, low cyclomatic complexity in artefacts.
The document discusses practical meta-programming using C++ templates. It explains how template specialization and partial specialization allow recursive instantiation of templates to transform types and data at compile-time in a functional programming-like manner. Examples are provided to demonstrate summing values, checking type traits, approximating mathematical functions, and creating heterogeneous tuples through recursive templates. SFINAE (substitution failure is not an error) is also introduced as a way to selectively overload functions based on type traits.
Generative Software Development. Overview and ExamplesEelco Visser
Generative software development is a system-family approach that focuses on automating the creation of system-family members. A given system can be automatically generated from a specification written in one or more domain-specific languages. Domain-specific languages are used to specify systems at a high level of abstraction in a particular problem domain, while mappings and solution components implement the specification in a lower-level solution space. This allows automatic generation of systems from concise, domain-focused specifications.
Seeking Enligtenment - A journey of purpose rather tan instructionSchalk Cronjé
The document discusses the benefits of exercise for mental health. Regular physical activity can help reduce anxiety and depression and improve mood and cognitive functioning. Exercise causes chemical changes in the brain that may help boost feelings of calmness, happiness and focus.
A Generative Programming Approach to Developing Pervasive Computing SystemsDamien Cassou
This document presents a generative programming approach to developing pervasive computing systems. It describes challenges in pervasive computing like heterogeneity, lack of structure, and dynamicity. It proposes addressing these through domain-specific languages to describe devices, architectures, and generate a programming framework and simulation support. This approach aims to guide development and ensure conformance while abstracting distributed aspects and supporting multiple expertise.
The document discusses practical generative programming. It defines generative programming as automatically manufacturing customized products from reusable components using configuration knowledge. It describes the key elements and steps of generative programming. It discusses strategies for implementing generative programming in C++, including using templates and traits classes to configure generic components. It provides an example of how to capture configuration metadata in XML to define attributes like port ranges and generate C++ code.
Presentation done at the historic 20 yeras of C++ conference in Las Vegas 2005. This is also the first time I ever spoke on the topic of combing generative programming and C++ template metaprogramming
What is probabilistic programming? By analogy: if functional programming is programming with first-class functions and equational reasoning, probabilistic programming is programming with first-class distributions and Bayesian inference. All computable probability distributions can be encoded as probabilistic programs, and every probabilistic program represents a probability distribution.
What does it do? It gives a concise language for specifying complex, structured statistical models, and abstracts over the implementation details of exact and approximate inference algorithms. These models can be networked, causal, hierarchical, recursive, anything: the graph structure of the program is the generative structure of the distribution.
Who's interested? Cognitive scientists, statisticians, machine-learning specialists, and artificial-intelligence researchers.
1. The document discusses Transformational Generative Grammar, which is a theory of grammar developed by Noam Chomsky that uses transformations to relate deep and surface structures of sentences.
2. It defines key concepts of transformational grammar like deep structure, surface structure, and transformations. Deep structure is the underlying form of a sentence before rules are applied, and surface structure is the final spoken/heard form.
3. Examples of transformations provided include passive, extraposition, and various focusing transformations like end-focus that place important information at the end of sentences.
This document provides an overview of syntax and generative grammar. It defines syntax as the way words are arranged to show relationships of meaning within and between sentences. Grammar is defined as the art of writing, but is now used to study language. Generative grammar uses formal rules to generate an infinite set of grammatical sentences. It distinguishes between deep structure and surface structure. Tree diagrams are used to represent syntactic structures with symbols like S, NP, VP. Phrase structure rules, lexical rules, and movement rules are components of generative grammar. Complement phrases and recursion allow sentences to be embedded within other sentences.
Ubiquitous computing (ubicomp) refers to computers integrated into everyday objects and activities. The goal is to create an environment where connectivity between devices is always available but unobtrusive. Examples of ubicomp devices include digital audio players, RFID tags, smartphones, and interactive whiteboards. Mark Weiser is considered the father of ubiquitous computing and coined the term in the 1980s.
Metaprograms and metadata (as part of the the PTT lecture)Ralf Laemmel
This document discusses metaprograms and metadata in Java. Metaprograms are programs that manipulate other programs, where programs correspond to data of metaprograms. Metadata is data that provides additional information about programs or other data. The document provides examples of using reflection and annotations in Java to implement metaprogramming and work with metadata. It also discusses using proxies to implement the proxy pattern reflectively in Java.
Functional OO programming (as part of the the PTT lecture)Ralf Laemmel
The document discusses functional programming concepts and how they can be implemented in Java. Functional programming focuses on functions as mathematical abstractions rather than methods bound to classes. While Java does not support first-class functions, functional concepts like closures can be achieved using anonymous classes. The document provides examples of implementing functions for addition and multiplication using static methods and anonymous classes. It also discusses how functional programming concepts like higher-order functions, lazy evaluation, and pattern matching can be approximated in Java. Combinator libraries that allow functional composition are highlighted as a key use case for functional object-oriented programming in Java.
XML data binding allows XML data to be represented and manipulated as objects in an object-oriented programming language. It provides a mapping between XML schemas and object-oriented types, allowing XML data to be deserialized into objects and objects to be serialized back into XML. This mapping is done through an XML-to-object mapping tool. XML data binding facilitates working with XML data in an object-oriented way by enabling operations like totaling salaries for employees to be implemented using object-oriented methods rather than requiring the use of XML query or transformation languages.
This document provides an overview of compiler construction principles and practices. It introduces the basic components of a compiler, including scanning, parsing, semantic analysis, code generation, and optimization phases. It also discusses related tools like assemblers, linkers, and debuggers. The document outlines the translation process from source code to target code and describes major data structures used in compilers like symbol tables and syntax trees.
This document provides an introduction to compiler construction. It outlines the objectives of understanding how to build a compiler, use compiler construction tools, and be familiar with concepts like virtual machines, grammars, and optimization techniques. It defines compilation as translating a program to a semantically equivalent target language and interpretation as performing operations implied by a source program. The analysis-synthesis model and how it is used in compilers and other tools is described. The phases of a compiler from preprocessing to code generation are outlined.
This document outlines the course structure and content for UCS 802 Compiler Construction. It discusses the key components of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. Parsing techniques like top-down and bottom-up are also covered. The major parts of a compiler including analysis and synthesis phases are defined.
This document provides an overview of compilers and their various phases. It begins by introducing compilers and their importance for increasing programmer productivity and enabling reverse engineering. It then covers the classification of programming languages and the history of compilers. The rest of the document details each phase of the compiler process, including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, code generation, and the role of the symbol table. It provides definitions and examples for each phase to explain how a source program is translated from a high-level language into executable machine code.
Lecture 1 introduction to language processorsRebaz Najeeb
The document provides an overview of the different phases of a compiler: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It discusses each phase briefly and provides examples to illustrate how a program is processed through each step of compilation.
This document provides an overview of key concepts related to programming languages. It discusses the definition of a programming language and the history and evolution of popular languages from 1951 to present. It covers programming language paradigms like procedural, object-oriented, functional, and logic-based languages. It also discusses factors that influence language design like efficiency, regularity, and issues in language translation. Finally, it summarizes the structure and operation of computers and how different programming models map to underlying computer architectures.
- The document outlines the goals, outcomes, prerequisites, topics covered, and grading for a compiler design course.
- The major goals are to provide an understanding of compiler phases like scanning, parsing, semantic analysis and code generation, and have students implement parts of a compiler for a small language.
- By the end of the course students will be familiar with compiler phases and be able to define the semantic rules of a programming language.
- Prerequisites include knowledge of programming languages, algorithms, and grammar theories.
- The course covers topics like scanning, parsing, semantic analysis, code generation and optimization.
This document summarizes Srikanth Vanama's graduate compiler project at Clemson University. It introduces Srikanth and provides details about the project implementation including the lexical analyzer, parser, semantic analyzer, code generation, and assembly code output. The project involved developing a compiler for a new programming language using tools like Perl.
This document provides an introduction to a course on compiler construction. It outlines the goals of the course as learning how to build a compiler for a programming language, use compiler construction tools, and write different grammar types. It also discusses the grading policy, required textbook, and defines what a compiler is and provides examples of different compilers. It gives an overview of the phases and process of compilation from high-level language to machine code.
The document discusses the different phases of a compiler including lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and code generation. It provides details on each phase and the techniques involved. The overall structure of a compiler is given as taking a source program through various representations until target machine code is generated. Key terms related to compilers like tokens, lexemes, and parsing techniques are also introduced.
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)Ralf Laemmel
Aspect-oriented programming (AOP) allows programmers to modularize crosscutting concerns. Logging is a common example of a crosscutting concern that can be implemented using AOP. In AspectJ, an AOP extension to Java, aspects are used to encapsulate crosscutting concerns. Advice such as before and after advice can be used to add behavior at certain join points, such as method calls and executions. This avoids tangling code for crosscutting concerns throughout multiple classes.
Using ANTLR on real example - convert "string combined" queries into paramete...Alexey Diyan
1. Hello ANTLR: ANother Tool for Language Recognition
2. Where we can use ANTLR?
3. Why just not use regular expression language?
4. Tools under ANTLR umbrella
5. ANTLR basic syntax
6. ANTLR on real example
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORijistjournal
Pseudocode is an artificial and informal language that helps developers to create algorithms. In this papera software tool is described, for translating the pseudocode into a particular source programminglanguage. This tool compiles the pseudocode given by the user and translates it to a source programminglanguage. The scope of the tool is very much wide as we can extend it to a universal programming toolwhich produces any of the specified programming language from a given pseudocode. Here we present thesolution for translating the pseudocode to a programming language by using the different stages of acompiler
This document provides an overview of compiler design and the different phases involved in compiling a program. It begins with defining a compiler as a program that translates code written in one programming language into another target language to be executed by a computer. The major phases of a compiler are then described as the analysis phase (front-end) which breaks down and analyzes the source code, and the synthesis phase (back-end) which generates the target code. Key phases in the front-end include lexical analysis, syntax analysis, and semantic analysis, while the back-end includes code optimization and code generation. Different types of compilers such as single-pass, two-pass, and multi-pass compilers are also introduced based on how many times
This document provides an outline for a compiler design course. It discusses the key tasks of a compiler including the front-end (lexical analysis, syntax analysis, intermediate code generation) and back-end (instruction selection, register allocation, code generation). It also describes the disciplines involved in compiler design such as algorithms, languages, and computer architectures. The goal of the course is to learn techniques for modern compilers by translating source code into machine code.
This document summarizes Suneel Marthi's presentation on large scale natural language processing. It discusses how natural language processing deals with processing and analyzing large amounts of human language data using computers. It provides an overview of Apache OpenNLP and Apache Flink, two open source projects for natural language processing. It also discusses how models for tasks like part-of-speech tagging and named entity recognition can be trained for different languages and integrated into data pipelines for large scale processing using these frameworks.
Similar to Generative programming (mostly parser generation) (20)
Developer workflow analysis and ownership management present comprehension challenges for software ecosystems and global software engineering. Dark matter exists because tools are not fully integrated, logging is not designed for analysis, and developer workflow is unstructured. Probabilistic models using machine learning and heuristics can help associate activities with work items to address this. Ownership management challenges include ownership decay, asset subclassing, team-level ownership, and providing explainable recommendations.
The document discusses functional data structures. It begins by defining functional data structures as data structures suitable for functional programming languages or for coding in an imperative language using a functional style. Key characteristics include immutability, recursion, garbage collection, and pattern matching. Examples of functional implementations of stacks, sets using binary search trees, and priority queues (heaps) using skew heaps are provided in Haskell and Java. Functional data structures have advantages like fewer bugs due to immutability and increased sharing through lack of defensive cloning. The document discusses the tree-copying involved in operations on functional data structures and provides benchmark results showing improved performance of binary search trees over naive lists for sets.
Modeling software systems at a macroscopic scaleRalf Laemmel
This document discusses megamodeling, which involves creating models that represent other models, languages, and technologies used in software projects. A megamodel captures the relationships between these different elements at a macro scale. The document proposes using MegaL, a general-purpose megamodeling language, to precisely model software systems in terms of the languages, technologies, and concepts involved and their relationships. MegaL aims to help manage diversity and heterogeneity in software while providing cognitive value through abstract understanding and documentation of designs.
Surfacing ‘101’ in a Linked Data manner as presented at SATToSE 2013Ralf Laemmel
The 101companies Project is a software chrestomathy or collection of small software systems that collects knowledge about software languages, technologies, and concepts. It models and implements a conceived human resources management system in various programming languages and technologies to demonstrate different features, designs, and concepts. It consists of contributions hosted in a GitHub repository, a semantically enriched wiki, and computational infrastructure for analyzing and synthesizing information from the repository and wiki.
Remote method invocation (as part of the the PTT lecture)Ralf Laemmel
Remote Method Invocation (RMI) allows objects to communicate between different computers in an object-oriented manner. RMI uses stubs and skeletons so that a client can invoke methods on remote objects hosted on a different machine, with the arguments and return values being serialized and transmitted over the network. Developers must design interfaces for remote services, implement those services, and start a registry and server to bind and look up remote objects that clients can then invoke.
Database programming including O/R mapping (as part of the the PTT lecture)Ralf Laemmel
The document discusses database programming and relational databases. It begins by introducing some key concepts about persisting data and separating data and functionality. It then covers modeling data using entity-relationship diagrams and mapping the model to relational tables in a database. The document concludes by discussing how to programmatically interact with the database using SQL and JDBC to create, read, update and delete data.
Multithreaded programming (as part of the the PTT lecture)Ralf Laemmel
This document discusses multithreading and concurrency in Java. It introduces key concepts like threads, thread pools, runnables, callables, and futures. It discusses how to implement parallelism using these concepts. It also covers concurrency issues like synchronization, deadlocks, and solutions like semaphores. Examples provided include a multithreaded string length summing program, a dining philosophers problem, and synchronized banking transactions.
The Expression Problem (as part of the the PTT lecture)Ralf Laemmel
The document discusses the Expression Problem and different approaches to solving it. The Expression Problem involves adding new data types and operations to an existing class hierarchy in a way that supports both extensibility. The document examines three approaches: 1) Using instanceof and casts which allows easy addition of data types and operations but is error prone. 2) Adding virtual methods which makes adding operations difficult by requiring code changes. 3) The Visitor Pattern which uses double dispatch to allow adding new operations without code changes to existing classes.
Selected design patterns (as part of the the PTT lecture)Ralf Laemmel
This document discusses several common design patterns, including Composite, Command, Visitor, Observer, MVC, Proxy, Object Adapter, Template Method and Abstract Factory. For each pattern, it provides a short description of the problem it addresses and its basic structure and solution. It also includes examples of how each pattern could be implemented.
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...alexjohnson7307
Predictive maintenance is a proactive approach that anticipates equipment failures before they happen. At the forefront of this innovative strategy is Artificial Intelligence (AI), which brings unprecedented precision and efficiency. AI in predictive maintenance is transforming industries by reducing downtime, minimizing costs, and enhancing productivity.
GraphRAG for Life Science to increase LLM accuracyTomaz Bratanic
GraphRAG for life science domain, where you retriever information from biomedical knowledge graphs using LLMs to increase the accuracy and performance of generated answers
Best 20 SEO Techniques To Improve Website Visibility In SERPPixlogix Infotech
Boost your website's visibility with proven SEO techniques! Our latest blog dives into essential strategies to enhance your online presence, increase traffic, and rank higher on search engines. From keyword optimization to quality content creation, learn how to make your site stand out in the crowded digital landscape. Discover actionable tips and expert insights to elevate your SEO game.
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...Alex Pruden
Folding is a recent technique for building efficient recursive SNARKs. Several elegant folding protocols have been proposed, such as Nova, Supernova, Hypernova, Protostar, and others. However, all of them rely on an additively homomorphic commitment scheme based on discrete log, and are therefore not post-quantum secure. In this work we present LatticeFold, the first lattice-based folding protocol based on the Module SIS problem. This folding protocol naturally leads to an efficient recursive lattice-based SNARK and an efficient PCD scheme. LatticeFold supports folding low-degree relations, such as R1CS, as well as high-degree relations, such as CCS. The key challenge is to construct a secure folding protocol that works with the Ajtai commitment scheme. The difficulty, is ensuring that extracted witnesses are low norm through many rounds of folding. We present a novel technique using the sumcheck protocol to ensure that extracted witnesses are always low norm no matter how many rounds of folding are used. Our evaluation of the final proof system suggests that it is as performant as Hypernova, while providing post-quantum security.
Paper Link: https://eprint.iacr.org/2024/257
For the full video of this presentation, please visit: https://www.edge-ai-vision.com/2024/06/temporal-event-neural-networks-a-more-efficient-alternative-to-the-transformer-a-presentation-from-brainchip/
Chris Jones, Director of Product Management at BrainChip , presents the “Temporal Event Neural Networks: A More Efficient Alternative to the Transformer” tutorial at the May 2024 Embedded Vision Summit.
The expansion of AI services necessitates enhanced computational capabilities on edge devices. Temporal Event Neural Networks (TENNs), developed by BrainChip, represent a novel and highly efficient state-space network. TENNs demonstrate exceptional proficiency in handling multi-dimensional streaming data, facilitating advancements in object detection, action recognition, speech enhancement and language model/sequence generation. Through the utilization of polynomial-based continuous convolutions, TENNs streamline models, expedite training processes and significantly diminish memory requirements, achieving notable reductions of up to 50x in parameters and 5,000x in energy consumption compared to prevailing methodologies like transformers.
Integration with BrainChip’s Akida neuromorphic hardware IP further enhances TENNs’ capabilities, enabling the realization of highly capable, portable and passively cooled edge devices. This presentation delves into the technical innovations underlying TENNs, presents real-world benchmarks, and elucidates how this cutting-edge approach is positioned to revolutionize edge AI across diverse applications.
Digital Marketing Trends in 2024 | Guide for Staying AheadWask
https://www.wask.co/ebooks/digital-marketing-trends-in-2024
Feeling lost in the digital marketing whirlwind of 2024? Technology is changing, consumer habits are evolving, and staying ahead of the curve feels like a never-ending pursuit. This e-book is your compass. Dive into actionable insights to handle the complexities of modern marketing. From hyper-personalization to the power of user-generated content, learn how to build long-term relationships with your audience and unlock the secrets to success in the ever-shifting digital landscape.
Have you ever been confused by the myriad of choices offered by AWS for hosting a website or an API?
Lambda, Elastic Beanstalk, Lightsail, Amplify, S3 (and more!) can each host websites + APIs. But which one should we choose?
Which one is cheapest? Which one is fastest? Which one will scale to meet our needs?
Join me in this session as we dive into each AWS hosting service to determine which one is best for your scenario and explain why!
Introduction of Cybersecurity with OSS at Code Europe 2024Hiroshi SHIBATA
I develop the Ruby programming language, RubyGems, and Bundler, which are package managers for Ruby. Today, I will introduce how to enhance the security of your application using open-source software (OSS) examples from Ruby and RubyGems.
The first topic is CVE (Common Vulnerabilities and Exposures). I have published CVEs many times. But what exactly is a CVE? I'll provide a basic understanding of CVEs and explain how to detect and handle vulnerabilities in OSS.
Next, let's discuss package managers. Package managers play a critical role in the OSS ecosystem. I'll explain how to manage library dependencies in your application.
I'll share insights into how the Ruby and RubyGems core team works to keep our ecosystem safe. By the end of this talk, you'll have a better understanding of how to safeguard your code.
Programming Foundation Models with DSPy - Meetup SlidesZilliz
Prompting language models is hard, while programming language models is easy. In this talk, I will discuss the state-of-the-art framework DSPy for programming foundation models with its powerful optimizers and runtime constraint system.
Dandelion Hashtable: beyond billion requests per second on a commodity serverAntonios Katsarakis
This slide deck presents DLHT, a concurrent in-memory hashtable. Despite efforts to optimize hashtables, that go as far as sacrificing core functionality, state-of-the-art designs still incur multiple memory accesses per request and block request processing in three cases. First, most hashtables block while waiting for data to be retrieved from memory. Second, open-addressing designs, which represent the current state-of-the-art, either cannot free index slots on deletes or must block all requests to do so. Third, index resizes block every request until all objects are copied to the new index. Defying folklore wisdom, DLHT forgoes open-addressing and adopts a fully-featured and memory-aware closed-addressing design based on bounded cache-line-chaining. This design offers lock-free index operations and deletes that free slots instantly, (2) completes most requests with a single memory access, (3) utilizes software prefetching to hide memory latencies, and (4) employs a novel non-blocking and parallel resizing. In a commodity server and a memory-resident workload, DLHT surpasses 1.6B requests per second and provides 3.5x (12x) the throughput of the state-of-the-art closed-addressing (open-addressing) resizable hashtable on Gets (Deletes).
Generating privacy-protected synthetic data using Secludy and MilvusZilliz
During this demo, the founders of Secludy will demonstrate how their system utilizes Milvus to store and manipulate embeddings for generating privacy-protected synthetic data. Their approach not only maintains the confidentiality of the original data but also enhances the utility and scalability of LLMs under privacy constraints. Attendees, including machine learning engineers, data scientists, and data managers, will witness first-hand how Secludy's integration with Milvus empowers organizations to harness the power of LLMs securely and efficiently.
Trusted Execution Environment for Decentralized Process MiningLucaBarbaro3
Presentation of the paper "Trusted Execution Environment for Decentralized Process Mining" given during the CAiSE 2024 Conference in Cyprus on June 7, 2024.
2. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Program generation
Specification Program
Program
generator
3. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Parser generation
Grammar
with some
code
Parser
Program
generator
4. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Generative programming
Generative programming is a style of computer
programming that uses automated source code
creation through generic frames, classes, prototypes,
templates, aspects, and code generators to improve
programmer productivity ... It is often related to code-
reuse topics such as component-based software
engineering and product family engineering.
Retrieved from Wikipedia
on 3 May, 2011.
5. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Language processing patterns
manual
patterns
generative
patterns
1. The Chopper Pattern
2. The Lexer Pattern
3. The Copy/Replace Pattern
4. The Acceptor Pattern
5. The Parser Pattern
6. The Lexer Generation Pattern
7. The Acceptor Generation Pattern
8. The Parser Generation Pattern
9. The Text-to-object Pattern
10.The Object-to-text Pattern
11.The Text-to-tree Pattern
12.The Tree-walk Pattern
13.The Parser Generation2 Pattern
7. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Lexer Generation Pattern
Intent:
Analyze text at the lexical level.
Use token-level grammar as input.
Operational steps (compile time):
1. Generate code from the lexer grammar.
2. Write boilerplate code to drive the lexer.
3. Write code to process token/lexeme stream.
4. Build generated and hand-written code.
8. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Token-level grammar for 101
COMPANY : 'company';
DEPARTMENT : 'department';
EMPLOYEE : 'employee';
MANAGER : 'manager';
ADDRESS : 'address';
SALARY : 'salary';
OPEN : '{';
CLOSE : '}';
STRING : '"' (~'"')* '"';
FLOAT : ('0'..'9')+ ('.' ('0'..'9')+)?;
WS : (' '|'r'? 'n'|'t')+;
9. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Lexer generation
....g ....javaANTLR
10. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
ANTLR
“ANTLR, ANother Tool for Language Recognition, is a language
tool that provides a framework for constructing recognizers,
interpreters, compilers, and translators from grammatical
descriptions containing actions in a variety of target languages.
ANTLR provides excellent support for tree construction, tree
walking, translation, error recovery, and error reporting.”
http://www.antlr.org/
11. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Boilerplate code for
lexer execution
FileInputStream stream = new FileInputStream(file);
ANTLRInputStream antlr = new ANTLRInputStream(stream);
MyLexer lexer = new MyLexer(antlr);
Token token;
while ((token = lexer.nextToken())
!=Token.EOF_TOKEN) {
...
}
Grammar-
derived class
12. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrLexer
13. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Define regular expressions for all tokens.
Generate code for lexer.
Set up input and token/lexeme stream.
Implement operations by iteration over pairs.
Build generated and hand-written code.
Summary of implementation aspects
15. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Acceptor Generation Pattern
Intent:
Verify syntactical correctness of input.
Use context-free grammar as input.
Operational steps (compile time):
1. Generate code from the context-free grammar.
2. Write boilerplate code to drive the acceptor (parser).
3. Build generated and hand-written code.
16. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
company :
'company' STRING '{' department* '}' EOF;
department :
'department' STRING '{'
('manager' employee)
('employee' employee)*
department*
'}';
employee :
STRING '{'
'address' STRING
'salary' FLOAT
'}';
Wanted: a
generated
acceptor
Context-free grammar for 101
17. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Parser generation
.g
...Lexer.java
...Parser.java
ANTLR
18. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Driver for acceptor
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
SetyLexer lexer = new ...Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...Parser parser = new ...Parser(tokens);
parser....();
}
}
This is basically boilerplate
code. Copy and Paste!
19. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Driver for acceptor
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
SetyLexer lexer = new ...Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...Parser parser = new ...Parser(tokens);
parser....();
}
}
Prepare System.in
as ANTLR input
stream
20. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Driver for acceptor
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
SetyLexer lexer = new ...Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...Parser parser = new ...Parser(tokens);
parser....();
}
}
Set up lexer
for language
21. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Driver for acceptor
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
SetyLexer lexer = new ...Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...Parser parser = new ...Parser(tokens);
parser....();
}
}
Obtain token
stream from lexer
22. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Driver for acceptor
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
SetyLexer lexer = new ...Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...Parser parser = new ...Parser(tokens);
parser....();
}
} Set up parser and
feed with token
stream of lexer
23. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Driver for acceptor
import org.antlr.runtime.*;
public class Test {
public static void main(String[] args) throws Exception {
ANTLRInputStream input = new ANTLRInputStream(System.in);
SetyLexer lexer = new ...Lexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
...Parser parser = new ...Parser(tokens);
parser....();
}
}
Invoke start
symbol of parser
24. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrAcceptor
25. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Define regular expressions for all tokens.
Define context-free productions for all nonterminals.
Generate code for acceptor (parser).
Set up input and token/lexeme stream.
Feed parser with token stream.
Acceptor (parser) execution = call start symbol.
Build generated and hand-written code.
Summary of implementation aspects
27. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Parser Generation Pattern
Intent:
Enable structure-aware functionality.
Use context-free grammar as the primary input.
Operational steps (compile time):
1. Include semantic actions into context-free grammar.
2. Generate code from enhanced grammar.
3. Write boilerplate code to drive the parser.
4. Build generated and hand-written code.
28. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A grammar rule with
a semantic action
employee :
STRING '{'
'address' STRING
'salary' s=FLOAT
{ total += Double.parseDouble($s.text); }
'}';
Semantic actions
are enclosed
between braces.
Variable local to
parser execution
Retrieve and parse
lexeme for the number
29. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrParser
30. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Parser descriptions can also use
“synthesized” attributes.
Add synthesized attributes to nonterminals.
Add semantic actions to productions.
expr returns [int value]
: e=multExpr {$value = $e.value;}
( '+' e=multExpr {$value += $e.value;}
| '-' e=multExpr {$value -= $e.value;}
)*;
(Context-free part in bold face.)
Compute an int
value
Perform addition
& Co.
32. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Text-to-object Pattern
Intent:
Enable structure-aware OO programs.
Build AST objects along parsing.
Operational steps (compile time):
1. Define object model for AST.
2. Instantiate Parser Generation pattern as follows:
Use semantic actions for AST construction.
33. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Acceptor---for comparison
company :
'company' STRING '{'
department*
'}'
EOF;
34. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
With semantic actions for
object construction included
company returns [Company c]:
{ $c = new Company(); }
'company' STRING
{ $c.setName($STRING.text); }
'{'
( topdept= department
{ $c.getDepts().add($topdept.d); }
)*
'}'
;
Construct company object.
Set name of company.
Add all departments.
35. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrObjects
37. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Text-to-object Pattern
Intent:
Map abstract syntax (in objects) to concrete syntax.
Operational steps (run/compile time):
This is ordinary OO programming.
Walk the object model for the AST.
Generate output via output stream.
38. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Methods for pretty printing
public void ppCompany(Company c, String s) throws IOException {
writer = new OutputStreamWriter(new FileOutputStream(s));
write("company");
space();
write(c.getName());
space();
write("{");
right();
nl();
for (Department d : c.getDepts())
ppDept(d);
left();
indent();
write("}");
writer.close();
}
Undo indentation
Indent
Write into OutputStream
Pretty print substructures
39. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrObjects
40. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Discussion
We should assume Visitor pattern on object model.
Challenges:
How to ensure that correct syntax is generated?
How can we maintain layout of input?
Alternative technology / technique options:
Template processors
Pretty printing libraries.
42. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Text-to-tree Pattern
Intent:
Enable structure-aware grammar-based programs.
Build AST trees along parsing.
Use grammar with tree construction actions as input.
Operational steps (compile time):
1. Author grammar with tree construction actions.
2. Generate parser.
Advanced stuff!
43. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Tree construction with ANTLR
department :
'department' name=STRING '{'
manager
('employee' employee)*
department*
'}'
-> ^(DEPT $name manager employee* department*)
;
ANTLR’s special semantic
actions for tree construction
44. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrTrees
46. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Tree-walk Pattern
Intent:
Operate on trees in a grammar-based manner.
Productions describe tree structure.
Semantic actions describe actions along tree walking.
Operational steps (compile time):
1. Author tree grammar (as opposed to CFG).
2. Add semantic actions.
3. Generate and build tree walker.
Advanced stuff!
47. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Total: Tree walking with ANTLR
company :
^(COMPANY STRING dept*)
;
dept :
^(DEPT STRING manager employee* dept*)
;
manager :
^(MANAGER employee)
;
employee :
^(EMPLOYEE STRING STRING FLOAT)
{ total += Double.parseDouble($FLOAT.text); }
;
Matching trees
rather than
parsing text.
Semantic actions
as before.
48. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Cut: Tree walking with ANTLR
Match trees
Rebuild tree
topdown : employee;
employee :
^(EMPLOYEE STRING STRING s=FLOAT)
-> ^(EMPLOYEE
STRING
STRING
FLOAT[
Double.toString(
Double.parseDouble(
$s.text) / 2.0d)])
;
Tree walking
strategy
49. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:antlrTrees
50. The Parser Generation2 Pattern
(That is, the Parser Generation Generation Pattern.)
See
the Parser Pattern
and
the Parser Generation Pattern
for comparison
51. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
The Parser Generation2 Pattern
Intent:
Enable structure-aware OO programs.
Build AST objects along parsing.
Use idomatic context-free grammar as the only input.
Operational steps (compile time):
1. Author idiomatic context-free grammar.
2. Generate object model from context-free grammar.
3. Generate enhanced grammar for AST construction.
4. Generate parser and continue as before.
52. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
More declarative
parser generation
idiomatic
grammar
Program
generator
....g
....java
object
model
53. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Idiomatic grammar for 101
Company : ...;
Department :
'department' dname=QqString '{'
" 'manager' manager=Employee"
" subdepartments=Department*
" " employees=NonManager*
" '}';
NonManager : ...;
Employee : ...;
Label all nonterminal
occurrences
Leverage predefined
token-level grammar
54. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Demo
http://101companies.org/wiki/
Contribution:yapg
55. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Bootstrapping
1. Develop ANTLR-based parser for idiomatic grammars.
2. Develop object model for ASTs for idiomatic grammars.
3. Develop ANTLR generator.
4. Develop object model generator.
5. Define idiomatic grammar of idiomatic grammars.
6. Generate grammar parser from said grammar.
7. Generate object model from said grammar.
8. Remove (1.) and (2.).
57. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
Summary
Language processing is a programming domain.
Grammars are program specifications in that domain.
Those specifications may be enhanced semantically.
Those specifications may also be constrained idiomatically.
Manual implementation of such specifications is not productive.
Parser generators automatically implement such specifications.
Parser generation is an instance of generative programming.
58. (C) 2010-2013 Prof. Dr. Ralf Lämmel, Universität Koblenz-Landau (where applicable)
A development cycle
for language-based tools
1. Author language samples.
2. Complete samples into test cases.
3. Author the EBNF for the language.
4. Refine EBNF into acceptor (using generation or not).
5. Build and test the acceptor.
6. Extend the acceptor with semantic actions.
7. Build and test the language processor.
Some bits of
software engineering