Skip to content

Commit

Permalink
Add support for true/false keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Feb 4, 2022
1 parent fc07b10 commit 3b4a8c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions EOBot/Interpreter/BotTokenParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ public sealed class BotTokenParser : IDisposable
{
"if",
"while",
"goto"
"goto",
"else",
};

private static readonly HashSet<string> Literals = new HashSet<string>
{
"true",
"false"
};

private readonly StreamReader _inputStream;
Expand Down Expand Up @@ -91,7 +98,9 @@ public BotToken GetNextToken()

var type = Keywords.Contains(identifier)
? BotTokenType.Keyword
: BotTokenType.Identifier;
: Literals.Contains(identifier)
? BotTokenType.Literal
: BotTokenType.Identifier;

return Token(type, identifier);
}
Expand Down Expand Up @@ -141,7 +150,7 @@ public BotToken GetNextToken()
{
var nextChar = Read();
if (nextChar != '=')
return Token(BotTokenType.Error, inputChar.ToString() + nextChar);
return Token(BotTokenType.NotOperator, inputChar.ToString() + nextChar);
return Token(BotTokenType.NotEqualOperator, inputChar.ToString() + nextChar);
}
case '>':
Expand Down
1 change: 1 addition & 0 deletions EOBot/Interpreter/BotTokenType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum BotTokenType
MinusOperator,
MultiplyOperator,
DivideOperator,
NotOperator,
Dot,
NewLine,
Error,
Expand Down

0 comments on commit 3b4a8c3

Please sign in to comment.