تقرير حول كتاب كيف تصنع مترجم مع كتاب LET'S BUILD A COMPILER تأليف Jack W. Crenshaw

Compiler construction brings together techniques from disparate parts of Computer  Science. The compiler deals with many big-picture issues. At its simplest, a compiler is just a computer program that takes as input one potentially executable  program and produces as output another, related, potentially executable program. As part of this translation, the compiler must perform syntax analysis  to determine if the input program is valid. To map that input program onto the finite resources of a target computer, the compiler must manipulate several distinct name spaces, allocate several different kinds of resources, and synchronize  the behavior of different run-time components. For the output program to have reasonable performance, it must manage hardware latencies in functional units, predict the flow of execution and the demand for memory, and reason  about the independence and dependence of different machine-level operations in the program. These sequences of articles are classes on the theory and practice of developing language compilers and parsers. by the time we are Finished, we will have covered every facet of compiler Production, designed a fresh programming language, and built a Operational compiler.

Compiler texts are Made  for Computer Scientists, and are tough boring  for the rest of us.but by the end of this series  you will by no way be a computer scientist, nor will you know all the mysterious aspects of compiler theory. It intend to completely  ignore the more theoretical aspects of the subject. What you Will know is al*the practical aspects that you needs to know  to build a functional system. The average text on compiler theory covers a lot of ground that we won't be covering here. The typical sequence is:
o An introductory chapter describing what a compiler is.
o A chapter or two on syntax equations, using Backus-Naur Form BNF.
o A chapter or two on lexical scanning, with emphasis on deterministic and non-deterministic finite automata.
o Several chapters on parsing theory, beginning with top-down recursive descent, and ending with LALR parsers.
o A chapter on intermediate languages, with emphasis on P-code and similar reverse polish representations.
o Many chapters on alternative ways to handle subroutines and parameter passing, type declarations, and such.
o A chapter toward the end on code generation, usually for some imaginary CPU with a simple instruction set. Most readers (and in fact, most college classes) never make it this far.
o A final chapter or two on optimization. This chapter often goes unread, too. 





I also will skip over most of the theory that puts people to sleep. Don't get me wrong: I don't belittle the theory, and it's vitally important when it comes to dealing with the more tricky parts of a given language. But I believe in putting first things first. Here we'll be dealing with the 95% of compiler techniques that don't need a lot of theory to handle. I also will discuss only one approach to parsing: top-down, recursive descent parsing, which is the ONLY technique that's at all amenable to hand-crafting a compiler. The other approaches are only useful if you have a tool like YACC, and also don't care how much memory space the final product uses. I also take a page from the work of Ron Cain,
the author of the Original Small C. Whereas almost all other compiler authors have historically used an intermediate language like P-code and divided the compiler into two parts (a front end that produces P-code, and a back end that processes P-code to produce executable object code), Ron showed us that it is a straightforward matter to make a compiler directly produce executable object code, in the form of assembler language statements. The code will  NOT be the world's tightest code ... producing optimized code is a much more difficult job. But it will work, and work reasonably well. Just so that I don't leave you with the impression that our end product will be worthless, I  DO  intend to show you how to "soup up" the compiler with some optimization.
Finally, I'll be using some tricks that I've found to be most Helpful in letting me understand what's going on without wading through a lot of boiler plate. Chief among these is the use of single-character tokens, with no embedded spaces, for the early design work. I figure that if I can get a parser to recognize and deal with I-T-L, I can get it to do the same with IF-THENELSE. And I can. In the second "lesson," I'll show you just how easy it is to extend a simple parser to handle tokens of arbitrary length. As another trick, I completely ignore file I/O, figuring that if I can read source from the keyboard and output object to the screen, I can also do it from/to disk files. Experience has proven that once a translator is working correctly, it's a straightforward matter to redirect the I/O to files. The last trick is that I make no attempt to do error correction/recovery. The programs we'll be building will RECOGNIZE errors, and will not CRASH, but they will simply stop on the first error ... just like good ol' Turbo does. There will be other tricks that you'll see as you go. Most of them can't be found in any compiler textbook, but they work.
Part I: INTRODUCTION (24th July 1988)
INTRODUCTION
THE CRADLE
Part II: EXPRESSION PARSING (24th July 1988)
GETTING STARTED
SINGLE DIGITS
BINARY EXPRESSIONS
GENERAl EXPRESSIONS
USING THE STACK
MULTIPLICATION AND DIVISION
PARENTHESES
UNARY MINUS
A WORD ABOUT OPTIMIZATION
Part III: MORE EXPRESSIONS (4th Aug 1988)
INTRODUCTION
VARIABLES
FUNCTIONS
MORE ON ERROR HANDLING
ASSIGNMENT STATEMENTS
MULTI-CHARACTER TOKENS
WHITE SPACE
Part IV: INTERPRETERS (24th July 1988)
INTRODUCTION
THE INTERPRETER
A LITTLE PHILOSOPHY
Part V: CONTROl CONSTRUCTS (19th Aug 1988)


INTRODUCTION
THE PLAN
SOME GROUNDWORK
THE IF STATEMENT
THE WHILE STATEMENT
THE LOOP STATEMENT
REPEAT-UNTIL
THE FOR LOOP
THE DO STATEMENT
THE BREAK STATEMENT
CONCLUSION

Part VI: BOOLEAN EXPRESSIONS (31st Aug 1988)


INTRODUCTION
THE PLAN
THE GRAMMAR
RELOPS
FIXING THE GRAMMAR
THE PARSER
MERGING WITH CONTRO*CONSTRUCTS
ADDING ASSIGNMENTS
Part VII: LEXICAl SCANNING (7th Nov 1988)


INTRODUCTION
EXICAl SCANNING
STATE MACHINES AND ALTERNATIVES
SOME EXPERIMENTS IN SCANNING
WHITE SPACE
STATE MACHINES
NEWLINES
OPERATORS
LISTS, COMMAS AND COMMAND LINES
GETTING FANCY
RETURNING A CHARACTER
DISTRIBUTED vs. CENTRALIZED SCANNERS
MERGING SCANNER AND PARSER
CONCLUSION
Part VIII: A LITTLE PHILOSOPHY (2nd Apr 1989)

INTRODUCTION
THE ROAD HOME
WHY IS IT SO SIMPLE?
CONCLUSION
Part IX: A TOP VIEW (16th Apr 1989)

INTRODUCTION
THE TOP LEVEL
THE STRUCTURE OF PASCAL
FLESHING IT OUT
DECLARATIONS
THE STRUCTURE OF C
Part X: INTRODUCING "TINY" (21st May 1989)

INTRODUCTION
GETTING STARTED
DECLARATIONS
DECLARATIONS AND SYMBOLS
INITIALIZERS
THE SYMBOl TABLE
EXECUTABLE STATEMENTS
BOOLEANS
CONTROl STRUCTURES
LEXICAl SCANNING
MULTI-CHARACTER VARIABLE NAMES
MORE RELOPS
INPUT/OUTPUT
CONCLUSION
Part XI: LEXICAl SCAN REVISITED (3rd Jun 1989)

INTRODUCTION
BACKGROUND
THE PROBLEM
THE SOLUTION
FIXING UP THE COMPILER
CONCLUSION
TINY VERSION 1.1
Part XII: MISCELLANY (5th Jun 1989)

INTRODUCTION
SEMICOLONS
SYNTACTIC SUGAR
DEALING WITH SEMICOLONS
A COMPROMISE
COMMENTS
SINGLE-CHARACTER DELIMITERS
MULTI-CHARACTER DELIMITERS
ONE-SIDED COMMENTS
CONCLUSION
Part XIII: PROCEDURES (27th Aug 1989)

INTRODUCTION
ONE LAST DIGRESSION
THE BASICS
A BASIS FOR EXPERIMENTS
DECLARING A PROCEDURE
CALLING THE PROCEDURE
PASSING PARAMETERS
THE SEMANTICS OF PARAMETERS
PASS-BY-VALUE
WHAT'S WRONG?
CALL-BY-REFERENCE
LOCAl VARIABLES
CONCLUSION
Part XIV: TYPES (26th May 1990)


INTRODUCTION
WHAT'S COMING NEXT?
THE SYMBOl TABLE
ADDING ENTRIES
ALLOCATING STORAGE
DECLARING TYPES
ASSIGNMENTS
THE COWARD'S WAY OUT
A MORE REASONABLE SOLUTION
LITERAl ARGUMENTS
ADDITIVE EXPRESSIONS
WHY SO MANY PROCEDURES?
MULTIPLICATIVE EXPRESSIONS
MULTIPLICATION
DIVISION
BEGINNING TO WIND DOWN
TO COERCE OR NOT TO COERCE
CONCLUSION
Part 15: BACK TO THE FUTURE (5th Mar 1994)


INTRODUCTION
NEW STARTS, OLD DIRECTIONS
STARTING OVER?
THE INPUT UNIT
THE OUTPUT UNIT
THE ERROR UNIT
SCANNING AND PARSING
THE SCANNER UNIT
DECISIONS, DECISIONS
PARSING
REFERENCES
Part 16: UNIT CONSTRUCTION (29th May 1995)


INTRODUCTION
JUST LIKE CLASSICAL?
FLESHING OUT THE PARSER
TERMS AND EXPRESSIONS
ASSIGNMENTS
BOOLEANS
BOOLEAN "AND"

تعليقات

المشاركات الشائعة من هذه المدونة

الشاشة الإفتتاحية لإكسل

أوامر الجافا سكريبت JavaScript

مسائل علي الترانزستورات MOSFET