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
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
1.3k
AppRouterを用いた大規模サービス開発におけるディレクトリ構成の変遷と問題点
eiganken
1
450
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
770
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
Amazon Nova Reelの可能性
hideg
0
200
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
1k
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.4k
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
960
AHC041解説
terryu16
0
400
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
快速入門可觀測性
blueswen
0
500
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Agile that works and the tools we love
rasmusluckow
328
21k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
4 Signs Your Business is Dying
shpigford
182
22k
Navigating Team Friction
lara
183
15k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
192
16k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Why Our Code Smells
bkeepers
PRO
335
57k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Music & Morning Musume
bryan
46
6.3k
Practical Orchestrator
shlominoach
186
10k
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.