Question: You will need to detect keywords. You can deduce the keywords from both the Tran documentation and the Token.java that is part of the sample

You will need to detect keywords. You can deduce the keywords from both the Tran documentation and the Token.java that is part of the sample project.
One subtle thing Tran has keywords:
accessor:
mutator:
There are a few ways to implement this in the lexer. We will choose to have those as two separate tokens. That means that we create a small bug where the lexer is more flexible than the language we will accept accessor : and mutator : as well.
Add line and character position to your lexer. Make sure that you are careful about when to increment character position. You will have to start looking for
(newline) explicitly instead of just ignoring it; spaces, too.
The SyntaxErrorException is also available on Brightspace. Make sure to replace any previous exceptions that you might have had with this exception.
Indentation is a part of Tran (like Python). Use 4 spaces as one indentation level.
Add support for quoted strings. You do not need to worry about escaped strings in Tran, but you will use them in the unit tests.
Finally comments should be ignored. This is the same idea as quoted strings, except that we dont generate a token for them. Tran uses { curly braces } for comments.
With both quoted strings and comments, a few things to consider:
1) If the file ends in the middle of either, it is a syntax error.
2) Both can span multiple lines.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!