Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier...

Post on 17-Mar-2020

10 views 0 download

Transcript of Complier - East China Normal Universityldou/8studentswork/10072130154.pdf · Complier...

Complier

Implementation in JAVA™

By 10072130154 程栋梁

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.

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.

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

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

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

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

Following pages are some screenshots and my illustrations in

RED and Italic

Menus and buttons

Code pane

Output pane

AST view

Instructions view and stack view

Create a new or open an existing code.

Syntax highlighting:4 different colors forkeywords, numbers,comments and others

After parsing

Outputs indicates parsed successfully.

AST view show the program’s structure.

After compiling

Generated instructions

Stack view in debug

Debug in one step

nested functions

case statement

Functions with the same name but different parameters Array of multi-dimension