SlideShare a Scribd company logo
Tweaking with the
Java Compiler J--
Trung M Dang
TCSS 421 Compiler Construction
Scanning
Exercise 2.10: Multi-line comment:
- Added 1 branch to check for star after slash. If there is, ignore characters
until a star is encountered. If slash after this star, comment ends.
Scanning
Exercise 2.10: Multi-line comment:
Scanning
Exercise 2.11 and 2.12: Operators/Reserved words:
- Added new operators to TokenInfo.java
- Division was hard since it is used for comment.
- Added reserved words to TokenInfo and Hashtable.
Exercise 2.13: Double_literal
- Check if there is a dot. 2 if statements: start with 0 and not start
with 0.
Exercise 2.14: Float_literal, long_literal
- Switch statement with empty cases is brilliant: handles
number beginning with 0 to 9 in simple way
Exercise 2.15: Hexadecimal, otal…
- Added to TokenInfo.
- Check if literal begins with 0, and if there is any x character, b
character, or digit after that 0.
Parsing
Parser is structured from
less precedence
(assignmentExpression) to
high precedence
(postfixExpression)
- Higher precedence
methods are called last
Parsing
Exercise 3.21, 3.22, 3.23, 3.27, 3.28, 3.29, 3.34:
double, float, long, operators, , try-catch-finally,
throw(s), do-until
- Added more branches to method literal() in Parser in
the case of literals.
- Created more classes for AST, added tokens to
TokenInfo.
Exercise 3.24 ternary
- Difficult to do. New methods added:
• Parsing the expression until the question mark “?”
• Parsing the rest of the ternary expression.
Parsing
Exercise 3.25 For statement
- Both starts with initializer (example: int i = 0)
-> Solution: Overload the
localVariableDeclarationStatement() method in Parser
to indicate whether to consume the next character
after initializer. If not, then the character is used to
identify type of “for” statement.
Exercise 3.26: Switch
- Difficulty: BREAK is sometimes followed by a semi-
colon or a semi-colon and a right curly brace. Check to
see if there is a left curly brace first before checking the
switch block.
Type Checking
Exercise 4.1: One public type declaration
- Added counter to count public types. Only 1 is allowed.
Exercise 4.2: Jvariable
- Added an entry of the missing variable to the symbol table
as Type.ANY.
Code Generation
Modified Main.java to output JVM instructions, not the
default SPIM codes.
Code Generation
Exercise 5.7 Classic For
- rewriting the for-
statement into while-
statement.
- Added getters for out-of-
scope objects.
Code Generation
Exercise 5.11: ternary
- Each part of ternary is
extracted individually.
- Textbook:
• condition == false, branch
to the alternative.
• Generate code for the
consequent
• unconditional jump to the
end
• generating code for the
alternative
• generate code for the
assignment.
Code Generation
Exercise 5.12: OR
- Short circuited: branch
to true label if lhs == true.
If lhs == false, branch to
target label if rhs == false.
Code Generation
Exercise 5.15: Throw
- Added new class JThrowStatement
- Used addNoArgInstruction(ATHROW)
Code Generation
Exercise 5.21: Long primitive
- Generated codes for pushing
long variable to the stack
(ldc2_w) , but not storing it
(lstore_<n>)
 Solution: Added long type to
JVariable in codegenstore method.
The End
Thank you for listening!
Feel free to ask questions!

More Related Content

What's hot

Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
Jin Castor
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
Atul Sehdev
 
Interface and abstract classes
Interface and abstract classesInterface and abstract classes
Interface and abstract classes
Chang John
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
Noopur Gupta
 
14 interface
14  interface14  interface
14 interface
Ravindra Rathore
 
Java8 features
Java8 featuresJava8 features
Java8 features
Minal Maniar
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
Lecture 5
Lecture 5Lecture 5
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014
Noopur Gupta
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
Niloy Saha
 
Switch statement
Switch statementSwitch statement
Switch statement
Patrick John McGee
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
solutionjug4
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
Todor Kolev
 
If and select statement
If and select statementIf and select statement
If and select statement
Rahul Sharma
 
Devry ecet 370 week 3 ilab the stack and the queue ad ts new
Devry ecet 370 week 3 ilab the stack and the queue ad ts newDevry ecet 370 week 3 ilab the stack and the queue ad ts new
Devry ecet 370 week 3 ilab the stack and the queue ad ts new
nikig6806
 
Chap04
Chap04Chap04
Chap04
Terry Yoast
 
Final keyword
Final keywordFinal keyword
Final keyword
Namrata_Thakare
 

What's hot (18)

Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Interface and abstract classes
Interface and abstract classesInterface and abstract classes
Interface and abstract classes
 
Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013Eclipse and Java 8 - Eclipse Day India 2013
Eclipse and Java 8 - Eclipse Day India 2013
 
14 interface
14  interface14  interface
14 interface
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014JDT Embraces Lambda Expressions - EclipseCon North America 2014
JDT Embraces Lambda Expressions - EclipseCon North America 2014
 
Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
Switch statement
Switch statementSwitch statement
Switch statement
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
If and select statement
If and select statementIf and select statement
If and select statement
 
Devry ecet 370 week 3 ilab the stack and the queue ad ts new
Devry ecet 370 week 3 ilab the stack and the queue ad ts newDevry ecet 370 week 3 ilab the stack and the queue ad ts new
Devry ecet 370 week 3 ilab the stack and the queue ad ts new
 
Chap04
Chap04Chap04
Chap04
 
Final keyword
Final keywordFinal keyword
Final keyword
 

Viewers also liked

Organização eurocodigos
Organização eurocodigosOrganização eurocodigos
Organização eurocodigos
Admilson Da Silva Fernandes
 
curriculum vitae Dheya P. Yousif
curriculum vitae Dheya P. Yousifcurriculum vitae Dheya P. Yousif
curriculum vitae Dheya P. Yousif
Dheyaa yousuf
 
Tinnitus aus der Sicht der Zahnheilkunde
Tinnitus aus der Sicht der ZahnheilkundeTinnitus aus der Sicht der Zahnheilkunde
Tinnitus aus der Sicht der Zahnheilkunde
Tinnitus Research Initiative
 
Kim_Harlan_Resume_2016
Kim_Harlan_Resume_2016Kim_Harlan_Resume_2016
Kim_Harlan_Resume_2016
Kim Harlan
 
Tinnitus aus der Sicht der Audiologie
Tinnitus aus der Sicht der AudiologieTinnitus aus der Sicht der Audiologie
Tinnitus aus der Sicht der Audiologie
Tinnitus Research Initiative
 
Sokat várnak a natívtól a magyaroroszági hirdetők
Sokat várnak a natívtól a magyaroroszági hirdetőkSokat várnak a natívtól a magyaroroszági hirdetők
Sokat várnak a natívtól a magyaroroszági hirdetők
CEMPSalesHouse
 
What I have learned about myself Presentation 1
What I have learned about myself Presentation 1What I have learned about myself Presentation 1
What I have learned about myself Presentation 1
Depika Battu
 
Aula subsistema estrutural cimento concreto
Aula  subsistema estrutural cimento concretoAula  subsistema estrutural cimento concreto
Aula subsistema estrutural cimento concreto
UNAERP
 
Aula unidade 4
Aula  unidade 4Aula  unidade 4
Aula unidade 4
UNAERP
 
mouth dissolving tablet by raja
mouth dissolving tablet by rajamouth dissolving tablet by raja
mouth dissolving tablet by raja
Md Raza
 
Alessa Pointer's Resume
Alessa Pointer's ResumeAlessa Pointer's Resume
Alessa Pointer's Resume
Alessa Pointer
 
Trender inom mobila upplevelser - Webb, appar och wearables
Trender inom mobila upplevelser - Webb, appar och wearablesTrender inom mobila upplevelser - Webb, appar och wearables
Trender inom mobila upplevelser - Webb, appar och wearables
Daniel Chow
 

Viewers also liked (13)

Organização eurocodigos
Organização eurocodigosOrganização eurocodigos
Organização eurocodigos
 
curriculum vitae Dheya P. Yousif
curriculum vitae Dheya P. Yousifcurriculum vitae Dheya P. Yousif
curriculum vitae Dheya P. Yousif
 
Tinnitus aus der Sicht der Zahnheilkunde
Tinnitus aus der Sicht der ZahnheilkundeTinnitus aus der Sicht der Zahnheilkunde
Tinnitus aus der Sicht der Zahnheilkunde
 
Kim_Harlan_Resume_2016
Kim_Harlan_Resume_2016Kim_Harlan_Resume_2016
Kim_Harlan_Resume_2016
 
Tinnitus aus der Sicht der Audiologie
Tinnitus aus der Sicht der AudiologieTinnitus aus der Sicht der Audiologie
Tinnitus aus der Sicht der Audiologie
 
VN_7_8_PDF_final
VN_7_8_PDF_finalVN_7_8_PDF_final
VN_7_8_PDF_final
 
Sokat várnak a natívtól a magyaroroszági hirdetők
Sokat várnak a natívtól a magyaroroszági hirdetőkSokat várnak a natívtól a magyaroroszági hirdetők
Sokat várnak a natívtól a magyaroroszági hirdetők
 
What I have learned about myself Presentation 1
What I have learned about myself Presentation 1What I have learned about myself Presentation 1
What I have learned about myself Presentation 1
 
Aula subsistema estrutural cimento concreto
Aula  subsistema estrutural cimento concretoAula  subsistema estrutural cimento concreto
Aula subsistema estrutural cimento concreto
 
Aula unidade 4
Aula  unidade 4Aula  unidade 4
Aula unidade 4
 
mouth dissolving tablet by raja
mouth dissolving tablet by rajamouth dissolving tablet by raja
mouth dissolving tablet by raja
 
Alessa Pointer's Resume
Alessa Pointer's ResumeAlessa Pointer's Resume
Alessa Pointer's Resume
 
Trender inom mobila upplevelser - Webb, appar och wearables
Trender inom mobila upplevelser - Webb, appar och wearablesTrender inom mobila upplevelser - Webb, appar och wearables
Trender inom mobila upplevelser - Webb, appar och wearables
 

Similar to Project presentation

Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
Ashita Agrawal
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
parveen837153
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
ArnaldoCanelas
 
Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.ppt
Govind Samleti
 
Java tut1
Java tut1Java tut1
Java tut1
Sumit Tambe
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
Graham Royce
 
Java tut1
Java tut1Java tut1
Java tut1
Sumit Tambe
 
Javatut1
Javatut1 Javatut1
Javatut1
desaigeeta
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
Bui Kiet
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
Syed Farjad Zia Zaidi
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
Tarunsingh198
 
Java tutorials
Java tutorialsJava tutorials
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
VeerannaKotagi1
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
venud11
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Sagar Verma
 
Chap05
Chap05Chap05
Chap05
Terry Yoast
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
ranjanadeore1
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
Isham Rashik
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
sanjeeviniindia1186
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
Sanjeev Tripathi
 

Similar to Project presentation (20)

Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.pptJava_Tutorial_Introduction_to_Core_java.ppt
Java_Tutorial_Introduction_to_Core_java.ppt
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
Java tut1
Java tut1Java tut1
Java tut1
 
Javatut1
Javatut1 Javatut1
Javatut1
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
MODULE_2_Operators.pptx
MODULE_2_Operators.pptxMODULE_2_Operators.pptx
MODULE_2_Operators.pptx
 
1669958779195.pdf
1669958779195.pdf1669958779195.pdf
1669958779195.pdf
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Chap05
Chap05Chap05
Chap05
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 
Android Application Development - Level 3
Android Application Development - Level 3Android Application Development - Level 3
Android Application Development - Level 3
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 

Project presentation

  • 1. Tweaking with the Java Compiler J-- Trung M Dang TCSS 421 Compiler Construction
  • 2. Scanning Exercise 2.10: Multi-line comment: - Added 1 branch to check for star after slash. If there is, ignore characters until a star is encountered. If slash after this star, comment ends.
  • 4. Scanning Exercise 2.11 and 2.12: Operators/Reserved words: - Added new operators to TokenInfo.java - Division was hard since it is used for comment. - Added reserved words to TokenInfo and Hashtable. Exercise 2.13: Double_literal - Check if there is a dot. 2 if statements: start with 0 and not start with 0. Exercise 2.14: Float_literal, long_literal - Switch statement with empty cases is brilliant: handles number beginning with 0 to 9 in simple way Exercise 2.15: Hexadecimal, otal… - Added to TokenInfo. - Check if literal begins with 0, and if there is any x character, b character, or digit after that 0.
  • 5. Parsing Parser is structured from less precedence (assignmentExpression) to high precedence (postfixExpression) - Higher precedence methods are called last
  • 6. Parsing Exercise 3.21, 3.22, 3.23, 3.27, 3.28, 3.29, 3.34: double, float, long, operators, , try-catch-finally, throw(s), do-until - Added more branches to method literal() in Parser in the case of literals. - Created more classes for AST, added tokens to TokenInfo. Exercise 3.24 ternary - Difficult to do. New methods added: • Parsing the expression until the question mark “?” • Parsing the rest of the ternary expression.
  • 7. Parsing Exercise 3.25 For statement - Both starts with initializer (example: int i = 0) -> Solution: Overload the localVariableDeclarationStatement() method in Parser to indicate whether to consume the next character after initializer. If not, then the character is used to identify type of “for” statement. Exercise 3.26: Switch - Difficulty: BREAK is sometimes followed by a semi- colon or a semi-colon and a right curly brace. Check to see if there is a left curly brace first before checking the switch block.
  • 8. Type Checking Exercise 4.1: One public type declaration - Added counter to count public types. Only 1 is allowed. Exercise 4.2: Jvariable - Added an entry of the missing variable to the symbol table as Type.ANY.
  • 9. Code Generation Modified Main.java to output JVM instructions, not the default SPIM codes.
  • 10. Code Generation Exercise 5.7 Classic For - rewriting the for- statement into while- statement. - Added getters for out-of- scope objects.
  • 11. Code Generation Exercise 5.11: ternary - Each part of ternary is extracted individually. - Textbook: • condition == false, branch to the alternative. • Generate code for the consequent • unconditional jump to the end • generating code for the alternative • generate code for the assignment.
  • 12. Code Generation Exercise 5.12: OR - Short circuited: branch to true label if lhs == true. If lhs == false, branch to target label if rhs == false.
  • 13. Code Generation Exercise 5.15: Throw - Added new class JThrowStatement - Used addNoArgInstruction(ATHROW)
  • 14. Code Generation Exercise 5.21: Long primitive - Generated codes for pushing long variable to the stack (ldc2_w) , but not storing it (lstore_<n>)  Solution: Added long type to JVariable in codegenstore method.
  • 15. The End Thank you for listening! Feel free to ask questions!