This is an old revision of the document!
Table of Contents
Formal Languages and Compilers Course (year 2025/2026)
Assistant: Stefano Scanzio
www: https://www.skenz.it/ss
email: stefano.scanzio [ AT_SYMBOL ] polito.it
Telegram group of the course: https://t.me/+kDacjz9GKedkYjM0
News
- [2026/04/25]: Some modification highlighted in bold on the calendar of the course.
- [2026/03/19]: Welcome to the Formal Languages and Compilers course.
Calendar
- [2026/05/28] from 14:30 to 16:00 (room 8I) → Seventh classroom practice (Exam solutions)
- [2026/05/21] from 17:30 to 19:00 (LABINF) → Seventh laboratory tutoring (Group A-Z)
- [2026/05/21] from 16:00 to 17:30 (LABINF) → Seventh laboratory (Group A-Z)
- [2026/05/21] from 14:30 to 16:00 (room 8I) → Sixth classroom practice
- [2026/05/14] from 17:30 to 19:00 (LABINF) → Sixth laboratory tutoring (Group A-Z)
- [2026/05/14] from 16:00 to 17:30 (LABINF) → Sixth laboratory (Group A-Z)
- [2026/05/12] from 14:30 to 16:00 (room 5T) → Fifth classroom practice
- [2026/05/07] from 17:30 to 19:00 (LABINF) → Fifth laboratory tutoring (Group A-Z)
- [2026/05/07] from 16:00 to 17:30 (LABINF) → Fifth laboratory (Group A-Z)
- [2026/05/05] from 14:30 to 16:00 (room 5T) → Fourth classroom practice
- [2026/04/30] from 17:30 to 19:00 (LABINF) → Fourth laboratory tutoring (Group A-Z)
- [2026/04/30] from 16:00 to 17:30 (LABINF) → Fourth laboratory (Group A-Z)
- [2026/04/28] from 14:30 to 16:00 (room 5T) → Third classroom practice
- [2026/04/16] from 17:30 to 19:00 (LABINF) → Third laboratory tutoring (Group A-Z)
- [2026/04/16] from 16:00 to 17:30 (LABINF) → Third laboratory (Group A-Z)
- [2026/04/16] from 14:30 to 16:00 (room 8I) → Second classroom practice
- [2026/03/26] from 17:30 to 19:00 (LABINF) → Second laboratory tutoring (Group A-Z)
- [2026/03/26] from 16:00 to 17:30 (LABINF) → Second laboratory (Group A-Z)
- [2026/03/19] from 17:30 to 19:00 (LABINF) → First laboratory tutoring (Group A-Z)
- [2026/03/19] from 16:00 to 17:30 (LABINF) → First laboratory (Group A-Z)
- [2026/03/19] from 14:30 to 16:00 (room 8I) → First classroom practice
Tools installation
Installation in your PC
Install Windows: How to download and install Jflex, Java, and Cup in the Windows operating system
Install Linux Bash: How to download, install and configure Jflex, Java, and Cup in the Ubuntu Linux operating system with bash shell
Install macOS: How to download, install and configure Jflex, Java, and Cup in the macOS operating system
Slides (Practice in classroom)
- Practice 1: practice1_1.pdf, practice1_2.pdf, practice1_6.pdf
Regular expressions and the scanner JFlex
Other material: Context dependent regular expressions, inclusive states and exclusive states in Jflex
Classroom example: exClass-1.zip.
To compile and execute type the following commands:jflex exp.jflex javac Calc.java java Calc example_expr.txt
- Practice 2: practice2_1.pdf, practice2_2.pdf, practice2_6.pdf
Grammar and introduction of Cup
Example: exClass-2.zip.
Video on how to compile the example:
To compile and execute the example type the following commands:jflex scanner.jflex java java_cup.MainDrawTree parser.cup javac *.java java Main example_expr.txt
- Practice 3: practice3_1.pdf, practice3_2.pdf, practice3_6.pdf
Ambiguous grammars, Lists, Handling syntax errors
Additional material: complex example about shift/reduce conflicts: exClass-4.zip
- Practice 4: practice4_1.pdf, practice4_2.pdf, practice4_6.pdf
Semantic: Synthesized attributes
Classroom example: exClass-4b.zip
Additional material: debugging features of the Cup parser
- Practice 5: practice5_1.pdf, practice5_2.pdf, practice5_6.pdf
Semantic: Inherited attributes
Classroom example (Inherited attributes): exClass-5.zip
- Practice 6: practice6_1.pdf, practice6_2.pdf, practice6_6.pdf
Type-checking and exam solution
Commented exam: Exam 1.
Solution: sol_exam1
- Practice 7: exam2.pdf, 20150903.pdf
Exams commented in classroom
Solutions: Exam2: sol1, sol2, sol3
Other material:
Commented solution of 20150903.pdf exam: IMP: exam_20150903
Laboratories
- Laboratory 1: laboratory_1.pdf
Regular expression and the scanner JFlex
Before starting try to compile and to understand the following example: exClass-1.zip
Solutions: Exercise 1, Exercise 2, Exercise 3 - Laboratory 2: laboratory_2.pdf
Exercises regarding the JFlex scanner.
Solutions: Exercise 1, Exercise 2 - Laboratory 3: laboratory_3.pdf
Implement a parser for a simplified version of the C programming language (mini C), and a parser for all the C programming language
Provided code: for the first exercise the scanner, the main file, the makefile and part of the parser are provided: compiler_es3_before.zip
Solutions: Exercise 1, Exercise 2, Exercise 3 - Laboratory 4: laboratory_4.pdf
Parsing of a logic program and error handling for the mini C programming language.
Solutions: Exercise 1, Exercise 2 - Laboratory 6: laboratory_6.pdf
Realize a translator from mini C to Pseudo Assembler.
Description of the Pseudo Assembler language: interpreter.pdf
Download the interpreter: interpreter.jar
To solve the exercise start from the solution of the second exercise of laboratory 4: Exercise 2
Solutions: Exercise 1 - Laboratory 7:
Solve the following exam: Exam 1 and the following exercises about type checking; laboratory_7.pdf
Solutions: Exercise 1 Exercise 2
Other tools like Jflex/Cup
- Ply Examples: Laboratories solutions with Ply (i.e., scanner and parser in Python)
- Ply: Mini guide about the use of the Ply scanner and parser
- Flex Bison Examples: Laboratories solutions with Flex and Bison (i.e., scanner and parser in C)
- Flex Bison: Mini guide about the use of the Flex scanner and the Bison parser
Assignments
Previous assignments
- Flex Bison: Implementation of laboratories using the Flex scanner and the Bison parser in C
- Ply: Implementation of laboratories using the Ply scanner and parser
- Go to LLVM: Translator from the Go language to LLVM
- Julia to LLVM: Translator from the Julia language to LLVM
Useful Resources
- LLVM: Guide about the use of LLVM
Pseudo Assembler interpreter
- Description of the Pseudo Assembler language: interpreter.pdf
- Interpreter, jar version: interpreter.jar
To run the interpreter:java -jar interpreter.jar <filename> - Interpreter source code: interpreter.zip
Exams
- Some previous exams 20200720.pdf,20150903.pdf,20120626.pdf,20090909.pdf, 20081110.pdf, 20080912.pdf, 20080625.pdf, 20061107.pdf
Proposed Theses (Master Degree)
New research Master Theses (Research thesis, four different topics, starting May 2026) (watch the video)
Thesis proposals can be downloaded here: https://www.skenz.it/ss/theses
If interested, for informations, contact: stefano.scanzio [ AT_SYMBOL ] polito.it www: https://www.skenz.it/ss
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/compilers?rev=1781517801
