Skip to content

This project showcases two approaches to parsing: a bottom-up parser using Flex & Bison, and a top-down parser using Flex & Recursive Descent. Developed as part of a Compiler course exercise, the parsers process Olympic sports data, identifying those that appeared in at least 7 Olympic games.

Notifications You must be signed in to change notification settings

YosiBs/Compiler-Ex2-Flex-Bison-RecursiveDecentParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Compiler-Ex2-Flex-Bison-RecursiveDecentParser

ex2 image

Overview

This repository contains the solution for the second exercise of the Compiler course. The exercise involved creating two versions of a parser: one using Flex & Bison and the other using Flex & Recursive Descent Parser.

Files

  • olympics.lex: The Flex file containing the lexical analyzer definitions.
  • olympics.y: The Bison file containing the parser definitions for the bottom-up approach.
  • olympics.c: The C file containing the parser definitions for the top-down approach.
  • test_olympics.txt: A sample input file with data on Olympic sports and the years they were part of the games.
  • Makefile: A Makefile to compile the Flex and Bison code and run the parsers on the sample input.

Usage

To compile and run the lexical analyzer and parsers, follow these steps:

Bottom-Up Parser (Flex & Bison)

  1. Generate the C source files using Flex and Bison:
    flex olympics.lex
    bison -d olympics.y
  2. Compile the generated C source files:
    gcc -o olympics_bison lex.yy.c olympics.tab.c
  3. Run the parser with the sample input:
    ./olympics_bison test_olympics.txt

Top-Down Parser (Flex & Recursive Descent)

  1. Generate the C source file using Flex:
    flex olympics.lex
  2. Compile the generated C source file along with the parser file:
    gcc -o olympics_recursive lex.yy.c olympics.c
  3. Run the parser with the sample input:
    ./olympics_recursive test_olympics.txt

Another Option is to Open the terminal in a desired folder and run this commands:

  1. make
  2. make run

Expected Output

The parsers will output the names of sports that appeared in at least 7 Olympic games and the average number of games per sport. For example:

sports which appeared in at least 7 olympic games:
Archery
Athletics
Basketball

average number of games per sport: 15.60

Authors

Additional Information

The input format and token types are detailed in the exercise description. Refer to the olympics.lex, olympics.y, and olympics.c files for the specific regular expressions and grammar rules used to match each token type.

References

Notes

Ensure Flex, Bison, and GCC are installed on your system to compile and run the parsers.

This project was completed as part of the Compiler course in June 2024.

About

This project showcases two approaches to parsing: a bottom-up parser using Flex & Bison, and a top-down parser using Flex & Recursive Descent. Developed as part of a Compiler course exercise, the parsers process Olympic sports data, identifying those that appeared in at least 7 Olympic games.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published