Skip to content

Latest commit

 

History

History
49 lines (42 loc) · 1.37 KB

File metadata and controls

49 lines (42 loc) · 1.37 KB

LL(1) Grammar Tools (Left Factoring, Left Recursion, FIRST/FOLLOW, Table)

C project that reads a context-free grammar, performs left factoring and left recursion removal, computes FIRST and FOLLOW sets, and builds an LL(1) parsing table. Includes sample grammars and a Makefile.

Features

  • Read grammar from grammar.txt
  • Left factoring transformation
  • Left recursion elimination
  • Compute FIRST and FOLLOW sets
  • Construct and display LL(1) parsing table

Project Structure

./
  grammar.txt         # Primary sample grammar
  grammar2.txt        # Additional samples
  grammar3.txt
  leftFactoring.c/.h
  leftRecursion.c/.h
  LL1Parser.c/.h
  utils.c/.h          # Shared data structures and helpers
  main.c              # Entry point
  Makefile            # Build and run targets
  README.md

Build

Using the provided Makefile (Linux/macOS with make, or Windows with make in MinGW/MSYS):

make

This produces the parser executable.

Run

make run

The program reads grammar.txt, applies transformations, prints FIRST/FOLLOW sets, and the LL(1) table.

Clean

make clean   # POSIX
make cleanW  # Windows

Notes

  • utils.c writes a space-stripped copy of the grammar to output.txt during processing.
  • Update grammar.txt to experiment with different grammars.
  • Compilation flags: -g -w (debugging enabled, warnings suppressed in Makefile).