CS 325: Software Engineering March 5, 2015 Modeling and Design of Rule-Based Systems Rule-Based Systems Interpreter Pattern Code Reviews.

Slides:



Advertisements
Similar presentations
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Advertisements

Elif Kongar*, Mahesh Baral and Tarek Sobh *Departments of Technology Management and Mechanical Engineering University of Bridgeport, Bridgeport, CT, U.S.A.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
Programming Types of Testing.
Behavioral Pattern: Interpreter C h a p t e r 5 – P a g e 149 Some programs benefit from having a language to describe operations that they can perform.
CHAPTER 1: AN OVERVIEW OF COMPUTERS AND LOGIC. Objectives 2  Understand computer components and operations  Describe the steps involved in the programming.
CS 355 – Programming Languages
CFGs and PDAs Sipser 2 (pages ). Last time…
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
An Overview of Programming Logic and Design
Describing Syntax and Semantics
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Fundamentals of Python: From First Programs Through Data Structures
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
Introduction to High-Level Language Programming
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Fundamentals of Python: First Programs
CS 501: Software Engineering Fall 1999 Lecture 16 Verification and Validation.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
AS Computing Introduction to Programming. What is a Computer Program? A list of instructions that a computer must work through, in a logical sequence,
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.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 11 Conditional.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
Visual Basic Programming
C Operators. CONTENTS C OPERATORS TYPES OF OPERATOR UNARY BINARY TERNARY ARITHMATIC RELATIONAL LOGICAL.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Objects – State u There are only two things we can do to an object u Inspect it’s state u Alter it’s state u This is a profound statement! u If you think.
Intermediate 2 Computing Unit 2 - Software Development.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Boolean Functions and Boolean Algebra Laxmikant Kale.
Types and Programming Languages
Concepts and Realization of a Diagram Editor Generator Based on Hypergraph Transformation Author: Mark Minas Presenter: Song Gu.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
PhD at CSE: Overview CSE department offers Doctoral degree in the Computer Science (CS) or Computer Engineering areas (CpE) at both MS to PhD and BS to.
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
ALGORITHMS AND FLOWCHARTS
Expressions and Control Flow in JavaScript
Lexical and Syntax Analysis
Karnaugh Maps (K-Maps)
Representation, Syntax, Paradigms, Types
Introduction to Primitive Data types
From now on: Combinatorial Circuits:
Flowcharts and Pseudo Code
Basic Programming Concepts
Basic Concepts of Algorithm
Chapter 10: Compilers and Language Translation
CS 325: Software Engineering
Introduction to Primitive Data types
Faculty of Computer Science and Information System
Presentation transcript:

CS 325: Software Engineering March 5, 2015 Modeling and Design of Rule-Based Systems Rule-Based Systems Interpreter Pattern Code Reviews

CS 325 March 5, 2015 Page 147 Rule-Based Systems Some software systems are set up to make decisions via a (occasionally convoluted) set of rules. Consider a university’s computer science department, which uses a set of admission criteria to process applications to its graduate program. Applications that clearly satisfy all of the admission criteria are classified as “accepted”; those that do not satisfy the criteria are classified as “rejected”; and the remaining applications are marked as “pending”. The applicant must have paid the application fee. The applicant must have a four-year undergraduate degree in a technical area. The applicant must have at least a 3.2 GPA on a 4.0 scale in the last two years of undergraduate course work. The applicant’s undergraduate degree is ranked (high, average, or low) based on its relevance to the CS curriculum. The applicant’s undergraduate degree-granting institution is ranked (high, average, or low). The applicant must have a sum of verbal and quantitative scores of at least 1,150 on the GRE with a quantitative score of at least 700 and a verbal score of at least 400. International applicants must have a score of at least 90 on the TOEFL Internet- Based Test or a score of at least 7.0 on the International English Language Testing System (IELTS).

CS 325 March 5, 2015 Page 148 Rule-Based Systems These rules can be concisely represented in a decision table Is fee paid?YNYYYYY UG degree relevant to CS?H--HAL- UG institution rank?H--AH-L All other conditions satisfied?Y-NYYYY Rule count AcceptedX RejectedXXX Pending investigationXX Wait for fee paidX

CS 325 March 5, 2015 Page 149 Rule-Based Systems To facilitate viewing the rule-based system as a software system, a grammar is defined to give the rules a syntax. rule-set ::= rule [rule] rule ::= condition-list '==>' action ';' condition-list ::= condition [‘&’ condition-list] condition ::= condition-name ‘=’ condition-value action ::= ‘accept’ | ‘reject’ | ‘pending’ | ‘wait’ condition-name ::= ‘fee-paid’ | ‘relevance’ | ‘inst-rank’ | ‘all-other’ condition-value ::= ‘Y’ | ‘N’ | ‘H’ | ‘A’ | ‘L’ Legend: ::= defined as ‘abc’ literal abc [abc] abc is optional a | b selectively a or b

CS 325 March 5, 2015 Page 150 Rule-Based Systems The grammar translates in a straightforward manner into a class diagram, and an actual implementation follows.

CS 325 March 5, 2015 Page 151 Interpreter Pattern Some programs benefit from having a language to describe operations that they can perform. The Interpreter Pattern generally describes defining a grammar for that language and using that grammar to interpret statements in that language. For example, a Boolean Expression is either a terminal expression (a Constant) or a compound expression (an AND, OR, or NOT Expression). A Boolean Expression is interpreted in the context of its variable names and values. For instance, the Boolean Expression (X AND NOT Y) OR Z in the context of (X,Y,Z) = (true, false, false) evaluates to eval(X AND NOT Y) OR eval(Z), which is (eval(X) AND eval(NOT Y)) OR false, which evaluates to (true AND NOT eval(Y)), which is NOT(false), resulting in an evaluation of true.

CS 325 March 5, 2015 Page 152 Interpreter Pattern As another example, consider Roman Numerals Reading left to right, a Roman Numeral can be interpreted via four “sub-interpreters”. First, the thousands characters (the leading “M” characters) are read. This is followed by the hundreds characters (either a 900-sequence “CM”, a 400-sequence “CD”, or an optional 500-sequence “D” followed by zero to three 100-sequences “C”). The tens and ones characters are handled similarly. Notice that all of the derived “expressions” are terminal.

CS 325 March 5, 2015 Page 153 Interpreter Pattern When a program presents a number of different, but somewhat similar, cases with which it must contend, it can be advantageous to use a simple language to describe these cases and then have the program interpret that language. Recognizing cases where the Interpreter Pattern can be helpful can be problematic, and programmers who lack training in formal languages or compilers often overlook this option. One fairly obvious place where languages are applicable is when the program must parse algebraic strings in order to carry out operations based on the computation of user-entered equations. A far more useful situation that uses the Interpreter Pattern is when the program produces varying kinds of output (e.g., generating reports based on a database without having to resort to elaborate SQL queries).

CS 325 March 5, 2015 Page 154 Code Reviews While there are many aspects to software quality, one particularly important emphasis is on the elimination of defects. Rationale: If the software doesn’t work right, other quality issues are irrelevant. How can defects be effectively eliminated? Since low defect content is best achieved where the defects are injected, software engineers should: remove their own defects determine the causes of their defects learn to prevent those defects When should the defects be eliminated? Rather than waiting until late in the development process (i.e., during testing, when locating and correcting defects is difficult and expensive), modern processes advocate eliminating defects during code review (and possibly even design review).

CS 325 March 5, 2015 Page 155 Code Reviews Defects are injected primarily during the code phase, with the design phase at second place and the requirements phase a distant third. Defects are removed primarily during the code phase, with the expensive test phase at second place and the much cheaper design phase a distant third.

CS 325 March 5, 2015 Page 156 Code Reviews In testing, you must detect unusual behavior figure out what the test program was doing find where the problem is in the program figure out which defect could cause such behavior With reviews and inspections, you follow your own logic know where you are when you find a defect know what the program should do, but did not know why this is a defect are in a better position to devise a correct fix

CS 325 March 5, 2015 Page 157 Code Reviews