Skip to content

Repository files navigation

PLY-Based Python Syntax Parser

This project demonstrates the use of the PLY (Python Lex-Yacc) library to build lexical analyzers and parsers for a subset of Python constructs. It features:

  • Syntax validation for function definitions
  • Parsing for control structures (if/else, for, while)
  • Support for list declarations

Features

  • Function declaration parsing
  • If and If-Else conditional parsing
  • For loop parsing (including range variations)
  • While loop parsing with logical expressions
  • List declaration parsing with support for integers, floats, and strings
  • Error handling for invalid syntax and tokens

Requirements

  • Python 3.x
  • PLY library (pip install ply)

How to Run

  1. Install Python 3.x and the PLY library (pip install ply).
  2. Clone or download the project files.
  3. Run any parser script (e.g., python function_parser.py).
  4. Enter a code snippet when prompted to validate its syntax.

Files

  • function_parser.py: Parser for function declarations
  • if_else_parser.py: Parser for if and if-else conditionals
  • for_loop_parser.py: Parser for for loops
  • while_loop_parser.py: Parser for while loops
  • list_parser.py: Parser for list declarations

Notes

  • This project is developed for educational purposes as part of AFLL coursework.
  • Each parser handles a specific subset of Python syntax.

License

This project is licensed under the MIT License.

About

A lexical analyzer and parser built using PLY (Python Lex-Yacc) to identify and validate simplified Python constructs like function declarations, conditional statements, loops, and list declarations.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages