Skip to content

About

Python-based syntax validator supporting variable declarations, expressions, conditionals, and loops.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Programming Language Syntax Validator

A syntax validator built using Python and PLY (Python Lex-Yacc) that performs lexical analysis and parsing for a simple programming language. The project tokenizes source code, validates it against predefined grammar rules, and reports syntax errors.

Features

  • Lexical analysis using PLY Lex
  • Parsing using Context-Free Grammar (CFG)
  • Variable declaration validation (int, float, char)
  • Assignment statement parsing
  • Arithmetic expression parsing
  • Conditional statement (if-else) support
  • do-while loop parsing
  • Syntax error detection and reporting

Tech Stack

  • Python
  • PLY (Python Lex-Yacc)

Grammar Supported

The parser supports:

  • Variable declarations
  • Variable assignments
  • Arithmetic expressions
  • if / if-else statements
  • do-while loops
  • Relational conditions

Example:

int x = 10;
float y = 20;

if (x < 20) {
    x = x + 1;
}

do {
    x = x + 1;
} while (x < 30);

Project Structure

.
├── lexer.py          # Lexical analyzer
├── parser.py         # Grammar rules and parser
├── input.txt         # Sample input program
└── README.md

How It Works

  1. The lexer scans the source code and converts it into tokens.
  2. The parser processes the token stream using Context-Free Grammar rules.
  3. Valid programs are accepted by the parser.
  4. Invalid syntax is detected and reported with descriptive error messages.

Learning Outcomes

  • Lexical analysis
  • Parsing techniques
  • Context-Free Grammars (CFG)
  • Compiler design fundamentals
  • Syntax validation using PLY

Future Improvements

  • Symbol table implementation
  • Semantic analysis
  • Type checking
  • Support for functions and arrays
  • Intermediate code generation

About

Python-based syntax validator supporting variable declarations, expressions, conditionals, and loops.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages