From c40bfd0725b8231d5ae2b6c8d19abeb954ff1b3f Mon Sep 17 00:00:00 2001 From: unknown <user@mil8a-202a-02.mmcs.sfedu.ru> Date: Mon, 5 Sep 2022 13:21:54 +0300 Subject: [PATCH] IntLexer and part of IdentLexer --- Module1/Lexer.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Module1/Lexer.cs b/Module1/Lexer.cs index 4b11463..2a84012 100644 --- a/Module1/Lexer.cs +++ b/Module1/Lexer.cs @@ -68,13 +68,17 @@ namespace Lexer public override bool Parse() { NextCh(); + int sign = 1; if (currentCh == '+' || currentCh == '-') { + if (currentCh == '-') + sign *= -1; NextCh(); } if (char.IsDigit(currentCh)) { + parseResult = currentCh - '0'; NextCh(); } else @@ -84,10 +88,11 @@ namespace Lexer while (char.IsDigit(currentCh)) { + parseResult = parseResult * 10 + (currentCh - '0'); NextCh(); } - + parseResult *= sign; if (currentCharValue != -1) { Error(); @@ -114,8 +119,12 @@ namespace Lexer } public override bool Parse() - { - throw new NotImplementedException(); + { + if (builder.Length == 0) + Error(); + if (!(char.IsLetter(builder[0]) || builder[0] == '_')) + Error(); + //throw new NotImplementedException(); } } -- GitLab