diff --git a/Module1/Lexer.cs b/Module1/Lexer.cs index 4b1146367f9e97ec612e3335bcfc6f6d3de3132a..ce470f05b40597135f1b1c84df44b61f719cec5f 100644 --- a/Module1/Lexer.cs +++ b/Module1/Lexer.cs @@ -68,13 +68,18 @@ namespace Lexer public override bool Parse() { NextCh(); + int res = 0; // тут будем собирать число + int sign = 1; // знак числа if (currentCh == '+' || currentCh == '-') { + if (currentCh == '-') + sign = -1; NextCh(); } if (char.IsDigit(currentCh)) { + res = currentCh - '0'; NextCh(); } else @@ -84,6 +89,7 @@ namespace Lexer while (char.IsDigit(currentCh)) { + res = res * 10 + currentCh - '0'; NextCh(); } @@ -93,6 +99,8 @@ namespace Lexer Error(); } + this.parseResult = res * sign; + return true; } @@ -113,10 +121,40 @@ namespace Lexer builder = new StringBuilder(); } - public override bool Parse() - { - throw new NotImplementedException(); - } + public override bool Parse() + { + NextCh(); + + if (currentCharValue != -1) + { + Error(); + } + + var builder1 = new StringBuilder(); + + if (char.IsLetter(currentCh) || currentCh == '_') + { + builder1.Append(currentCh); + NextCh(); + } + else + Error(); + + while (char.IsDigit(currentCh) || char.IsLetter(currentCh) || currentCh == '_') + { + builder1.Append(currentCh); + NextCh(); + } + + if (currentCharValue != -1) + { + Error(); + } + + parseResult = builder1.ToString(); + + return true; + } }