Skip to content

Commit

Permalink
Add 0b and 0x numbers, fix do while loops, fix ctrl+s sometimes addin…
Browse files Browse the repository at this point in the history
…g text to textbox, better error handling for numbers
  • Loading branch information
PocketMiner82 committed Feb 12, 2024
1 parent 5f532c8 commit a759e7c
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AutoUpdater.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.2.0.1</version>
<version>1.2.1.0</version>
<url>https://github.com/PocketMiner82/pseudocode-ide/releases/latest/download/pseudocode-ide.zip</url>
<changelog>https://github.com/PocketMiner82/pseudocode-ide/releases</changelog>
<mandatory>false</mandatory>
Expand Down
4 changes: 2 additions & 2 deletions SolutionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;

[assembly: AssemblyVersion("1.2.0.1")]
[assembly: AssemblyFileVersion("1.2.0.1")]
[assembly: AssemblyVersion("1.2.1.0")]
[assembly: AssemblyFileVersion("1.2.1.0")]
4 changes: 2 additions & 2 deletions pseudocodeIde/PseudocodeIDEForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ private void codeTextBox_TextChanged(object sender, EventArgs e)

private void codeTextBox_KeyDown(object sender, KeyEventArgs e)
{
// ignore CTRL[+SHIFT]+(Z/Y/L/R/E)
if ((e.KeyCode == Keys.Z || e.KeyCode == Keys.Y || e.KeyCode == Keys.L || e.KeyCode == Keys.R || e.KeyCode == Keys.E)
// ignore CTRL[+SHIFT]+(Z/Y/L/R/E/S)
if ((e.KeyCode == Keys.Z || e.KeyCode == Keys.Y || e.KeyCode == Keys.L || e.KeyCode == Keys.R || e.KeyCode == Keys.E || e.KeyCode == Keys.S)
&& (Control.ModifierKeys == Keys.Control || Control.ModifierKeys == (Keys.Control | Keys.Shift)))
{
e.SuppressKeyPress = true;
Expand Down
2 changes: 1 addition & 1 deletion pseudocodeIde/interpreter/parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private string handleDoWhile()
do
{
this.advance();
output += this.parseToken(output.LastOrDefault(), true);
output += this.parseToken(output.LastOrDefault());
currentToken = this.peek();
}
while (!this.isAtEnd() && currentToken.type != WHILE);
Expand Down
63 changes: 55 additions & 8 deletions pseudocodeIde/interpreter/scanner/Scanner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using pseudocodeIde.interpreter.logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using static pseudocodeIde.interpreter.TokenType;

namespace pseudocodeIde.interpreter
Expand Down Expand Up @@ -184,17 +186,24 @@ private void scanToken()
case '\'': this.handleChar(); break;

default:
if (this.isDigit(c))
try
{
this.handleNumber();
}
else if (this.isAlpha(c))
{
this.handleIdentifier();
if (this.isDigit(c))
{
this.handleNumber();
}
else if (this.isAlpha(c))
{
this.handleIdentifier();
}
else
{
Logger.error(this.line, $"Unerwartetes Zeichen: '{c}'.");
}
}
else
catch (Exception e)
{
Logger.error(this.line, $"Unerwartetes Zeichen: '{c}'.");
Logger.error(this.line, $"Unerwartete Zeichen nach '{c}'. {e.GetType().Name}: {e.Message}");
}
break;
}
Expand Down Expand Up @@ -286,6 +295,32 @@ private void handleNumber()
this.advance();
}
}
else if (this.peek() == 'x' && this.isHexDigit(this.peekNext()))
{
// consume the 'x'
this.advance();

while (this.isHexDigit(this.peek()))
{
this.advance();
}
// start + 2 because the '0x' must be removed
this.addToken(NUMBER, Convert.ToInt32(this.code.Substring(this.start + 2, this.current - this.start), 16));
return;
}
else if (this.peek() == 'b' && this.isBinaryDigit(this.peekNext()))
{
// consume the 'b'
this.advance();

while (this.isBinaryDigit(this.peek()))
{
this.advance();
}
// start + 2 because the '0b' must be removed
this.addToken(NUMBER, Convert.ToInt32(this.code.Substring(this.start, this.current - this.start).Substring(2), 2));
return;
}

this.addToken(NUMBER, double.Parse(this.code.Substring(this.start, this.current - this.start)));
}
Expand Down Expand Up @@ -394,6 +429,18 @@ private bool isDigit(char c)
return c >= '0' && c <= '9';
}

private bool isHexDigit(char c)
{
return isDigit(c) ||
(c >= 'a' && c <= 'f') ||
(c >= 'A' && c <= 'F');
}

private bool isBinaryDigit(char c)
{
return c == '0' || c == '1';
}

private bool isAlpha(char c)
{
return (c >= 'a' && c <= 'z') ||
Expand Down

0 comments on commit a759e7c

Please sign in to comment.