Mini Java Compiler (1)

xiaoxiao2021-03-06  15

First, the task overview

This big job will design and implement a MINI JAVA language compiler

MINI Java Overview

MINI Java is a subset of Java languages. As a good compilation course teaching language, it has made the following comparal compared with Java:

(1) Do not allow overloading (OVERLOADING)

(2) A file can be declared in a file, but there must be only one primary class, the secondary class can have multiple, the class cannot be declared as public; the primary class can only have a primary method, the signature of this method must For "public static void main (string []), where the String [] parameter does not work. There can only be an output statement in the main method: system.out.println (int), which can only output integer variables

(3) Only class, there is no interface, there is inheritance relationship (single inheritance)

(4) Class can only declare variables and methods

(5) Only four variable types: Integer, Boolean, array, object; only one class: integer array (int []); variable must be affirmed as (Auto)

(6) The method must be public, must have a return value, the return value type is limited; the parameters can be, no, the number of parameters is not limited, the type is limited (5) limit

(7) A total of 6 statements: Code block (Block), an array assignment state, a print statement, an IF statement, a While statement

(8) A total of 9 expressions: and (and), comparison (PLUS), minus, multiply (TIMES), Array Lookup, array length (Array Length ), Message delivery, parameter delivery), primary expression; and expressions are "Short Road and" (&&); compare can only be smaller than comparison

(9) Main expression has 9 species: Integer, "true", "false", object, this, initialization, array allocation, non-NOT Brackets (Bracket)

(10) When initialization, only empty parameters can only be used, so there is no "constructor" concept (11) not clearly defined the identifier (Identifier), which is only a collection of letters and numbers here, but must be The beginning of the letters, the case is case sensitive

(12) There is no clear definition of integer (Integer_Literal), which is specified as unsigned integer, 32 bits (0 ~ 4294967295)

(13) Not allowed

(14) When the class variable declares cannot be initialized, the initialization must be completed in the method

(15) Can't define internal classes

Reserved word, end

Reserved word recognition encoding memory value 0eof-boolean1boolean-class2class-else3else-extends4extends-fasle5false-if6if-int7int-length8length-main9

! MAIN-new10NEW-public11PUBLIC-return12RETURN-static13STATIC-this14THIS-true15TRUE-void16VOID-while17WHILE-String18STRING-System.out.println19PRINTLN- = 20EQUAL- 21NOT - && 22AND- 23PLUS - 24MINUS- * 25TIMES- <26COMPARE-.27DOT-; 28SEMICOLON-, 29COMMA- [30LEFT_SQUARE-] 31Right_Square- (32left_bracket-) 33right_bracket- {34left_block-} 35Right_Block-identifier 36ID_STRING internal string no symbol integer 37ID_INTEGER integer value

This compiler overview

(1) Grammatical analysis program with tracered recursive subroutine

(2) Treatment of the source file: the first passage analysis, the second time grammar analysis

(3) Static allocation storage space when using compile

(4) Integer data type 32-bit, accounting for 4 bytes; Boolean data types, accounting for 1 bytes; memory (list virtual) Add 10-bit, 1KB

(5) In order to achieve convenience, the parent class must define before the subclass

(6) Due to time reasons, the compiler has made the following simplification:

(I) Expression can only handle addition, subtraction, multiplication, less than comparison, logic, and only calculate the integer or Boolean value without calculating the value of the variable.

(Ii) cannot handle method call

(Iii) cannot handle arrays

(Iv) cannot be initialized

(V) Cannot handle structured statements

转载请注明原文地址:https://www.9cbs.com/read-46701.html

New Post(0)