SlideShare a Scribd company logo
CSE340 - Principles of
Programming Languages
Lecture 12:
Parser Implementation II
Javier Gonzalez-Sanchez
javiergs@asu.edu
BYENG M1-38
Office Hours: By appointment
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2
Review
Programming Assignment 2
Level 1
Review and Understand the Source Code
posted in Blackboard.
Particularly the use of DefaultMutableTreeNode)
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3
Review
* Parser.java is the only file that you are allowed to modify
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4
Review
Programming Assignment 2
Level 2
Modify the Source Code
to include the rules PROGRAM and BODY, EXPRESSION, X, Y, R
(from Grammar 2)
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5
Review
<PROGRAM> à '{' <BODY> '}'
<BODY> à {<EXPRESSION>';'}
<EXPRESSION> à <X> {'|' <X>}
<X> à <Y> {'&' <Y>}
<Y> à ['!'] <R>
<R> à <E> {('>'|'<'|'=='|'!=') <E>}
<E> à <A> {(’+'|'-’) <A>}
<A> à <B> {('*'|'/') <B>}
<B> à ['-'] <C>
<C> à integer|
identifier|'(' <EXPRESSION> ')'
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6
Programming Assignment 2
Level 3
The complete grammar for our language
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7
KEYWORD {return, print}
STRING
Language
Actions
Expressions
(operators)
Instructions
Control
Structures
ARITHMETIC OPERATORS { +, -, *, /, =}
LOGIC OPERATORS { &, |, ! }
RELATIONAL OPERATORS {<, >, ==, !=}
KEYWORD { if, else, while, switch, case }
Data
INTEGER
FLOAT
HEXADECIMAL
CHAR
KEYWORD { void, int, char, string, float, boolean }
KEYWORD { true, false }
BINARY
Delimiter : ; , ( ) { } [ ]
Assignment 2 | Language
OCTAL
IDENTIFIER
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8
Assignment 2 | Grammar
<PROGRAM> à '{' <BODY> '}’
<BODY> à {<PRINT>';'|<ASSIGNMENT>';'|<VARIABLE>';’|<WHILE>|<IF>|<RETURN>';'}
<ASSIGNMENT> à identifier '=' <EXPRESSION>
<VARIABLE> à ('int'|'float'|'boolean'|'char’|'string'|'void')identifier
<WHILE> à 'while' '(' <EXPRESSION> ')' <PROGRAM>
<IF> à 'if' '(' <EXPRESSION> ')' <PROGRAM> ['else' <PROGRAM>]
<RETURN> à 'return'
<PRINT> à ’print’ ‘(‘ <EXPRESSION> ‘)’
<EXPRESSION> à <X> {'|' <X>}
<X> à <Y> {'&' <Y>}
<Y> à ['!'] <R>
<R> à <E> {('>'|'<'|'=='|'!=') <E>}
<E> à <A> {(’+'|'-’) <A>}
<A> à <B> {('*'|'/') <B>}
<B> à ['-'] <C>
<C> à integer | octal | hexadecimal | binary | true | false |
string | char | float | identifier|'(' <EXPRESSION> ')'
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9
Assignment 2 | Input
Are there syntactical errors?
{
float a;
x = 0;
int x;
y = 1 + 1;
x = (0b11) +(05 – 0xFF34);
while (2 == "hi") {
a = 2 > (4 + Y);
if (true) { if( 2 + 2 ) {} else {} }
}
print ("hello" + "world");
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10
Assignment 2 | Input
Are there syntactical errors?
{
int x;
x = 5;
x = 05;
x = 0x5ff;
x = 5.55;
x = "five";
x = ’5';
x = false;
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11
Assignment 2 | Input
Are there syntactical errors?
{
int x;
float x;
string x;
char x;
void x;
boolean x;
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12
Assignment 2 | Input
Are there syntactical errors?
{
x = "hello" + "world" – 'w' * 5 / 3.4;
x = y – hello & 0xffff | 05;
x = -7;
x = !y;
x = (cse340 + cse310) / cse101 ;
}
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13
Assignment 2 | Code
------------ program(root);
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14
Assignment 2 | Code
public static void RULE_PROGRAM() {
if (tokens.get(currentToken).getWord().equals(“{”)) {
currentToken++;
else
error(1);
RULE_BODY();
if (tokens.get(currentToken).getWord().equals(“}”))
currentToken++;
else
error(2);
}
PROGRAM
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15
Assignment 2 | Code
public static void RULE_BODY() {
while (!tokens.get(currentToken).getWord().equals(“}”)) {
if (tokens.get(currentToken).getToken().equals(“identifier”)) {
RULE_ASSIGNMENT();
if (tokens.get(currentToken).getWord().equals(“;”)) {
currentToken++;
else error(3);
} else if (tokens.get(currentToken).getToken().equals(“int”) | ...) {
RULE_VARIABLE();
if (tokens.get(currentToken).getWord().equals(";")) {
currentToken++;
else error(3);
} else if (tokens.get(currentToken).getWord().equals(“while”)) {
RULE_WHILE();
} else if (tokens.get(currentToken).getWord().equals(“if”)) {
RULE_IF();
} else if (tokens.get(currentToken).getWord().equals(“return”)) {
RULE_RETURN();
if (tokens.get(currentToken).getWord().equals(“;”)) {
currentToken++;
else
error(3);
} else error(4);
}
}
BODY
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16
Assignment 2 | Code
public static void RULE_ASSIGNMENT() {
}
ASSIGNMENT
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17
Assignment 2 | Code
public static void RULE_VARIABLE() {
}
VARIABLE
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18
Assignment 2 | Code
public static void RULE_WHILE() {
}
WHILE
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19
Assignment 2 | Code
public static void RULE_IF() {
}
IF
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20
Assignment 2 | Code
public static void RULE_RETURN() {
}
RETURN
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 21
Assignment 2 | Code
public static void RULE_PRINT () {
}
PRINT
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 22
Assignment 2 | Code
public static void RULE_C() {
}
C
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 23
PREDICTIVE
DESCENDENT
RECURSIVE
PARSER
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 24
Concepts
{
int a;
a = 0xFF + 0b111;
while (a != 05) {
if (true) {
a = 2.5e-1 / 7;
} else {
a = 'A’;
while(true) {
}
}
}
print ("hello");
}
PREDICTIVE
DESCENDENT
RECURSIVE
PARSER
Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 25
Homework
Programming Assignment #2
(Complete Levels 1 to 3)
CSE340 - Principles of Programming Languages
Javier Gonzalez-Sanchez
javiergs@asu.edu
Summer 2015
Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.
Ad

More Related Content

What's hot (11)

Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++
Rushil Aggarwal
 
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Ahmed Gad
 
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-StepArtificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
Ahmed Gad
 
C++ file
C++ fileC++ file
C++ file
Mukund Trivedi
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
Abhishek Sinha
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul Patel
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
Sushil Mishra
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
Ankush Kumar
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
Aman Deep
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project
D. j Vicky
 
c++ program using All data type and operators
c++ program using All data type and operators c++ program using All data type and operators
c++ program using All data type and operators
AMUDHAJAY
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++
Rushil Aggarwal
 
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Introduction to Artificial Neural Networks (ANNs) - Step-by-Step Training & T...
Ahmed Gad
 
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-StepArtificial Neural Networks (ANNs) - XOR - Step-By-Step
Artificial Neural Networks (ANNs) - XOR - Step-By-Step
Ahmed Gad
 
Computer Science class 12
Computer Science  class 12Computer Science  class 12
Computer Science class 12
Abhishek Sinha
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul Patel
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output) Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
Aman Deep
 
cbse 12 computer science investigatory project
cbse 12 computer science investigatory project  cbse 12 computer science investigatory project
cbse 12 computer science investigatory project
D. j Vicky
 
c++ program using All data type and operators
c++ program using All data type and operators c++ program using All data type and operators
c++ program using All data type and operators
AMUDHAJAY
 

Viewers also liked (20)

A73A CQWW 2012 Contest operation from the Desert of Qatar
A73A CQWW 2012 Contest operation from the Desert of QatarA73A CQWW 2012 Contest operation from the Desert of Qatar
A73A CQWW 2012 Contest operation from the Desert of Qatar
Tobias Wellnitz
 
Harris & Clark + IceMilk Aprons
Harris & Clark + IceMilk ApronsHarris & Clark + IceMilk Aprons
Harris & Clark + IceMilk Aprons
IceMilk Aprons
 
Thehub bocconi law
Thehub   bocconi lawThehub   bocconi law
Thehub bocconi law
The Hub Milan
 
Phenomenal Oct 1, 2009
Phenomenal Oct 1, 2009Phenomenal Oct 1, 2009
Phenomenal Oct 1, 2009
etalcomendras
 
Thehub Milan Startup Weekend
Thehub   Milan Startup WeekendThehub   Milan Startup Weekend
Thehub Milan Startup Weekend
The Hub Milan
 
Valvuloplastie
ValvuloplastieValvuloplastie
Valvuloplastie
sfa_angeiologie
 
Micazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project reportMicazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project report
Ankit Singh
 
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
Javier Gonzalez-Sanchez
 
Technologische trends voor journalistiek
Technologische trends voor journalistiekTechnologische trends voor journalistiek
Technologische trends voor journalistiek
Bart Van Belle
 
Sanghamitra Iyengar - Índia
Sanghamitra  Iyengar - ÍndiaSanghamitra  Iyengar - Índia
Sanghamitra Iyengar - Índia
Luis Fernando Guggenberger
 
Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009
etalcomendras
 
201107 ICALT
201107 ICALT201107 ICALT
201107 ICALT
Javier Gonzalez-Sanchez
 
Angeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumesAngeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumes
sfa_angeiologie
 
Phenomenal Oct 15, 2009
Phenomenal Oct 15, 2009Phenomenal Oct 15, 2009
Phenomenal Oct 15, 2009
etalcomendras
 
Accomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: BostonAccomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: Boston
The Hub Milan
 
Urban Cottage + IceMilk Aprons
Urban Cottage + IceMilk ApronsUrban Cottage + IceMilk Aprons
Urban Cottage + IceMilk Aprons
IceMilk Aprons
 
LiveOffice Email Archiving Makes Cents
LiveOffice Email Archiving Makes CentsLiveOffice Email Archiving Makes Cents
LiveOffice Email Archiving Makes Cents
Veritas Technologies LLC
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
dphil002
 
201506 CSE340 Lecture 23
201506 CSE340 Lecture 23201506 CSE340 Lecture 23
201506 CSE340 Lecture 23
Javier Gonzalez-Sanchez
 
RCMSL Phenomenal Aug 28, 2009
RCMSL Phenomenal Aug 28, 2009RCMSL Phenomenal Aug 28, 2009
RCMSL Phenomenal Aug 28, 2009
etalcomendras
 
A73A CQWW 2012 Contest operation from the Desert of Qatar
A73A CQWW 2012 Contest operation from the Desert of QatarA73A CQWW 2012 Contest operation from the Desert of Qatar
A73A CQWW 2012 Contest operation from the Desert of Qatar
Tobias Wellnitz
 
Harris & Clark + IceMilk Aprons
Harris & Clark + IceMilk ApronsHarris & Clark + IceMilk Aprons
Harris & Clark + IceMilk Aprons
IceMilk Aprons
 
Phenomenal Oct 1, 2009
Phenomenal Oct 1, 2009Phenomenal Oct 1, 2009
Phenomenal Oct 1, 2009
etalcomendras
 
Thehub Milan Startup Weekend
Thehub   Milan Startup WeekendThehub   Milan Startup Weekend
Thehub Milan Startup Weekend
The Hub Milan
 
Micazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project reportMicazxpl - Intelligent Sensors Network project report
Micazxpl - Intelligent Sensors Network project report
Ankit Singh
 
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
201404 Multimodal Detection of Affective States: A Roadmap Through Diverse Te...
Javier Gonzalez-Sanchez
 
Technologische trends voor journalistiek
Technologische trends voor journalistiekTechnologische trends voor journalistiek
Technologische trends voor journalistiek
Bart Van Belle
 
Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009
etalcomendras
 
Angeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumesAngeiologie 4 2013 - 1-2014 livre des resumes
Angeiologie 4 2013 - 1-2014 livre des resumes
sfa_angeiologie
 
Phenomenal Oct 15, 2009
Phenomenal Oct 15, 2009Phenomenal Oct 15, 2009
Phenomenal Oct 15, 2009
etalcomendras
 
Accomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: BostonAccomplishment, Aspirations & Challenges: Boston
Accomplishment, Aspirations & Challenges: Boston
The Hub Milan
 
Urban Cottage + IceMilk Aprons
Urban Cottage + IceMilk ApronsUrban Cottage + IceMilk Aprons
Urban Cottage + IceMilk Aprons
IceMilk Aprons
 
RCMSL Phenomenal Aug 28, 2009
RCMSL Phenomenal Aug 28, 2009RCMSL Phenomenal Aug 28, 2009
RCMSL Phenomenal Aug 28, 2009
etalcomendras
 
Ad

Similar to 201506 CSE340 Lecture 12 (20)

201506 CSE340 Lecture 11
201506 CSE340 Lecture 11201506 CSE340 Lecture 11
201506 CSE340 Lecture 11
Javier Gonzalez-Sanchez
 
201506 CSE340 Lecture 13
201506 CSE340 Lecture 13201506 CSE340 Lecture 13
201506 CSE340 Lecture 13
Javier Gonzalez-Sanchez
 
201506 CSE340 Lecture 21
201506 CSE340 Lecture 21201506 CSE340 Lecture 21
201506 CSE340 Lecture 21
Javier Gonzalez-Sanchez
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
201506 CSE340 Lecture 18
201506 CSE340 Lecture 18201506 CSE340 Lecture 18
201506 CSE340 Lecture 18
Javier Gonzalez-Sanchez
 
Flow Control and Exception Handling.pptx
Flow Control and Exception Handling.pptxFlow Control and Exception Handling.pptx
Flow Control and Exception Handling.pptx
Sheetal343198
 
Java operators
Java operatorsJava operators
Java operators
Shehrevar Davierwala
 
201505 CSE340 Lecture 05
201505 CSE340 Lecture 05201505 CSE340 Lecture 05
201505 CSE340 Lecture 05
Javier Gonzalez-Sanchez
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
ShriKant Vashishtha
 
An Introduction to Test Driven Development with React
An Introduction to Test Driven Development with ReactAn Introduction to Test Driven Development with React
An Introduction to Test Driven Development with React
FITC
 
201506 CSE340 Lecture 17
201506 CSE340 Lecture 17201506 CSE340 Lecture 17
201506 CSE340 Lecture 17
Javier Gonzalez-Sanchez
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
جامعة القدس المفتوحة
 
TDD: What is it good for?
TDD: What is it good for?TDD: What is it good for?
TDD: What is it good for?
David Simons
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
Neeraj Kaushik
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
STAMP Project
 
Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
Nattawut Phetmak
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
jessitron
 
201506 CSE340 Lecture 14
201506 CSE340 Lecture 14201506 CSE340 Lecture 14
201506 CSE340 Lecture 14
Javier Gonzalez-Sanchez
 
201506 CSE340 Lecture 15
201506 CSE340 Lecture 15201506 CSE340 Lecture 15
201506 CSE340 Lecture 15
Javier Gonzalez-Sanchez
 
Java script
Java scriptJava script
Java script
Shagufta shaheen
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Flow Control and Exception Handling.pptx
Flow Control and Exception Handling.pptxFlow Control and Exception Handling.pptx
Flow Control and Exception Handling.pptx
Sheetal343198
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
ShriKant Vashishtha
 
An Introduction to Test Driven Development with React
An Introduction to Test Driven Development with ReactAn Introduction to Test Driven Development with React
An Introduction to Test Driven Development with React
FITC
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
جامعة القدس المفتوحة
 
TDD: What is it good for?
TDD: What is it good for?TDD: What is it good for?
TDD: What is it good for?
David Simons
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
Neeraj Kaushik
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
jessitron
 
Ad

More from Javier Gonzalez-Sanchez (20)

201804 SER332 Lecture 01
201804 SER332 Lecture 01201804 SER332 Lecture 01
201804 SER332 Lecture 01
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 03
201801 SER332 Lecture 03201801 SER332 Lecture 03
201801 SER332 Lecture 03
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 04
201801 SER332 Lecture 04201801 SER332 Lecture 04
201801 SER332 Lecture 04
Javier Gonzalez-Sanchez
 
201801 SER332 Lecture 02
201801 SER332 Lecture 02201801 SER332 Lecture 02
201801 SER332 Lecture 02
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 26
201801 CSE240 Lecture 26201801 CSE240 Lecture 26
201801 CSE240 Lecture 26
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 25
201801 CSE240 Lecture 25201801 CSE240 Lecture 25
201801 CSE240 Lecture 25
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 24
201801 CSE240 Lecture 24201801 CSE240 Lecture 24
201801 CSE240 Lecture 24
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 23
201801 CSE240 Lecture 23201801 CSE240 Lecture 23
201801 CSE240 Lecture 23
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 22
201801 CSE240 Lecture 22201801 CSE240 Lecture 22
201801 CSE240 Lecture 22
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 21
201801 CSE240 Lecture 21201801 CSE240 Lecture 21
201801 CSE240 Lecture 21
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 20
201801 CSE240 Lecture 20201801 CSE240 Lecture 20
201801 CSE240 Lecture 20
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 19
201801 CSE240 Lecture 19201801 CSE240 Lecture 19
201801 CSE240 Lecture 19
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 18
201801 CSE240 Lecture 18201801 CSE240 Lecture 18
201801 CSE240 Lecture 18
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 17
201801 CSE240 Lecture 17201801 CSE240 Lecture 17
201801 CSE240 Lecture 17
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 16
201801 CSE240 Lecture 16201801 CSE240 Lecture 16
201801 CSE240 Lecture 16
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 15
201801 CSE240 Lecture 15201801 CSE240 Lecture 15
201801 CSE240 Lecture 15
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 13
201801 CSE240 Lecture 13201801 CSE240 Lecture 13
201801 CSE240 Lecture 13
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 12
201801 CSE240 Lecture 12201801 CSE240 Lecture 12
201801 CSE240 Lecture 12
Javier Gonzalez-Sanchez
 
201801 CSE240 Lecture 11
201801 CSE240 Lecture 11201801 CSE240 Lecture 11
201801 CSE240 Lecture 11
Javier Gonzalez-Sanchez
 

Recently uploaded (20)

Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb ClarkDeploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Peter Caitens
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025
Web Designer
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb ClarkDeploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Deploying & Testing Agentforce - End-to-end with Copado - Ewenb Clark
Peter Caitens
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World ExamplesMastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
Mastering Selenium WebDriver: A Comprehensive Tutorial with Real-World Examples
jamescantor38
 
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
!%& IDM Crack with Internet Download Manager 6.42 Build 32 >
Ranking Google
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts[gbgcpp] Let's get comfortable with concepts
[gbgcpp] Let's get comfortable with concepts
Dimitrios Platis
 
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdfTop Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
Top Magento Hyvä Theme Features That Make It Ideal for E-commerce.pdf
evrigsolution
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Artificial hand using embedded system.pptx
Artificial hand using embedded system.pptxArtificial hand using embedded system.pptx
Artificial hand using embedded system.pptx
bhoomigowda12345
 
Exchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv SoftwareExchange Migration Tool- Shoviv Software
Exchange Migration Tool- Shoviv Software
Shoviv Software
 
Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025Wilcom Embroidery Studio Crack Free Latest 2025
Wilcom Embroidery Studio Crack Free Latest 2025
Web Designer
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
How to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber PluginHow to Install and Activate ListGrabber Plugin
How to Install and Activate ListGrabber Plugin
eGrabber
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 

201506 CSE340 Lecture 12

  • 1. CSE340 - Principles of Programming Languages Lecture 12: Parser Implementation II Javier Gonzalez-Sanchez javiergs@asu.edu BYENG M1-38 Office Hours: By appointment
  • 2. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 2 Review Programming Assignment 2 Level 1 Review and Understand the Source Code posted in Blackboard. Particularly the use of DefaultMutableTreeNode)
  • 3. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 3 Review * Parser.java is the only file that you are allowed to modify
  • 4. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 4 Review Programming Assignment 2 Level 2 Modify the Source Code to include the rules PROGRAM and BODY, EXPRESSION, X, Y, R (from Grammar 2)
  • 5. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 5 Review <PROGRAM> à '{' <BODY> '}' <BODY> à {<EXPRESSION>';'} <EXPRESSION> à <X> {'|' <X>} <X> à <Y> {'&' <Y>} <Y> à ['!'] <R> <R> à <E> {('>'|'<'|'=='|'!=') <E>} <E> à <A> {(’+'|'-’) <A>} <A> à <B> {('*'|'/') <B>} <B> à ['-'] <C> <C> à integer| identifier|'(' <EXPRESSION> ')'
  • 6. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 6 Programming Assignment 2 Level 3 The complete grammar for our language
  • 7. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 7 KEYWORD {return, print} STRING Language Actions Expressions (operators) Instructions Control Structures ARITHMETIC OPERATORS { +, -, *, /, =} LOGIC OPERATORS { &, |, ! } RELATIONAL OPERATORS {<, >, ==, !=} KEYWORD { if, else, while, switch, case } Data INTEGER FLOAT HEXADECIMAL CHAR KEYWORD { void, int, char, string, float, boolean } KEYWORD { true, false } BINARY Delimiter : ; , ( ) { } [ ] Assignment 2 | Language OCTAL IDENTIFIER
  • 8. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 8 Assignment 2 | Grammar <PROGRAM> à '{' <BODY> '}’ <BODY> à {<PRINT>';'|<ASSIGNMENT>';'|<VARIABLE>';’|<WHILE>|<IF>|<RETURN>';'} <ASSIGNMENT> à identifier '=' <EXPRESSION> <VARIABLE> à ('int'|'float'|'boolean'|'char’|'string'|'void')identifier <WHILE> à 'while' '(' <EXPRESSION> ')' <PROGRAM> <IF> à 'if' '(' <EXPRESSION> ')' <PROGRAM> ['else' <PROGRAM>] <RETURN> à 'return' <PRINT> à ’print’ ‘(‘ <EXPRESSION> ‘)’ <EXPRESSION> à <X> {'|' <X>} <X> à <Y> {'&' <Y>} <Y> à ['!'] <R> <R> à <E> {('>'|'<'|'=='|'!=') <E>} <E> à <A> {(’+'|'-’) <A>} <A> à <B> {('*'|'/') <B>} <B> à ['-'] <C> <C> à integer | octal | hexadecimal | binary | true | false | string | char | float | identifier|'(' <EXPRESSION> ')'
  • 9. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 9 Assignment 2 | Input Are there syntactical errors? { float a; x = 0; int x; y = 1 + 1; x = (0b11) +(05 – 0xFF34); while (2 == "hi") { a = 2 > (4 + Y); if (true) { if( 2 + 2 ) {} else {} } } print ("hello" + "world"); }
  • 10. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 10 Assignment 2 | Input Are there syntactical errors? { int x; x = 5; x = 05; x = 0x5ff; x = 5.55; x = "five"; x = ’5'; x = false; }
  • 11. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 11 Assignment 2 | Input Are there syntactical errors? { int x; float x; string x; char x; void x; boolean x; }
  • 12. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 12 Assignment 2 | Input Are there syntactical errors? { x = "hello" + "world" – 'w' * 5 / 3.4; x = y – hello & 0xffff | 05; x = -7; x = !y; x = (cse340 + cse310) / cse101 ; }
  • 13. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 13 Assignment 2 | Code ------------ program(root);
  • 14. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 14 Assignment 2 | Code public static void RULE_PROGRAM() { if (tokens.get(currentToken).getWord().equals(“{”)) { currentToken++; else error(1); RULE_BODY(); if (tokens.get(currentToken).getWord().equals(“}”)) currentToken++; else error(2); } PROGRAM
  • 15. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 15 Assignment 2 | Code public static void RULE_BODY() { while (!tokens.get(currentToken).getWord().equals(“}”)) { if (tokens.get(currentToken).getToken().equals(“identifier”)) { RULE_ASSIGNMENT(); if (tokens.get(currentToken).getWord().equals(“;”)) { currentToken++; else error(3); } else if (tokens.get(currentToken).getToken().equals(“int”) | ...) { RULE_VARIABLE(); if (tokens.get(currentToken).getWord().equals(";")) { currentToken++; else error(3); } else if (tokens.get(currentToken).getWord().equals(“while”)) { RULE_WHILE(); } else if (tokens.get(currentToken).getWord().equals(“if”)) { RULE_IF(); } else if (tokens.get(currentToken).getWord().equals(“return”)) { RULE_RETURN(); if (tokens.get(currentToken).getWord().equals(“;”)) { currentToken++; else error(3); } else error(4); } } BODY
  • 16. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 16 Assignment 2 | Code public static void RULE_ASSIGNMENT() { } ASSIGNMENT
  • 17. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 17 Assignment 2 | Code public static void RULE_VARIABLE() { } VARIABLE
  • 18. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 18 Assignment 2 | Code public static void RULE_WHILE() { } WHILE
  • 19. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 19 Assignment 2 | Code public static void RULE_IF() { } IF
  • 20. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 20 Assignment 2 | Code public static void RULE_RETURN() { } RETURN
  • 21. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 21 Assignment 2 | Code public static void RULE_PRINT () { } PRINT
  • 22. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 22 Assignment 2 | Code public static void RULE_C() { } C
  • 23. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 23 PREDICTIVE DESCENDENT RECURSIVE PARSER
  • 24. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 24 Concepts { int a; a = 0xFF + 0b111; while (a != 05) { if (true) { a = 2.5e-1 / 7; } else { a = 'A’; while(true) { } } } print ("hello"); } PREDICTIVE DESCENDENT RECURSIVE PARSER
  • 25. Javier Gonzalez-Sanchez | CSE340 | Summer 2015 | 25 Homework Programming Assignment #2 (Complete Levels 1 to 3)
  • 26. CSE340 - Principles of Programming Languages Javier Gonzalez-Sanchez javiergs@asu.edu Summer 2015 Disclaimer. These slides can only be used as study material for the class CSE340 at ASU. They cannot be distributed or used for another purpose.
  翻译: