Negative Vorzeichen bei VOR

This commit is contained in:
2025-10-12 22:41:13 +02:00
parent 9864c1965f
commit ec4d7dc26e
45 changed files with 76 additions and 13 deletions

View File

@ -167,6 +167,7 @@ public class StLexer {
public List<CompileError> Errors = new();
public StLexer(string s){src=s;}
char Peek()=> i<src.Length?src[i]:'\0';
char Peek2()=> i+1<src.Length?src[i+1]:'\0';
char Next(){
if (i >= src.Length) return '\0';
char c = src[i++];
@ -180,6 +181,18 @@ public class StLexer {
while (char.IsWhiteSpace(Peek())) Next();
if (Peek()=='\0') return new Token(TokType.EOF,"", currentLine);
// Skip line comments starting with '//'
if (Peek() == '/' && Peek2() == '/') {
// consume '//'
Next(); Next();
// skip until end of line or EOF
while (Peek() != '\0' && Peek() != '\n') Next();
// consume newline if present
if (Peek() == '\n') Next();
// restart tokenization after the comment
return NextToken();
}
if (char.IsLetter(Peek())||Peek()=='_'){
var sb=new StringBuilder();
int startLine = currentLine;
@ -558,6 +571,22 @@ public class StParser {
Expr? ParsePrimary(){
int startLine = cur.Line;
// Support unary + and -
if (cur.Type == TokType.PLUS || cur.Type == TokType.MINUS) {
var sign = cur.Type;
Next();
var p = ParsePrimary();
if (p == null) return null;
Expr zero;
if (p.Type == VarType.REAL || p.Type == VarType.LREAL) {
zero = new RealExpr(0.0, p.Type);
} else {
zero = new IntExpr(0, p.Type);
}
var op = sign == TokType.PLUS ? TokType.PLUS : TokType.MINUS;
return new BinaryExpr(zero, op, p);
}
switch(cur.Type) {
case TokType.INT:
if (!long.TryParse(cur.Text, out var v)) {