A custom programming language lexical analyzer built with Flex (Lex). PAW uses creative command names and syntax for a unique programming experience.
This project implements a lexical analyzer for the PAW programming language, a custom language with unique keywords and syntax patterns. The analyzer tokenizes source code and identifies different token types including keywords, identifiers, literals, operators, and delimiters.
- pawlang.l - Main Lex specification file for the PAW language lexer
- count.l - Additional Lex specification (utility lexer)
- lex.yy.c - Generated C code from Lex compilation
- input.txt - Sample PAW program for testing
- output.txt - Output from lexical analysis
- command.txt - Build and run commands
- Flex (Lex compiler)
- GCC (C compiler)
# Compile the PAW language lexer
flex pawlang.l
gcc lex.yy.c -o pawlang
.\pawlang
# Compile the counter lexer
flex count.l
.\count| PAW Keyword | Meaning | Example |
|---|---|---|
var |
Variable | var x = 10 |
const |
Constant | const g = 9.8 |
fun |
Function | fun main() {} |
iff |
If statement | iff (x > 5) {} |
eliff |
Else if | eliff (x < 5) {} |
neo |
Else | neo {} |
run |
For loop | run (var i = 0 \ i < 10 \ i++) |
when |
While loop | when (condition) {} |
show |
Print/Output | show "text" |
pay |
Return | pay value |
arr |
Array | arr numbers = {1, 2, 3} |
offja |
Break | offja |
skip |
Continue | skip |
turu |
True | turu |
vugi |
False | vugi |
nil |
Null | nil |
chk |
Try | chk {} |
caught |
Catch | caught {} |
staple |
Main function | fun staple() {} |
take |
Scanf/Input | take x |
proin |
Include | proin library |
- INTEGER - Numeric literals:
123,456 - FLOAT - Decimal numbers:
9.8,3.14 - STRING - Double-quoted text:
"hello world" - VSTRING - Variable string (with interpolation):
'hello {name}'
- OPERATOR - Arithmetic and logical:
+ - * / = < > ! & | - DELIMITER - Brackets and separators:
, ( ) [ ] { } \
- Single-line:
// comment - Multi-line:
/* comment */
The lexer produces output in the format:
token_type -> matched_text
Example output:
funtion -> fun
variable -> var
INTEGER -> 100
OPERATOR -> =
IDENTIFIER -> x
See input.txt for a sample PAW program demonstrating language features:
- Variable and constant declarations
- Array creation
- Conditional statements (if/else if/else)
- Loop construction
- String output with variable interpolation
The lexer uses Flex regex patterns to:
- Match language keywords to token types
- Identify identifiers and literals
- Recognize operators and delimiters
- Handle comments (single and multi-line)
- Report unrecognized symbols
Run the compiled program to analyze PAW source files and produce tokenized output showing the lexical analysis results.