Menu

[r4]: / Basic-Debugger / Debugger.cs  Maximize  Restore  History

Download this file

92 lines (78 with data), 3.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;
namespace Basic_Debugger
{
public class Debugger
{
public Debugger(BasicProject project)
{
_project = project;
}
BasicProject _project;
Regex r;
public bool Check(out int[] errorLines)
{
List<int> errors = new List<int>();
string[] lines = _project.Code.MainCode.Split("\n".ToCharArray());
for (int I = 0; I < lines.Length; I++)
{
string[] words = lines[I].Split(" ".ToCharArray());
if (words.Length > 0)
{
if (!CheckLine(lines[I], words[0]))
errors.Add(I);
}
}
errorLines = new int[errors.Count];
for (int I = 0; I < errors.Count; I++)
errorLines[I] = errors[I];
if (errors.Count > 0)
return false;
return true;
}
private bool CheckLine(string line, string command)
{
switch (command.ToUpper())
{
case "PRINT":
r = new Regex("^PRINT\\s*" +
"(?:(?<text>(?:\\-?(?:[a-zA-Z0-9]+[$%]|\\d)(?:\\s*[\\+\\-\\*\\/]\\s*(?:[a-zA-Z0-9]+[$%]|\\d+))*))" +
"|\\\"(?<text>[^\"]*?)\\\")?" +
"(?:\\s*[,;]\\s*" +
"(?:(?<text>(?:\\-?(?:[a-zA-Z0-9]+[$%]|\\d)(?:\\s*[\\+\\-\\*\\/]\\s*(?:[a-zA-Z0-9]+[$%]|\\d+))*))" +
"|\\\"(?<text>[^\"]*?)\\\"))*\\s*(?:'.*)?$");
return r.IsMatch(line);
case "INPUT":
r = new Regex("^INPUT\\s\".*\"\\s*[,;]\\s*[a-zA-Z0-9]*[$%](\\s*'.*)?$");
return r.IsMatch(line);
case "SLEEP":
r = new Regex("^SLEEP(\\s*'.*)?$");
return r.IsMatch(line);
case "REM":
return true;
case "'":
return true;
default:
r = new Regex("^[a-zA-Z0-9]+[%]\\s*\\=\\s*" + "(?<math>\\-?[a-zA-Z0-9]+[%]|\\d)(?<math>\\s*[\\+\\-\\*\\/]\\s*(?:[a-zA-Z0-9]+[%]|\\d+))*");
if (r.IsMatch(line))
return true;
r = new Regex( "^[a-zA-Z0-9]+[$]\\s*\\=\\s*" +
"(?:(?<text>(?:\\-?(?:[a-zA-Z0-9]+[$%]|\\d)(?:\\s*[\\+\\-\\*\\/]\\s*(?:[a-zA-Z0-9]+[$%]|\\d+))*))" +
"|\\\"(?<text>.*?)\\\")?" +
"(?:\\s*[\\+]\\s*" +
"(?:(?<text>(?:\\-?(?:[a-zA-Z0-9]+[$%]|\\d)(?:\\\\s*[\\+\\-\\\\*\\/]\\s*(?:[a-zA-Z0-9]+[$%]|\\d+))*))" +
"|\\\"(?<text>.*?)\\\"))*\\s*(?:'.*)?$(\\\\s*'.*)?");
if (r.IsMatch(line))
return true;
return false;
}
}
public bool Debug(out int errorline, DoWorkEventArgs e)
{
return RunQBasic.RunCode(_project, out errorline, e);
}
}
}
MongoDB Logo MongoDB