Loading page…
Token definitions, regex patterns, DFA construction, and the lexer pipeline.
| Token | Regex Pattern | Description |
|---|---|---|
| Keyword | `(if|else|while|for|return|int|void|struct)` | Reserved words |
| Identifier | `[a-zA-Z_][a-zA-Z0-9_]*` | Variable/function names |
| Integer | `[0-9]+` | Decimal integer literal |
| Float | `[0-9]+\.[0-9]*` | Floating-point literal |
| String | `"[^"]*"` | String literal |
| Operator | `[+\-*/%=<>!&|^~]` | Binary/unary operators |
| Punctuation | `[(){}\[\],;]` | Grouping and separator |
| Whitespace | `[ \t\n\r]+` | Ignored (not tokenized) |
| Comment | `//.*` or `/\*(.|\n)*?\*/` | Single/multi-line |
(type, lexeme, line, col) tuples.| Aspect | Lex/Flex | Hand-Written |
|---|---|---|
| Speed | Good | Better (control) |
| Readability | Regex rules | C code (verbose) |
| Error messages | Generic | Custom semantic errors |
| Lookahead | 1-char (flex) | Arbitrary (custom) |
| Maintainability | Easy to modify regex | Harder to change rules |
a.