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
CSC486 Lecture 04
javiergs
PRO
0
34
CSC486 Lecture 03
javiergs
PRO
0
17
CSC486 Lecture 02
javiergs
PRO
0
19
CSC486 Lecture 01
javiergs
PRO
0
41
CSC305 Lecture 26
javiergs
PRO
0
140
CSC305 Lecture 25
javiergs
PRO
0
140
CSC509 Lecture 14
javiergs
PRO
0
140
CSC305 Lecture 24
javiergs
PRO
0
50
CSC509 Lecture 13
javiergs
PRO
0
180
Other Decks in Programming
See All in Programming
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
Azure AI Foundryのご紹介
qt_luigi
1
210
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
300
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.4k
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.4k
良いユニットテストを書こう
mototakatsu
11
3.6k
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
210
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
7
1.4k
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
180
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
20241217 競争力強化とビジネス価値創出への挑戦:モノタロウのシステムモダナイズ、開発組織の進化と今後の展望
monotaro
PRO
0
290
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
335
57k
How GitHub (no longer) Works
holman
312
140k
Designing for humans not robots
tammielis
250
25k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Designing for Performance
lara
604
68k
Done Done
chrislema
182
16k
A better future with KSS
kneath
238
17k
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.