Pointer Type Implemented in SNL Language
- Author
- ZhaoYong
- Advisor
- LiuLei
- School
- Jilin University
- Major
- Computer System Architecture
- Classification
- TP314 Compiler,interpreter
- Degree
- Master's thesis
- Year
- 2005
- Downloads
- 45
- Citations
- 0
Abstract
This paper mainly introduced how to implement pointer type inSNL language.Pointer type implemented in compiler involves syntaxanlysis,semantic analysis,intermediate code generation andstorage-space manager.There are three general types of parsers for grammer.Universalparsing methods such as the Cocke-Younger-Kasami algorithm andEarley’s algorithm can parse any grammer.These methods, however,are too inefficient to use in production compilers. The methodscommonly used in compilers are classified as being either top-down orbottom-up.As indicated by their names, top-down parsers build parsetrees from the top(root) to the bottom(leaves), while bottom-up parsersstart from the leaves and work up to the root. In both cases, the inputto the parser is scanned from left to right, one symbol at a time. In thispaper, we use recursive-descent parsing method,a method of top-downmethod.In compiler syntax analysis phase, pointer type analysised onlycan complete pointer type defined and used is correct or not ingrammer,but it can not do more analysises, more analysises need workin semantic-analysis and type check phase. So mainly work in syntaxanalysis phase for pointer type is:Check pointer type defined in syntaxCheck pointer variable used in syntaxThe analysis for pointer type defined based on ordinarytypes,process rules is very simple. If type defined is pointer type,foreword token must to be identifier(ID). Pointer variable usedanalysis is a bit difficult. The token before this variable must to be aidentifier, in spite of variable identifier or field identifier. Variableidentifier and field identifier only define this pointer variable is asimple pointer type or a entry of record type.After lexical analysis and syntax analysis, the compiler mainlywok is semantic analysis phase. In this phase, compilers will use allkinds of symbol table technique for search. To determine thecorrection of pointer type in semantic, mainly problem is: Check pointer type defined in semantic Check pointer variable used in semantic Main work for checking pointer type defined in semantic is checking this variable is pointer type ? if yes, the usage of this variable is correct in semantic? The first question is so simple, we can do it just searching in symbol table, if searched it and it’s type is pointer type, express it is right, other is wrong. We must use iterate algorithm to process checking pointer variable used in semantic, as well as consumed a caret(^) notation at a loop statement, and checked it is pointer type in symbol table. In this phase , we also need involve foreword declaration and fill-back technique. The type checking for pointer, is analogue type checking forordinary type, because the pointer is mainly used in assign statementand as for arguments for procedures. First determine it is a pointer type,then compare their target type. if equal, it is right, otherwise wrong. The based question of dynamic-space manager is how to reply theuser’s request for allocing memory, and how to dealloc the memorythat user not used for the new request for allocing memory. firstquestion is simply, we only return a space that is free and size biggerenough, for deallocing, we must do more. We need combine adjacentfree-space, it can help to shrink fragment. There are 4 cases: 1. the left and right adjacent block is not free, in this case, we only release it and don’t do more. 2. the left block is free, but right is not. In this case, we combine this block and it’s left block to a block. 3. the right block is free but left is not. We do it as case 2. 4. the left block and right block are free. We need combine the three blocks into a block. The way is increasing the capacityp of the most left block size, and delete the right block node. This paper not involve is garbage collection. GC is character ofthe modern language,such as JAVA and C#. a great deal of work hasbeen done in the area of garbage collection algorithms. Any garbagecollection algorithm must do two basic things. First, it must detectgarbage objects, Second, it must reclaim the heap space used by thegarbage objects and make it avaiable to the program. Garbagedetection is ordinarily accomplished by defining a set of roots and
Table of contents
The first chapter 8-10
1.1 research background 8
1.2 The main objective 8
1.3 This major work done 8-10
Chapter lexical analysis procedures 10-12
2.1 Overview 10
2.2 SNL language alphabet and regular expressions 10-11
2.3 lexical analysis procedures mandate 11
2.4 pointer types of lexical analysis 11
2.5 lexical analysis procedures to achieve 11 - 12
Chapter parsing 12-23
3.1 Overview 12
3.2 recursive descent parser constructor 12-13
3.3 SNL language syntax diagram 13-18
3.4 pointer type parsing 18-22
3.4.1 common types of syntax analysis 19-20 < br /> 3.4.2 pointer type parsing 20-21
3.4.3 the use of pointer variables 21-22
3.5 parser implementation 22-23
Chapter semantic analysis 23-42
4.1 semantic analysis based 23-28
4.1.1 semantic Analysis content 23 -24
4.1.2 identifier and type of internal representation 24-26
4.1.3 symbol table structure 26-28
4.1.3.1 symbol Table localization and the establishment and Find 26-27
4.1.3.2 symbol table interface 27-28
4.2 semantic Analysis pointer type 28-33 < br /> 4.2.1 pointer types of internal representation 28-29
4.2.2 pointer type defined semantic analysis 29-30
4.2.3 the use of pointer variables in semantic checks 30-32
4.2.4 ahead declaration timing and backfill backfill algorithm 32-33
4.3 type checking 33-42 <br / > 4.3.1 General types of equivalence checking 33-40
4.3.2 pointer type equivalence checking 40-41
4.3.3 error Handling 41-42
Chapter runtime environment 42-49
5.1 target machine model 42-43
5.2 target machine instructions and format 43-45
5.3 interpreter and execution 45
5.4 interpreter execution instance 45-49
Chapter runtime storage space 49-65
6.1 runtime storage space structure 49
6.2 run-time memory allocation 49-65
6.2.1 static area storage allocation 50
6.2.2 stack area storage allocation 50-51
6.2.3 heap storage allocation 51-52
6.2.4 dynamic space ( heap space ) management 52-59
6.2.4.1 Overview 52-55
6.2.4.2 allocation and deallocation algorithms 55 - 59
6.2.5 runtime stack area during activity record with the organizational structure 59-65
6.2.5.1 records activities during 59-60
6.2 .5.2 dynamic link (DL) 60-61
6.2.5.3 variable Access 61-65
Chapter VII of the target code generation 65-70 <br / > 7.1 non- pointer type target code generation 65-68
7.1.1 declaration processing 66
7.1.2 assignment 66
7.1.3 procedure Call 66-67
7.1.4 while statement 67
7.1.5 if statement 67-68
7.1.6 for statement 68
7.2 code generation target pointer type 68-70
Chapter VIII instance 70-75
8.1 Tower of Hanoi example 70-71
8.2 binary sort 71-75
Chapter Summary 75-76
References 76-77 <br / > Thanks 77-78
Summary 78-81
Abstract 81-84
Related dissertations
- Object-oriented MSVL and Its Application to Verification of Composite Web Services
- Static Analysis of Pointer-related Path with Variable Relationship Graph and Symbolic Execution
- Design and Implementation of C to Java Automatic Program Transformation System Prototype
- Design and Implementation of C to Java Automatic Program Transformation System Prototype
- SDH access equipment , network interface and intelligent multiplexing