Commit adcd5bfe authored by Alexander Dietsch's avatar Alexander Dietsch

- small bugfixes

- new Pre-execution command #IMPORT: import all macros from another piece
  of code to use in your own code
- Log window should flicker less now
parent 0ba079d8
......@@ -11,6 +11,13 @@ namespace LWSimulatorGUI
{
class CustomRichTextBox : RichTextBox
{
private bool onUnix = false;
internal void setOnUnix(bool onUnix)
{
this.onUnix = onUnix;
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Tab)
......@@ -20,6 +27,19 @@ namespace LWSimulatorGUI
return true;
}
if (keyData == Keys.Enter && !onUnix)
{
SelectionLength = 0;
int countSpaces = 0;
string line = "";
if(Lines.Length > 0)
line = Lines[GetLineFromCharIndex(SelectionStart)];
while (countSpaces < line.Length && line[countSpaces] == ' ')
countSpaces++;
SelectedText = "\n" + new string(' ', countSpaces);
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
......
......@@ -10,24 +10,63 @@ namespace LWSimulatorGUI
{
public class DoubleBufferedListBox : ListBox
{
/*
* Code by http://yacsharpblog.blogspot.de/2008/07/listbox-flicker.html
*/
public DoubleBufferedListBox()
{
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
{
this.SetStyle(
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.UserPaint,
true);
this.DrawMode = DrawMode.OwnerDrawFixed;
this.DoubleBuffered = true;
}
/*
protected override void OnPaint(PaintEventArgs pe)
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (this.Items.Count > 0)
{
e.DrawBackground();
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, new SolidBrush(this.ForeColor), new PointF(e.Bounds.X, e.Bounds.Y));
}
base.OnDrawItem(e);
}
protected override void OnPaint(PaintEventArgs e)
{
// we draw the progressbar normally with
// the flags sets to our settings
base.OnPaintBackground(pe);
base.OnPaint(pe);
Region iRegion = new Region(e.ClipRectangle);
e.Graphics.FillRegion(new SolidBrush(this.BackColor), iRegion);
if (this.Items.Count > 0)
{
for (int i = 0; i < this.Items.Count; ++i)
{
System.Drawing.Rectangle irect = this.GetItemRectangle(i);
if (e.ClipRectangle.IntersectsWith(irect))
{
if ((this.SelectionMode == SelectionMode.One && this.SelectedIndex == i)
|| (this.SelectionMode == SelectionMode.MultiSimple && this.SelectedIndices.Contains(i))
|| (this.SelectionMode == SelectionMode.MultiExtended && this.SelectedIndices.Contains(i)))
{
OnDrawItem(new DrawItemEventArgs(e.Graphics, this.Font,
irect, i,
DrawItemState.Selected, this.ForeColor,
this.BackColor));
}
else
{
OnDrawItem(new DrawItemEventArgs(e.Graphics, this.Font,
irect, i,
DrawItemState.Default, this.ForeColor,
this.BackColor));
}
iRegion.Complement(irect);
}
}
}
base.OnPaint(e);
}
*/
}
}
namespace LWSimulatorGUI
using System.Windows.Forms;
namespace LWSimulatorGUI
{
partial class LogWindow
{
......@@ -34,6 +36,7 @@
this.exportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clearToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.btLogOk = new System.Windows.Forms.Button();
this.lBLog = new LWSimulatorGUI.DoubleBufferedListBox();
this.mSLogMenu.SuspendLayout();
this.SuspendLayout();
//
......@@ -59,14 +62,14 @@
// exportToolStripMenuItem
//
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
this.exportToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.exportToolStripMenuItem.Size = new System.Drawing.Size(107, 22);
this.exportToolStripMenuItem.Text = "Export";
this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click);
//
// clearToolStripMenuItem
//
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
this.clearToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.clearToolStripMenuItem.Size = new System.Drawing.Size(107, 22);
this.clearToolStripMenuItem.Text = "Clear";
this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
//
......@@ -81,6 +84,21 @@
this.btLogOk.UseVisualStyleBackColor = true;
this.btLogOk.Click += new System.EventHandler(this.btLogOk_Click);
//
// lBLog
//
this.lBLog.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lBLog.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.lBLog.FormattingEnabled = true;
this.lBLog.HorizontalScrollbar = true;
this.lBLog.Location = new System.Drawing.Point(13, 28);
this.lBLog.Name = "lBLog";
this.lBLog.SelectionMode = System.Windows.Forms.SelectionMode.None;
this.lBLog.Size = new System.Drawing.Size(343, 238);
this.lBLog.TabIndex = 1;
this.lBLog.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.lBlog_DrawItem);
//
// LogWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
......@@ -88,10 +106,10 @@
this.ClientSize = new System.Drawing.Size(368, 313);
this.Controls.Add(this.btLogOk);
this.Controls.Add(this.mSLogMenu);
this.Controls.Add(this.lBLog);
this.DoubleBuffered = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.mSLogMenu;
this.MaximizeBox = false;
this.Name = "LogWindow";
this.Text = "Log";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.LogWindow_FormClosing);
......@@ -107,7 +125,7 @@
private System.Windows.Forms.MenuStrip mSLogMenu;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exportToolStripMenuItem;
private System.Windows.Forms.ListBox lBLog;
private LWSimulatorGUI.DoubleBufferedListBox lBLog;
private System.Windows.Forms.Button btLogOk;
private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem;
}
......
......@@ -21,24 +21,7 @@ namespace LWSimulatorGUI
public LogWindow(MainGUI parent, LWCoordinator simul)
{
InitializeComponent();
//
// lBLog
//
this.lBLog = new LWSimulatorGUI.DoubleBufferedListBox();
this.lBLog.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lBLog.FormattingEnabled = true;
this.lBLog.Location = new System.Drawing.Point(13, 28);
this.lBLog.Name = "lBLog";
this.lBLog.SelectionMode = System.Windows.Forms.SelectionMode.None;
this.lBLog.Size = new System.Drawing.Size(343, 238);
this.lBLog.TabIndex = 1;
this.lBLog.DrawMode = DrawMode.OwnerDrawFixed;
this.lBLog.DrawItem += lBlog_DrawItem;
this.Controls.Add(this.lBLog);
this.PerformLayout();
//this.lBLog.DrawMode = DrawMode.OwnerDrawFixed;
this.parent = parent;
simulator = simul;
simulator.setLogFuncs(addLine_Notify, newRun, saveLog);
......@@ -84,7 +67,6 @@ namespace LWSimulatorGUI
else
textBrush = lBlogTextNormalBrush;
g.DrawString(text, e.Font, textBrush, lBLog.GetItemRectangle(index).Location);
}
e.DrawFocusRectangle();
......
......@@ -52,7 +52,6 @@
this.projectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.runProgramToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.enableBreakpointsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showTransitionFunctionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.displayLogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.registersToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.insertRegistersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
......@@ -246,7 +245,6 @@
this.projectToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.runProgramToolStripMenuItem,
this.enableBreakpointsToolStripMenuItem,
this.showTransitionFunctionToolStripMenuItem,
this.displayLogToolStripMenuItem});
this.projectToolStripMenuItem.Name = "projectToolStripMenuItem";
this.projectToolStripMenuItem.Size = new System.Drawing.Size(56, 20);
......@@ -256,7 +254,7 @@
//
this.runProgramToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("runProgramToolStripMenuItem.Image")));
this.runProgramToolStripMenuItem.Name = "runProgramToolStripMenuItem";
this.runProgramToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.runProgramToolStripMenuItem.Size = new System.Drawing.Size(174, 22);
this.runProgramToolStripMenuItem.Text = "Run Program";
this.runProgramToolStripMenuItem.Click += new System.EventHandler(this.tSBRun_Click);
//
......@@ -267,20 +265,13 @@
this.enableBreakpointsToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.enableBreakpointsToolStripMenuItem.Enabled = false;
this.enableBreakpointsToolStripMenuItem.Name = "enableBreakpointsToolStripMenuItem";
this.enableBreakpointsToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.enableBreakpointsToolStripMenuItem.Size = new System.Drawing.Size(174, 22);
this.enableBreakpointsToolStripMenuItem.Text = "Enable Breakpoints";
//
// showTransitionFunctionToolStripMenuItem
//
this.showTransitionFunctionToolStripMenuItem.Enabled = false;
this.showTransitionFunctionToolStripMenuItem.Name = "showTransitionFunctionToolStripMenuItem";
this.showTransitionFunctionToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.showTransitionFunctionToolStripMenuItem.Text = "Show Transition Function";
//
// displayLogToolStripMenuItem
//
this.displayLogToolStripMenuItem.Name = "displayLogToolStripMenuItem";
this.displayLogToolStripMenuItem.Size = new System.Drawing.Size(209, 22);
this.displayLogToolStripMenuItem.Size = new System.Drawing.Size(174, 22);
this.displayLogToolStripMenuItem.Text = "Display Log";
this.displayLogToolStripMenuItem.Click += new System.EventHandler(this.displayLogToolStripMenuItem_Click);
//
......@@ -632,7 +623,6 @@
private System.Windows.Forms.ToolStripMenuItem projectToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem runProgramToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem enableBreakpointsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem showTransitionFunctionToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem displayLogToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem registersToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem insertRegistersToolStripMenuItem;
......
......@@ -43,8 +43,8 @@ namespace LWSimulatorGUI
@"((a|i|o|x)(0|[1-9]([0-9])*))", //registers
@"(?<=(\s)|^)(def|enddef|do|loop|while|as)(?=(\s|$))", //commands ending with whitespace
@"(?<=(\s)|^)(in|out|aux)(?=(\s|:))", //commands ending with whitespace or colon
@"(?<=(\s)|^)end(?=(\s|;))", //commands ending with whitespace or semicolon
@"((?<=(\s|\())|^)(pred|succ)(?=(\s|\())", //commands ending with whitespace or bracket
@"(?<=(\s)|^)end(?=(\s|;|$))", //commands ending with whitespace or semicolon
@"((?<=(\s|\())|^)(pred|succ)(?=(\s|\())", //commands ending with whitespace or bracket
@"#[A-Z]+", //Preprocessor commands
};
......@@ -77,6 +77,7 @@ namespace LWSimulatorGUI
if (platform == 4 || platform == 6 || platform == 128)
onUnix = true;
InitializeComponent();
fCTBProgram.setOnUnix(onUnix);
// Remove ugly selection colors (usually cell has blue background => cell is selected)
/*this.dGVRegisters.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
this.dGVRegisters.DefaultCellStyle.SelectionForeColor = SystemColors.HighlightText;*/
......@@ -370,7 +371,7 @@ namespace LWSimulatorGUI
if (res == DialogResult.Yes)
{
saveFile();
saveFile(currentFilePath);
return true;
}
return false;
......@@ -858,7 +859,7 @@ namespace LWSimulatorGUI
dGVRegisters.CurrentCell = null;
dGVRegisters.Columns[1].ReadOnly = true; // Prevent deadlocks by calling this here.
}
simulator.runProgram(fCTBProgram.Text);
simulator.runProgram(fCTBProgram.Text, currentFilePath);
failSafeTimer = new System.Timers.Timer(100);
failSafeTimer.Elapsed += FailSafeTimer_Elapsed;
failSafeTimer.Enabled = true;
......@@ -896,7 +897,7 @@ namespace LWSimulatorGUI
dGVRegisters.CurrentCell = null; // Workaround to validate cell even if run is pressed
dGVRegisters.Columns[1].ReadOnly = true; // Prevent deadlocks by calling this here.
}
simulator.singleStepProgram(fCTBProgram.Text);
simulator.singleStepProgram(fCTBProgram.Text, currentFilePath);
failSafeTimer = new System.Timers.Timer(100);
failSafeTimer.Elapsed += FailSafeTimer_Elapsed;
failSafeTimer.Enabled = true;
......
......@@ -85,7 +85,7 @@
this.pPreferences.Controls.Add(this.gBRegisters);
this.pPreferences.Location = new System.Drawing.Point(13, 13);
this.pPreferences.Name = "pPreferences";
this.pPreferences.Size = new System.Drawing.Size(436, 385);
this.pPreferences.Size = new System.Drawing.Size(439, 395);
this.pPreferences.TabIndex = 0;
//
// gBEditor
......@@ -93,7 +93,7 @@
this.gBEditor.Controls.Add(this.chBHighlight);
this.gBEditor.Location = new System.Drawing.Point(4, 331);
this.gBEditor.Name = "gBEditor";
this.gBEditor.Size = new System.Drawing.Size(427, 47);
this.gBEditor.Size = new System.Drawing.Size(427, 59);
this.gBEditor.TabIndex = 3;
this.gBEditor.TabStop = false;
this.gBEditor.Text = "Texteditor";
......@@ -103,10 +103,10 @@
this.chBHighlight.AutoSize = true;
this.chBHighlight.Location = new System.Drawing.Point(10, 19);
this.chBHighlight.Name = "chBHighlight";
this.chBHighlight.Size = new System.Drawing.Size(421, 17);
this.chBHighlight.Size = new System.Drawing.Size(473, 17);
this.chBHighlight.TabIndex = 8;
this.chBHighlight.Text = "Highlight code after 2 seconds of no input (currently not supported on Unix Syste" +
"ms)";
this.chBHighlight.Text = "Highlight code after 2 seconds of no input \n(may cause unexpected behaviour on Uni" +
"x Systems)";
this.chBHighlight.UseVisualStyleBackColor = true;
//
// gBSimulation
......@@ -408,7 +408,7 @@
// bPrefCancel
//
this.bPrefCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bPrefCancel.Location = new System.Drawing.Point(374, 404);
this.bPrefCancel.Location = new System.Drawing.Point(377, 414);
this.bPrefCancel.Name = "bPrefCancel";
this.bPrefCancel.Size = new System.Drawing.Size(75, 23);
this.bPrefCancel.TabIndex = 2;
......@@ -419,7 +419,7 @@
// bPrefOK
//
this.bPrefOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.bPrefOK.Location = new System.Drawing.Point(293, 404);
this.bPrefOK.Location = new System.Drawing.Point(296, 414);
this.bPrefOK.Name = "bPrefOK";
this.bPrefOK.Size = new System.Drawing.Size(75, 23);
this.bPrefOK.TabIndex = 3;
......@@ -435,7 +435,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(461, 439);
this.ClientSize = new System.Drawing.Size(464, 449);
this.Controls.Add(this.bPrefOK);
this.Controls.Add(this.bPrefCancel);
this.Controls.Add(this.pPreferences);
......
This diff is collapsed.
This diff is collapsed.
......@@ -60,6 +60,7 @@ namespace MainLWSimulator
}
}
defVal = newDefVal;
parent.performRegisterUpdate();
return true;
}
......@@ -85,7 +86,14 @@ namespace MainLWSimulator
}
if (registers.Count < newSize)
{
registers.InsertRange(oldCount, Enumerable.Repeat<long>(0, newSize - oldCount).ToList());
if (parent.onUnix)
for(int i = oldCount; i < newSize; i++)
{
registers.Insert(i, defVal);
registers[i] = defVal;
}
else
registers.InsertRange(oldCount, Enumerable.Repeat<long>(defVal, newSize - oldCount).ToList());
updateRange(oldCount, newSize - oldCount);
changed = true;
}
......
......@@ -170,8 +170,8 @@ namespace TinyPG
case TokenType.Start:
Value = EvalStart(tree, paramlist);
break;
case TokenType.PreProcDef:
Value = EvalPreProcDef(tree, paramlist);
case TokenType.PreExecComs:
Value = EvalPreExecComs(tree, paramlist);
break;
case TokenType.MacroDef:
Value = EvalMacroDef(tree, paramlist);
......@@ -285,7 +285,7 @@ namespace TinyPG
return "Could not interpret input; no semantics implemented.";
}
protected virtual object EvalPreProcDef(ParseTree tree, params object[] paramlist)
protected virtual object EvalPreExecComs(ParseTree tree, params object[] paramlist)
{
throw new NotImplementedException();
}
......
......@@ -53,11 +53,12 @@ namespace TinyPG
}
tok = scanner.LookAhead(TokenType.PREPROCESSORCOM);
while (tok.Type == TokenType.PREPROCESSORCOM)
tok = scanner.LookAhead(TokenType.PRE_EXEC_COMS_INT, TokenType.PRE_EXEC_COMS_STRING);
while (tok.Type == TokenType.PRE_EXEC_COMS_INT
|| tok.Type == TokenType.PRE_EXEC_COMS_STRING)
{
ParsePreProcDef(node);
tok = scanner.LookAhead(TokenType.PREPROCESSORCOM);
ParsePreExecComs(node);
tok = scanner.LookAhead(TokenType.PRE_EXEC_COMS_INT, TokenType.PRE_EXEC_COMS_STRING);
}
......@@ -91,36 +92,63 @@ namespace TinyPG
parent.Token.UpdateRange(node.Token);
}
private void ParsePreProcDef(ParseNode parent)
private void ParsePreExecComs(ParseNode parent)
{
Token tok;
ParseNode n;
ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.PreProcDef), "PreProcDef");
ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.PreExecComs), "PreExecComs");
parent.Nodes.Add(node);
tok = scanner.LookAhead(TokenType.PRE_EXEC_COMS_INT, TokenType.PRE_EXEC_COMS_STRING);
switch (tok.Type)
{
case TokenType.PRE_EXEC_COMS_INT:
tok = scanner.Scan(TokenType.PREPROCESSORCOM);
n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok);
node.Nodes.Add(n);
if (tok.Type != TokenType.PREPROCESSORCOM) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.PREPROCESSORCOM.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return;
}
tok = scanner.Scan(TokenType.PRE_EXEC_COMS_INT);
n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok);
node.Nodes.Add(n);
if (tok.Type != TokenType.PRE_EXEC_COMS_INT) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.PRE_EXEC_COMS_INT.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return;
}
tok = scanner.LookAhead(TokenType.INTEGER);
if (tok.Type == TokenType.INTEGER)
{
tok = scanner.Scan(TokenType.INTEGER);
n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok);
node.Nodes.Add(n);
if (tok.Type != TokenType.INTEGER) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.INTEGER.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return;
}
tok = scanner.Scan(TokenType.INTEGER);
n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok);
node.Nodes.Add(n);
if (tok.Type != TokenType.INTEGER) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.INTEGER.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return;
}
break;
case TokenType.PRE_EXEC_COMS_STRING:
tok = scanner.Scan(TokenType.PRE_EXEC_COMS_STRING);
n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok);
node.Nodes.Add(n);
if (tok.Type != TokenType.PRE_EXEC_COMS_STRING) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.PRE_EXEC_COMS_STRING.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return;
}
tok = scanner.Scan(TokenType.STRING);
n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok);
node.Nodes.Add(n);
if (tok.Type != TokenType.STRING) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.STRING.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return;
}
break;
default:
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found.", 0x0002, 0, tok.StartPos, tok.StartPos, tok.Length));
break;
}
parent.Token.UpdateRange(node.Token);
......
......@@ -50,8 +50,16 @@ namespace TinyPG
Tokens.Add(TokenType.PROGRAMTYPE);
regex = new Regex(@"#MAXREG", RegexOptions.Compiled);
Patterns.Add(TokenType.PREPROCESSORCOM, regex);
Tokens.Add(TokenType.PREPROCESSORCOM);
Patterns.Add(TokenType.PRE_EXEC_COMS_INT, regex);
Tokens.Add(TokenType.PRE_EXEC_COMS_INT);
regex = new Regex(@"#IMPORT", RegexOptions.Compiled);
Patterns.Add(TokenType.PRE_EXEC_COMS_STRING, regex);
Tokens.Add(TokenType.PRE_EXEC_COMS_STRING);
regex = new Regex(@"[A-Za-z0-9-_,.]+[A-Za-z0-9-_]", RegexOptions.Compiled);
Patterns.Add(TokenType.STRING, regex);
Tokens.Add(TokenType.STRING);
regex = new Regex(@"0", RegexOptions.Compiled);
Patterns.Add(TokenType.ZERO, regex);
......@@ -61,7 +69,7 @@ namespace TinyPG
Patterns.Add(TokenType.INTEGER, regex);
Tokens.Add(TokenType.INTEGER);
regex = new Regex(@"[A-Z][a-zA-Z_]*", RegexOptions.Compiled);
regex = new Regex(@"[A-Z][a-zA-Z_0-9]*", RegexOptions.Compiled);
Patterns.Add(TokenType.NAME, regex);
Tokens.Add(TokenType.NAME);
......@@ -282,7 +290,7 @@ namespace TinyPG
//Non terminal tokens:
Start = 2,
PreProcDef= 3,
PreExecComs= 3,
MacroDef= 4,
OutputDef= 5,
OutputRegister= 6,
......@@ -321,33 +329,35 @@ namespace TinyPG
BRACKETOPEN= 37,
BRACKETCLOSE= 38,
PROGRAMTYPE= 39,
PREPROCESSORCOM= 40,
ZERO = 41,
INTEGER = 42,
NAME = 43,
REGISTERCALL= 44,
DEFINE = 45,
ENDDEFINE= 46,
INPUT = 47,
INPUTCALL= 48,
OUTPUT = 49,
OUTPUTCALL= 50,
AUX = 51,
AUXCALL = 52,
LOOP = 53,
WHILE = 54,
END = 55,
DO = 56,
AS = 57,
NUMBER_OPERATION= 58,
COLON = 59,
ASSIGN = 60,
SEMICOLON= 61,
COMMA = 62,
EOF = 63,
WHITESPACE= 64,
COMMENTLINE= 65,
COMMENTBLOCK= 66
PRE_EXEC_COMS_INT= 40,
PRE_EXEC_COMS_STRING= 41,
STRING = 42,
ZERO = 43,
INTEGER = 44,
NAME = 45,
REGISTERCALL= 46,
DEFINE = 47,
ENDDEFINE= 48,
INPUT = 49,
INPUTCALL= 50,
OUTPUT = 51,
OUTPUTCALL= 52,
AUX = 53,
AUXCALL = 54,
LOOP = 55,
WHILE = 56,
END = 57,
DO = 58,
AS = 59,
NUMBER_OPERATION= 60,
COLON = 61,
ASSIGN = 62,
SEMICOLON= 63,
COMMA = 64,
EOF = 65,
WHITESPACE= 66,
COMMENTLINE= 67,
COMMENTBLOCK= 68
}
public class Token
......
......@@ -9,10 +9,12 @@
BRACKETOPEN -> @"\(";
BRACKETCLOSE -> @"\)";
PROGRAMTYPE -> @"#(LOOP|WHILE)";
PREPROCESSORCOM -> @"#MAXREG";
PRE_EXEC_COMS_INT -> @"#MAXREG";
PRE_EXEC_COMS_STRING -> @"#IMPORT";
STRING -> @"[A-Za-z0-9-_,.]+[A-Za-z0-9-_]";
ZERO -> @"0";
INTEGER -> @"0|[1-9][0-9]*";
NAME -> @"[A-Z][a-zA-Z_]*";
NAME -> @"[A-Z][a-zA-Z_0-9]*";
REGISTERCALL -> @"x";
DEFINE -> @"def";
ENDDEFINE -> @"enddef";
......@@ -47,8 +49,8 @@ COMMENTBLOCK -> @"/\*[^*]*\*+(?:[^/*][^*]*\*+)*/";
// Production lines LL(1):
Start -> PROGRAMTYPE (PreProcDef)* (MacroDef)* (Instruction)? EOF;
PreProcDef -> PREPROCESSORCOM (INTEGER)?;
Start -> PROGRAMTYPE (PreExecComs)* (MacroDef)* (Instruction)? EOF;
PreExecComs -> (PRE_EXEC_COMS_INT INTEGER) |(PRE_EXEC_COMS_STRING STRING);