Disammbler und Simulator angepasst. Arrays begonnen (defunct)

This commit is contained in:
2025-10-13 12:09:15 +02:00
parent 3cb6373915
commit 74f256efb2
50 changed files with 534 additions and 75 deletions

View File

@ -13,6 +13,7 @@ public enum TokType {
WHILE, DO, END_WHILE,
FOR, TO, BY, END_FOR,
PROGRAM, VAR, END_VAR, END_PROGRAM,
ARRAY, OF, LBRACKET, RBRACKET, DOTS,
EOF
}
@ -83,6 +84,8 @@ public class StLexer {
"TO"=>new Token(TokType.TO,s,startLine),
"BY"=>new Token(TokType.BY,s,startLine),
"END_FOR"=>new Token(TokType.END_FOR,s,startLine),
"ARRAY"=>new Token(TokType.ARRAY,s,startLine),
"OF"=>new Token(TokType.OF,s,startLine),
_=>new Token(TokType.IDENT,s,startLine)
};
}
@ -92,16 +95,23 @@ public class StLexer {
int startLine = currentLine;
bool isFloat = false;
// Ganze Zahl vor dem Dezimalpunkt
// Ganze Zahl vor dem Dezimalpunkt oder Bereichsoperator
while(char.IsDigit(Peek()))
sb.Append(Next());
// Optional: Dezimalpunkt und Nachkommastellen
// Prüfe auf Bereichsoperator (..) oder Dezimalpunkt (.)
if (Peek() == '.') {
isFloat = true;
sb.Append(Next());
while(char.IsDigit(Peek()))
if (Peek2() == '.') {
// Es ist ein Bereichsoperator (..)
// Don't consume the dots, just return the number
return new Token(TokType.INT, sb.ToString(), startLine);
} else {
// Es ist ein Dezimalpunkt
isFloat = true;
sb.Append(Next());
while(char.IsDigit(Peek()))
sb.Append(Next());
}
}
// Optional: Exponentialdarstellung
@ -150,10 +160,21 @@ public class StLexer {
if (c == ';') return new Token(TokType.SEMI,";",tokenLine);
if (c == '(') return new Token(TokType.LPAREN,"(",tokenLine);
if (c == ')') return new Token(TokType.RPAREN,")",tokenLine);
if (c == '[') return new Token(TokType.LBRACKET,"[",tokenLine);
if (c == ']') return new Token(TokType.RBRACKET,"]",tokenLine);
if (c == '+') return new Token(TokType.PLUS,"+",tokenLine);
if (c == '-') return new Token(TokType.MINUS,"-",tokenLine);
if (c == '*') return new Token(TokType.MUL,"*",tokenLine);
if (c == '/') return new Token(TokType.DIV,"/",tokenLine);
if (c == '.') {
if (Peek() == '.') {
Next();
return new Token(TokType.DOTS,"..",tokenLine);
}
// Put back the dot for floating point numbers
i--;
return NextToken();
}
AddError($"Unexpected character '{c}'");
return new Token(TokType.EOF,"",tokenLine); // Skip invalid character