complier - east china normal universityldou/8studentswork/10072130154.pdf · complier...
TRANSCRIPT
![Page 1: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/1.jpg)
Complier
Implementation in JAVA™
By 10072130154 程栋梁
![Page 2: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/2.jpg)
Introduction• Pascal-like grammar:
Initial PL/x grammar has been extended to cover the full Pascal
grammar.
• Graphic User Interface
User interface is implemented with JAVA™ swing framework.
Functionally, the compiler has syntax highlighting, Abstract Syntax Tree view , generated instructions view , data stack view and debug model that can pause after every single instruction.
• ToolUsing JavaCC™ to help, instead of LEX & YACC.
![Page 3: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/3.jpg)
About JavaCC• Java Compiler-Compiler
Formerly named Jack (rhymes with YACC), similar to YACC in
that it generates a parser from a formal grammar written in EBNF notation, except the output is Java source code.
• LL(K) rather than LR(1)Unlike YACC, however, JavaCC generates top-down parsers,
which limits it to the LL(k) class of grammars (in particular, left recursion cannot be used).
• Abstract Syntax Tree with JJTreeThe tree builder that accompanies it, JJTree, constructs its
trees from the bottom up.
![Page 4: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/4.jpg)
32 Key Words
array, begin, break, case, char, const, continue, do, downto, else, end, exit, false, for, function, if, integer, logical, of, procedure, program, read, real, repeat, result, then, to, true, until, var, while, write
![Page 5: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/5.jpg)
Identifier Types
• IntegerAutomatically cast to real when calculating with a real
number
• RealWhen a real number assigned to an integer ID, it is forced
to discard the fractional part.
• Logical
• ArrayOf any dimension and index
![Page 6: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/6.jpg)
Function and procedure
• Function
With return value
• Procedure
Without return value
• Parameters
Passed by value
• Check in symbol tableCheck name along with Parameters types
• Nested definition
![Page 7: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/7.jpg)
Statements• assignment
• if..then..[else..]
• repeat...until..
• do..while..
• for..to/downto..do..
• case..of..
• break/continue in loop block
• exit in procedure
• read
• write
![Page 8: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/8.jpg)
Following pages are some screenshots and my illustrations in
RED and Italic
![Page 9: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/9.jpg)
Menus and buttons
Code pane
Output pane
AST view
Instructions view and stack view
![Page 10: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/10.jpg)
Create a new or open an existing code.
Syntax highlighting:4 different colors forkeywords, numbers,comments and others
![Page 11: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/11.jpg)
After parsing
Outputs indicates parsed successfully.
AST view show the program’s structure.
![Page 12: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/12.jpg)
After compiling
Generated instructions
![Page 13: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/13.jpg)
Stack view in debug
Debug in one step
![Page 14: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/14.jpg)
nested functions
![Page 15: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/15.jpg)
case statement
![Page 16: Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier Implementation in JAVA™ ... Identifier Types •Integer Automatically cast to real when calculating](https://reader034.vdocuments.site/reader034/viewer/2022042021/5e783170cbd0936d2213dbdd/html5/thumbnails/16.jpg)
Functions with the same name but different parameters Array of multi-dimension