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 11
Search
Javier Gonzalez-Sanchez
PRO
December 14, 2023
Programming
0
110
UP Lecture 11
Compilers
Parser II
(202402)
Javier Gonzalez-Sanchez
PRO
December 14, 2023
Tweet
Share
More Decks by Javier Gonzalez-Sanchez
See All by Javier Gonzalez-Sanchez
CSC509 Lecture 13
javiergs
PRO
0
110
CSC305 Lecture 22
javiergs
PRO
0
61
CSC305 Lecture 22
javiergs
PRO
0
24
CSC509 Lecture 12
javiergs
PRO
0
160
CSC305 Lecture 21
javiergs
PRO
0
75
CSC305 Lecture 20
javiergs
PRO
0
59
CSC305 Lecture 19
javiergs
PRO
0
53
CSC509 Lecture 11
javiergs
PRO
0
180
CSC305 Lecture 18
javiergs
PRO
0
74
Other Decks in Programming
See All in Programming
受け取る人から提供する人になるということ
little_rubyist
0
230
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Outline View in SwiftUI
1024jp
1
330
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
950
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
Micro Frontends Unmasked Opportunities, Challenges, Alternatives
manfredsteyer
PRO
0
100
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
RailsConf 2023
tenderlove
29
900
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Six Lessons from altMBA
skipperchong
27
3.5k
Transcript
jgs Compilers Lecture 11: Parser II Dr. Javier Gonzalez-Sanchez
[email protected]
jgs Next
Dr. Javier Gonzalez-Sanchez | Compilers | 3 jgs Programming Assignment
2 Level 3 The complete grammar for our language
Dr. Javier Gonzalez-Sanchez | Compilers | 4 jgs 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
Dr. Javier Gonzalez-Sanchez | Compilers | 5 jgs 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> ')'
Dr. Javier Gonzalez-Sanchez | Compilers | 6 jgs 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> ')'
jgs New Rules
Dr. Javier Gonzalez-Sanchez | Compilers | 8 jgs Assignment 2
| Code ------------ program(root);
Dr. Javier Gonzalez-Sanchez | Compilers | 9 jgs 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
Dr. Javier Gonzalez-Sanchez | Compilers | 10 jgs 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
Dr. Javier Gonzalez-Sanchez | Compilers | 11 jgs Assignment 2
| Code public static void RULE_ASSIGNMENT() { } ASSIGNMENT
Dr. Javier Gonzalez-Sanchez | Compilers | 12 jgs Assignment 2
| Code public static void RULE_VARIABLE() { } VARIABLE
Dr. Javier Gonzalez-Sanchez | Compilers | 13 jgs Assignment 2
| Code public static void RULE_WHILE() { } WHILE
Dr. Javier Gonzalez-Sanchez | Compilers | 14 jgs Assignment 2
| Code public static void RULE_IF() { } IF
Dr. Javier Gonzalez-Sanchez | Compilers | 15 jgs Assignment 2
| Code public static void RULE_RETURN() { } RETURN
Dr. Javier Gonzalez-Sanchez | Compilers | 16 jgs Assignment 2
| Code public static void RULE_PRINT () { } PRINT
Dr. Javier Gonzalez-Sanchez | Compilers | 17 jgs Assignment 2
| Code public static void RULE_C() { } C
Dr. Javier Gonzalez-Sanchez | Compilers | 18 jgs Questions
Dr. Javier Gonzalez-Sanchez | Compilers | 19 jgs Homework Start
Working on a Parser (version 2)
Dr. Javier Gonzalez-Sanchez | Compilers | 20 jgs Homework Review
Recursion
jgs Compilers Javier Gonzalez-Sanchez, Ph.D.
[email protected]
Spring 2024 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.