Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
UP Lecture 15
Search
Javier Gonzalez-Sanchez
PRO
December 18, 2023
Programming
0
160
UP Lecture 15
Compilers
Parser II
(202503)
Javier Gonzalez-Sanchez
PRO
December 18, 2023
Tweet
Share
More Decks by Javier Gonzalez-Sanchez
See All by Javier Gonzalez-Sanchez
CSC486 Lecture 14
javiergs
PRO
0
140
CSC486 Lecture 13
javiergs
PRO
0
94
CSC486 Lecture 12
javiergs
PRO
0
99
CSC486 Lecture 11
javiergs
PRO
0
56
CSC486 Lecture 10
javiergs
PRO
1
91
CSC486 Lecture 08
javiergs
PRO
0
80
CSC486 Lecture 07
javiergs
PRO
0
140
CSC486 Lecture 06
javiergs
PRO
0
120
CSC486 Lecture 05
javiergs
PRO
0
110
Other Decks in Programming
See All in Programming
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
0
920
OpenTelemetryを活用したObservability入門 / Introduction to Observability with OpenTelemetry
seike460
PRO
0
320
体得しよう!RSA暗号の原理と解読
laysakura
3
530
CTFのWebにおける⾼難易度問題について
hamayanhamayan
1
980
2025/3/18 サービスの成長で生じる幅広いパフォーマンスの問題を、 AIで手軽に解決する
shirahama_x
0
160
生成AIの使いどころ
kanayannet
0
100
本当だってば!俺もTRICK 2022に入賞してたんだってば!
jinroq
0
250
Fluent UI Blazor 5 (alpha)の紹介
tomokusaba
0
140
パスキーのすべて / 20250324 iddance Lesson.5
kuralab
0
120
データベースエンジニアの仕事を楽にする。PgAssistantの紹介
nnaka2992
9
4.2k
Develop Faster With FrankenPHP
dunglas
2
2.5k
eBPF Updates (March 2025)
kentatada
0
130
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
336
57k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
We Have a Design System, Now What?
morganepeng
51
7.5k
Speed Design
sergeychernyshev
28
860
Facilitating Awesome Meetings
lara
53
6.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
135
33k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
31
4.7k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Designing for Performance
lara
606
69k
GraphQLとの向き合い方2022年版
quramy
45
14k
Code Reviewing Like a Champion
maltzj
522
39k
Transcript
jgs Compilers Lecture 15: Parser II Dr. Javier Gonzalez-Sanchez
[email protected]
jgs Previously …
Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs Class Token
Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs Class Automata
Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs Class Lexer
:: Your First Project
Dr. Javier Gonzalez-Sanchez | Compilers | 6 jgs Class Main
Dr. Javier Gonzalez-Sanchez | Compilers | 7 jgs Input
jgs Parser
Dr. Javier Gonzalez-Sanchez | Compilers | 9 jgs Class Main
| Next Step
Dr. Javier Gonzalez-Sanchez | Compilers | 10 jgs Class Parser
Dr. Javier Gonzalez-Sanchez | Compilers | 11 jgs Input
Dr. Javier Gonzalez-Sanchez | Compilers | 12 jgs Rules {
0; 1 + 2; 3 * (4 + hello); }
Dr. Javier Gonzalez-Sanchez | Compilers | 13 jgs Homework https://github.com/javiergs/TheParser/
Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs Homework You
Need your Own Lexer
jgs Next
Dr. Javier Gonzalez-Sanchez | Compilers | 16 jgs Parser 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
Dr. Javier Gonzalez-Sanchez | Compilers | 17 jgs Assignment 2
| Code PROGRAM Program this one
Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs Assignment 2
| Code METHODS Program this one
Dr. Javier Gonzalez-Sanchez | Compilers | 19 jgs Assignment 2
| Code BODY Program this one
Dr. Javier Gonzalez-Sanchez | Compilers | 20 jgs Assignment 2
| Code PARAMS Program this one
Dr. Javier Gonzalez-Sanchez | Compilers | 21 jgs Assignment 2
| Code PARAMS Program this one
Dr. Javier Gonzalez-Sanchez | Compilers | 22 jgs Assignment 2
| Code public static void RULE_ASSIGNMENT() { } ASSIGNMENT Program this one
Dr. Javier Gonzalez-Sanchez | Compilers | 23 jgs Parser public
static void RULE_BODY() { while (!tokens.get(currentToken).getWord().equals(“}”)) { RULE_EXPRESSION(); if (tokens.get(currentToken).getWord().equals(“;”)) currentToken++; else error(3); } } BODY
Dr. Javier Gonzalez-Sanchez | Compilers | 24 jgs Parser public
static void RULE_EXPRESSION() { RULE_X(); while (tokens.get(currentToken).getWord().equals(“|”)) { currentToken++; RULE_X(); } } EXPRESSION
Dr. Javier Gonzalez-Sanchez | Compilers | 25 jgs Parser public
static void RULE_X() { RULE_Y(); while (tokens.get(currentToken).getWord().equals(“&”)) { currentToken++; RULE_Y(); } } X
Dr. Javier Gonzalez-Sanchez | Compilers | 26 jgs Parser public
static void RULE_Y() { if (tokens.get(currentToken).getWord().equals(“!”)) { currentToken++; } RULE_R(); } Y
Dr. Javier Gonzalez-Sanchez | Compilers | 27 jgs Parser public
static void RULE_R() { RULE_E(); while ( tokens.get(currentToken).getWord().equals(“<”) |tokens.get(currentToken).getWord().equals(“>”) |tokens.get(currentToken).getWord().equals(“==”) |tokens.get(currentToken).getWord().equals(“!=”) ) { currentToken++; RULE_E(); } } R
Dr. Javier Gonzalez-Sanchez | Compilers | 28 jgs Parser public
static void RULE_E() { RULE_A(); while (tokens.get(currentToken).getWord().equals(“-”) | tokens.get(currentToken).getWord().equals(“+”) ) { currentToken++; RULE_A(); } } E
Dr. Javier Gonzalez-Sanchez | Compilers | 29 jgs Parser public
static void RULE_A() { RULE_B(); while (tokens.get(currentToken).getWord().equals(“/”) | tokens.get(currentToken).getWord().equals(“*”) ) { currentToken++; RULE_B(); } } A
Dr. Javier Gonzalez-Sanchez | Compilers | 30 jgs Parser public
static void RULE_B() { if (tokens.get(currentToken).getWord().equals(“-”)) { currentToken++; } RULE_C(); } B
Dr. Javier Gonzalez-Sanchez | Compilers | 31 jgs Parser public
static void RULE_C() { if (tokens.get(currentToken).getToken().equals(“integer”)) { currentToken++; } else if (tokens.get(currentToken).getToken().equals(“identifier”)) { currentToken++; } else if (tokens.get(currentToken).getWord().equals(“(”)) { currentToken++; RULE_EXPRESSION(); if (tokens.get(currentToken).getWord().equals(“)”)) { currentToken++; } else error(4); } } else { error (5); } } C
Dr. Javier Gonzalez-Sanchez | Compilers | 32 jgs Assignment 2
| Code public static void RULE_C() { } C
Dr. Javier Gonzalez-Sanchez | Compilers | 33 jgs Assignment 2
| Code public static void RULE_VARIABLE() { } VARIABLE
Dr. Javier Gonzalez-Sanchez | Compilers | 34 jgs Assignment 2
| Code public static void RULE_WHILE() { } WHILE
Dr. Javier Gonzalez-Sanchez | Compilers | 35 jgs Assignment 2
| Code public static void RULE_IF() { } IF
Dr. Javier Gonzalez-Sanchez | Compilers | 36 jgs Assignment 2
| Code public static void RULE_RETURN() { } RETURN
Dr. Javier Gonzalez-Sanchez | Compilers | 37 jgs Assignment 2
| Code public static void RULE_CALL_METHOD () { } CALL_METHOD
Dr. Javier Gonzalez-Sanchez | Compilers | 38 jgs Assignment 2
| Code public static void RULE_PARAM_VALUES () { } PARAM_VALUES
Dr. Javier Gonzalez-Sanchez | Compilers | 39 jgs Questions
jgs Compilers Javier Gonzalez-Sanchez, Ph.D.
[email protected]
Spring 2025 Copyright. These
slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.