K# Lexical Analyzer (K# Lexer) — Group 2
The K# Lexer is a custom-built lexical analyzer created in the C programming language as part of our Principles of Programming Languages project.
It reads a source file written in our proposed language K#, scans characters using Deterministic Finite Automata (DFAs), classifies code into tokens, and outputs a clean SymbolTable.txt containing every token with its corresponding classification.
What the K# Lexer Does The lexer performs the following major functions:
- Reads a .ksh Source File It only accepts files ending in .ksh. Any other file type results in an error.
- Converts Raw Text Into Tokens
It identifies and classifies lexemes into categories:
Keywords Identifiers Reserved Types Numeric Constants (int, float) Boolean Constants (true/false) Character Literals String Literals Noise Words (ignored words like please, of, then…) Operators (arithmetic, logical, relational, assignment) Delimiters (; , . :) Brackets (() [] {}) Comments (//, /* */) Unknown / Invalid symbols
- Ignores Whitespace and Comments Whitespace and comments are treated as boundaries—not tokens.
- Writes a Formatted Symbol Table
K# SEMANTIC ANALYZER (Additional Points)
- This file is just a demo of simple semantic checks.
How it works:
- Reads SymbolTable.txt (output of the lexer).
- Rebuilds a list of tokens (lexeme + token-type string).
- Builds a symbol table of variables from declarations: ;
- Checks:
- duplicate declarations
- type mismatch in simple assignments: identifier = value ;
Limitations:
- Very small grammar: only handles straight declarations and assignments.
- No full parsing, no scopes, no functions, no arrays.
- This is for demonstration, not for your project grade.