Compile One, task overview
This big job will design and implement a mini Java language compiler
Mini Java Overview
Mini Java is a subset of the Java language. As a good teaching language for compiling courses, it is as concise as Java:
(1) Do not allow overloading (overloading)
(2) A file may declare several classes, but must have and only one main class, the auxiliary class can have multiple, the class cannot be declared public; there can be only one main method in the main class, and the signature of the method must be "public static void Main (string[])". Where the string[] parameter is not processed. There can be only one output statement in the Main method: System.out.println (int), which can only output integer variable values
(3) Only classes, no interfaces, inheritance relationships (single inheritance)
(4) Only variables and methods can be declared in class
(5) Only four types of variables: Integer (Integer), Boolean (Boolean), Array (array), object; only one type of array: integer array (int[]); variable must be declared as (auto) type
(6) The method must be public, must have a return value, the return value type is limited by (5), can have parameters, can not, there are no restrictions on the number of parameters, type is limited by (5)
(7) A total of 6 Chinese statements (statement): block, simple assignment statement (Assignment statement), array assignment statement (array assignment statement), print statement statement), if statement, while statement
(8) A total of 9 expressions (expression): with (and), Comparison (compare), plus (plus), subtraction (minus), multiply (times), array positioning (array lookup), array length, Messaging (message sending, that is, parameter passing), the main expression (primary expression), and the expression is "short-circuit and" (&&), the comparison can only be less than the comparison
(9) There are 9 kinds of main expressions: integers (integer), True (True), False (False), object, this, initialization (allocation), array initialization (array allocation), non (not), Brackets (BRACKET)
(10) Only empty arguments can be used when initializing, so there is no "constructor (constructor)" Concept
(11) There is no explicit definition of identifiers (IDENTIFIER), where it is specified that only letters, numbers, but must begin with a letter, case-sensitive
(12) There is no explicit definition of an integer (Integer_literal), which is defined here as an unsigned integer, 32 bits (0~4294967295)
(13) Do not allow comments
(14) Class variable declaration cannot initialize, initialization must be done in the method
(15) cannot define inner class
Reserved words, non-terminal
Reserved word
Identification code
Memory characters
Value
<EOF>
0
Eof
-
Boolean
1
BOOLEAN
-
Class
2
CLASS
-
Else
3
ELSE
-
Extends
4
EXTENDS
-
Fasle
5
FALSE
-
If
6
IF
-
Int
7
Int
-
Length
8
LENGTH
-
Main
9
MAIN
-
New
10
NEW
-
Public
11
Public
-
Return
12
Return
-
Static
13
STATIC
-
This
14
This
-
True
15
TRUE
-
void
16
VOID
-
While
17
While
-
String
18
STRING
-
System.out.println
19
PRINTLN
-
=
20
EQUAL
-
!
21st
Not
-
&&
22
and
-
+
23
PLUS
-
-
24
Minus
-
*
25
Times
-
<
26
COMPARE
-
.
27
DOT
-
;
28
Semicolon
-
,
29
COMMA
-
[
30
Left_square
-
]
31
Right_square
-
(
32
Left_bracket
-
)
33
Right_bracket
-
{
34
Left_block
-
}
35
Right_block
-
Identifier
36
Id_string
Internal string
unsigned integer
37
Id_integer
Integer value
This compiler overview
(1) Recursive subroutine method with backtracking for grammar analysis program
(2) to the source file for two times processing: The first time lexical analysis, the second time grammatical analysis
(3) Using compile-time static allocation of storage space
(4) Integer data type 32 bits, 4 bytes, boolean data type 8 bits, 1 bytes, memory (by list virtual) addressing 10 bits, 1KB
(5) For convenience, the parent class must be defined before the subclass
(6) Due to time, the compiler did the following simplification:
(i) expressions can only handle addition, subtraction, multiplication, less than comparison, logical and, and can only be evaluated directly on integers or Boolean values, not the values of variables
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.