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.
- 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-whileloop parsing- Syntax error detection and reporting
- Python
- PLY (Python Lex-Yacc)
The parser supports:
- Variable declarations
- Variable assignments
- Arithmetic expressions
if/if-elsestatementsdo-whileloops- Relational conditions
Example:
int x = 10;
float y = 20;
if (x < 20) {
x = x + 1;
}
do {
x = x + 1;
} while (x < 30);.
├── lexer.py # Lexical analyzer
├── parser.py # Grammar rules and parser
├── input.txt # Sample input program
└── README.md
- The lexer scans the source code and converts it into tokens.
- The parser processes the token stream using Context-Free Grammar rules.
- Valid programs are accepted by the parser.
- Invalid syntax is detected and reported with descriptive error messages.
- Lexical analysis
- Parsing techniques
- Context-Free Grammars (CFG)
- Compiler design fundamentals
- Syntax validation using PLY
- Symbol table implementation
- Semantic analysis
- Type checking
- Support for functions and arrays
- Intermediate code generation