Master Thesis
Total Page:16
File Type:pdf, Size:1020Kb
KARADENİZ TECHNICAL UNIVERSITY THE GRADUATE SCHOOL OF NATURAL AND APPLIED SCIENCE COMPUTER ENGINEERING GRADUATE PROGRAM DESIGN AND IMPLEMENTATION OF A GENERAL INTERPRETER FOR STEP-BY-STEP SOLVING OF NONLINEAR SYSTEM OF EQUATIONS USING SYMBOLIC APPROACHES MASTER THESIS Computer Eng. Mohamed Yusuf HASSAN SEPTEMBER 2017 TRABZON FOREWORD This thesis is written as completion to the master of computer engineering, at Karadeniz Technical University. The subject of this thesis is focused on finding the roots of nonlinear functions with 푛 unknowns using a hybrid symbolic-numeric approach. I would like to offer my heart thanks to my master thesis supervisor, Asst. Prof. Dr. Hüseyin PEHLİVAN, for much support, guidance, and patient reading of my drafts and help make it sense. I am also grateful to other members of my thesis committee, Assoc. Prof. Dr. Mustafa ULUTAŞ and Assoc. Prof. Dr. Ahmet BARAN for their valuable feedback and encouragement. I would like to thank my parents for their love, constant encouragement and wonderful emotional support. I also like to thank my young brother who was there for me and gave me a great motivation to finish this work. This thesis would have taken far longer to complete without the encouragement from many other friends. The days would have passed far more slowly without the support of them. Mohamed Yusuf HASSAN Trabzon 2017 III THESIS STATEMENT I declare that, this Master Thesis, I have submitted with the tittle “Design and Implementation of a General Interpreter for Step-by-Step Solving of Nonlinear System of Equations Using Symbolic Approaches” has been completed under the guidance of my Master supervisor Asst. Prof. Dr. Hüseyin PEHLİVAN. All the data used in this thesis are obtained by simulation and experimental works done as part of this work in our research labs. All referred information used in thesis has been indicated in the text and cited in reference list. I have obeyed all research and ethical rules during my research and I accept all responsibility if proven otherwise. 05/09/2017 Mohamed Yusuf HASSAN IV TABLE OF CONTENTS Page No FOREWORD ....................................................................................................................... III THESIS STATEMENT ....................................................................................................... IV TABLE OF CONTENTS ..................................................................................................... V SUMMARY ..................................................................................................................... VIII ÖZET …………….. ............................................................................................................ IX LIST OF FIGURES .............................................................................................................. X LIST OF TABLES .............................................................................................................. XI LIST OF ABBREVIATIONS .......................................................................................... XIII 1 GENERAL INFORMATION ............................................................................... 1 1.1. Introduction ........................................................................................................... 1 1.2. Literature Review .................................................................................................. 3 1.3. Nonlinear Equations .............................................................................................. 7 1.3.1. Nonlinear Equations Introduction ......................................................................... 7 1.3.2. Methods for Solving Nonlinear Equations ............................................................ 8 1.3.3. Newton-Raphson Method ...................................................................................... 9 1.3.3.1. Graphical Depiction of Newton-Raphson Method .............................................. 10 1.3.3.2. Derivative of Newton-Raphson Method.............................................................. 10 1.3.3.2.1. Derivative of Newton-Raphson Method using Graph ......................................... 10 1.3.3.2.2. Derivative of Newton-Raphson Method of 1-Dimension System....................... 11 1.3.3.2.3. Derivative of Newton-Raphson Method of N-Dimenison System ...................... 12 1.4. Language Processors ........................................................................................... 14 1.4.1. Compilers ............................................................................................................ 14 1.4.2. Interpreters ........................................................................................................... 15 1.4.3. Mixed Compilation and Interpretation Systems .................................................. 16 1.4.4. Comparison between Compilers and Interpreters ............................................... 17 1.4.5. Basic Compiler Phases ........................................................................................ 17 1.4.5.1. Front-End ............................................................................................................. 17 1.4.5.2. Back-End ............................................................................................................. 18 V 1.5. Mathematical Expressions Interpretation ............................................................ 18 1.5.1. Lexical Analyser (Scanner) ................................................................................. 19 1.5.2. Syntax Analyser (Parser) ..................................................................................... 21 1.5.2.1. Context-Free Grammar ........................................................................................ 22 1.5.2.2. Derivation and Parsing Context-Free Grammar .................................................. 23 1.5.2.3. Parser Tree .......................................................................................................... 24 1.5.2.3.1. Ambiguity ............................................................................................................ 24 1.5.2.3.2. Left Recusrion ..................................................................................................... 25 1.5.2.3.3. Left Factoring ..................................................................................................... 26 1.5.3. Semantic Analyser ............................................................................................... 27 1.5.4. Symbol Table ....................................................................................................... 27 1.6. Parsing Techniques .............................................................................................. 28 1.6.1. Top-Down Parsing ............................................................................................... 28 1.6.1.1. LL Parsers ............................................................................................................ 29 1.6.1.2. First and Follow Sets ........................................................................................... 30 1.6.1.2.1. Firts Sets .............................................................................................................. 31 1.6.1.2.2. Follow Sets .......................................................................................................... 31 1.6.2. Bottom-Up Parsing .............................................................................................. 33 1.6.2.1. LR Parsers ........................................................................................................... 33 1.7. Automatic Parser Generator Tools .................................................................... 34 1.7.1. JavaCC ................................................................................................................. 35 1.8. Parser Tree Evaluation......................................................................................... 36 1.8.1. Instanceof Operator ............................................................................................. 36 1.8.2. Interpreter () Methods .......................................................................................... 36 1.8.3. Visitor Design Patter ........................................................................................... 37 2. STEP-BY-STEP SOLUTIONS FOR NONLINEAR SYSTEM OF EQUATIONS ...................................................................................................... 39 2.1. Introduction ......................................................................................................... 39 2.2. General Structure of the Implemented Mathematical Expresssion Interpreter .. 39 2.2.1. Lexical Analaysis ................................................................................................ 42 2.2.1.1. Token Declaration ............................................................................................... 42 2.2.2. Syntax Analaysis ................................................................................................. 43 2.2.2.1. Syntax Structure of Nonlinear Equations ............................................................ 44 VI 2.2.2.2. Generating Abstract Syntax Tree ........................................................................ 46 2.2.3. Semantic Analaysis ............................................................................................