front
所属分类:编译器/解释器
开发工具:Java
文件大小:24KB
下载次数:27
上传日期:2010-04-16 16:48:13
上 传 者:
yry8998
说明: 黑皮编译原理号称龙书,这里提供编译原理龙书全部源代码!!
(Compiler theory book called Black Dragon, here are compiled all the source code for the book Principles of dragons! !)
文件列表:
front\inter\Access.java (553, 2005-08-28)
front\inter\And.java (337, 2005-08-29)
front\inter\Arith.java (504, 2005-08-29)
front\inter\Break.java (266, 2007-02-19)
front\inter\Constant.java (503, 2005-08-28)
front\inter\Do.java (464, 2005-08-27)
front\inter\Else.java (591, 2005-08-27)
front\inter\Expr.java (738, 2005-08-29)
front\inter\Id.java (261, 2007-10-07)
front\inter\If.java (447, 2005-08-27)
front\inter\Logical.java (892, 2005-08-29)
front\inter\Node.java (396, 2005-08-29)
front\inter\Not.java (285, 2005-08-29)
front\inter\Op.java (288, 2005-08-29)
front\inter\Or.java (335, 2005-08-29)
front\inter\Rel.java (552, 2005-08-29)
front\inter\Seq.java (422, 2005-08-27)
front\inter\Set.java (546, 2005-08-29)
front\inter\SetElem.java (739, 2005-08-29)
front\inter\Stmt.java (318, 2005-08-27)
front\inter\Temp.java (251, 2005-08-29)
front\inter\Unary.java (447, 2005-08-30)
front\inter\While.java (526, 2005-08-27)
front\lexer\Lexer.java (2552, 2005-08-29)
front\lexer\Num.java (176, 2005-08-27)
front\lexer\Real.java (182, 2005-08-27)
front\lexer\Tag.java (357, 2005-08-27)
front\lexer\Token.java (148, 2005-08-27)
front\lexer\Word.java (623, 2005-08-27)
front\main\Main.java (259, 2005-08-27)
front\Makefile (491, 2005-08-27)
front\parser\Parser.java (6873, 2005-08-30)
front\symbols\Array.java (357, 2005-08-29)
front\symbols\Env.java (421, 2005-08-28)
front\symbols\Type.java (874, 2005-08-29)
front\tests\block1.i (111, 2007-10-07)
front\tests\block1.t (152, 2005-08-27)
front\tests\expr1.i (103, 2005-08-27)
front\tests\expr1.t (110, 2005-08-27)
... ...
The Language
The language is based on the fragments in Chapter 6: expressions, arrays,
boolean expressions, statements, declarations, blocks:
P -> { DD SS }
DD -> e | DD D | D
D -> T id ;
T -> T [ num ] | int | float | char | bool
SS -> e | SS S | S
S -> L = E ; | if ( B ) S | if ( B ) S else S | while ( B ) S
| do S while ( B ) ; | break ; | { DD SS }
B -> B or B | B and B | ! B | ( B ) | E rel E | true | false
E -> E + E | E - E | E * E | E / E | L | ( B ) | num
L -> L [ B ] | id
Package lexer
class Tag. Tags distinguish tokens.
class Token with subclasses Num, Real, and Word
class Lexer, with procedure scan
Package symbols
class Type. Put types here.
class Id. Could have put Id's with expressions; in fact Id extends Expr
clas Env. Linked symbol tables.
Package inter for intermediate code
For simplicity, the front end builds syntax trees. Three-address code is
emitted during a subsequent pass. We generate short-circuit code for
boolean expressions.
An optimizing compiler would presumably create intermediate-code objects
rather than emitting strings. Further, Chapter 9 has examples with code
that might be produced by backpatching -- that's a variant to be explored
separately.
Package parser
At one point, I had the parser and lexer in one package, called syntax.
The parser is kept separate for readability. We can present the lexer
early -- the parser "touches" the other packages, so it's best presented
later.
Directories tests and tmp
The makefile automatically runs a compiled front end on tests, presumed
to be in files ending in ".t"; for example, prog0.t is the quicksort
fragment from the running example in Chapter 9. The expected output is
in a file ending in ".i"; for example, prog0.i.
To distinguish between multiple declarations of the same name, uncomment
the line
// public String toString() {return "" + op.toString() + offset;}
in class Id in package inter. The intermediate code will then print the
offset as a suffix to an identifier.
近期下载者:
相关文件:
收藏者: