You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Welcome to the Lexical Analyzer for a custom programming language. This project builds a lexical analyzer that converts source code into tokens using finite automata (NFA & DFA). It supports various data types, operators, keywords, and comments with well-defined regular expressions.
🚀 Features
Custom Tokenization: Converts source code into categorized tokens.
Finite Automata Implementation: Uses NFA (Thompson's construction) and DFA for efficient lexical analysis.
Symbol Table Management: Stores identifiers with scopes.
Comment Handling: Ignores single-line and multi-line comments.
Operator Recognition: Supports arithmetic and exponentiation.
📝 Language Rules
Reserved Keywords
Type
Keyword
Integer
int
Decimal
dec
Boolean
bln
Character
char
Global
mrWorld
Local
mrArea
Data Types
Integer (int)
Decimal (dec)
Boolean (bln)
Character (char)
Constraints
Only lowercase alphabets allowed for identifiers [a-z].
Comments
Type
Syntax
Single-Line
%% This is a comment
Multi-Line
`%* This is a
multi-line comment *%`
Operators
Operator
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus
^
Exponentiation
🔍 Regular Expressions
Token Patterns
Token Type
Regex
Reserved Keywords
`(int
Identifiers
[a-z][a-z0-9_]*
Integer
\d+
Decimal
\d+\.\d{1,5}
Boolean
`(true
Character
'[a-z]'
Single-line Comment
%%.*
Multi-line Comment
`%*(*(?!%)
Operators
[+\-*/%^]
Whitespace
[ \t\n]+
🛠 How It Works
Define Tokens using Regular Expressions.
Convert Regular Expressions to NFA using Thompson’s construction.
Transform NFA to DFA for faster token recognition.
Scan Input Source Code, match tokens, and generate a symbol table.
Skip Comments and Report Errors for invalid syntax.
📌 Example Code & Token Output
Sample Input (test.sui)
int x = 10
dec y = 3.14
mrWorld z = true
%* This is a multi-line comment *%
x + y ^ 2