Skip to content

Initial Implementation of lexer#2

Open
sash070 wants to merge 27 commits intomainfrom
sash070
Open

Initial Implementation of lexer#2
sash070 wants to merge 27 commits intomainfrom
sash070

Conversation

@sash070
Copy link
Collaborator

@sash070 sash070 commented Feb 2, 2026

Implemented Lexer

  • Created separate maps for keywords, operators and delimiters
  • Added a few operators
  • Have not considered bitwise operators, other complex keywords and delimiters like {}, [], etc
  • Improved scanNumber (scientific notation, placeholder error handling)
  • Implemented indent stack (with placeholder error handling)
  • (Added vscode to .gitignore)
  • Added comments
  • Created tester for lexer
  • Modified Makefile to include tests for lexer, parser and evaluator

PS: I don't think indentation.hpp and indentation.cpp are required.

Copy link
Collaborator Author

@sash070 sash070 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basic lexer implementation except error handling and indentation stack.

@SujalKumar06
Copy link
Owner

SujalKumar06 commented Mar 1, 2026

Can you rebase and squash the commits. I will have a look at this in a while.

@SujalKumar06
Copy link
Owner

Can you rebase and squash the commits. I will have a look at this in a while.

I have done this for now. No worries !

Comment on lines +15 to +26
{"=", TokenType::ASSIGN},
{"+", TokenType::PLUS},
{"-", TokenType::MINUS},
{"*", TokenType::STAR},
{"/", TokenType::SLASH},
{"(", TokenType::LPAREN},
{")", TokenType::RPAREN},
{":", TokenType::COLON},
{",", TokenType::COMMA},
{"\n", TokenType::NEWLINE},
{"\t", TokenType::INDENT},
{" ", TokenType::SPACE}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think these are keywords?
I assume its better if we split it out before even entering keywords, I am not very sure but they don't seem to fit in the 'keywords'.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea the keywords map needs to be cleaned up. Maybe we can have another unordered map for operators and such..

tokens.push_back(token);
}

void Lexer::scanIdentifier(std::string curr){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better naming required here for curr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}
std::string curr = "";
curr += advance();
if (keywords.count(curr)){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will something else like .find or .contains be better than .count

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea you're right. I think contains() is best for C++20 and later.

@SujalKumar06 SujalKumar06 changed the title cahnge Initial Implementation of lexer Mar 2, 2026
@SujalKumar06
Copy link
Owner

@sash070

Update the PR Description properly with what is being done in this PR, you can change the title also, I have changed it to something more suitable for now.

A few more things are

  • Add comments to your code and functions, Its very tough to understand what is the function attempting to do without comments
  • Some places the flow of logic might be a little tough to follow, so please add comments if you think it can be made much clear using comments, don't add redundant ones also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants