Font Size: a A A

Pointer Type Implemented In SNL Language

Posted on:2006-03-14Degree:MasterType:Thesis
Country:ChinaCandidate:Y ZhaoFull Text:PDF
GTID:2168360155953027Subject:Computer system architecture
Abstract/Summary:PDF Full Text Request
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...
Keywords/Search Tags:Implemented
PDF Full Text Request
Related items