Commit 35ce1705 authored by Alexander Dietsch's avatar Alexander Dietsch

Simulator:

-Fixed minor bugs occuring on rare conditions

Dissertation:
Finished dissertation
parent 8f0d4580
...@@ -41,7 +41,7 @@ namespace LWSimulatorCons ...@@ -41,7 +41,7 @@ namespace LWSimulatorCons
} }
} }, } },
{ {
"e|execute", "automatically run the program; sets clock-rate to 0 and sets parameter '--quarantined'", "r|run", "automatically run the code; sets clock-rate to 0 and sets parameter '--quarantined'",
v => { v => {
if(v != null) if(v != null)
{ {
...@@ -73,11 +73,11 @@ namespace LWSimulatorCons ...@@ -73,11 +73,11 @@ namespace LWSimulatorCons
"q|quarantined", "disallow the simulator to save the options so they won't carry over to the next start; will be set automatically if paremeter '--run' is set", "q|quarantined", "disallow the simulator to save the options so they won't carry over to the next start; will be set automatically if paremeter '--run' is set",
v => quarantined = v != null }, v => quarantined = v != null },
{ {
"R|variables=", "set variable file", "V|variables=", "set variable file",
v => variablePath = v }, v => variablePath = v },
{ {
"r|limit-variables=", "limit the number of variables that any program is allowed to use at most; default is 100", "v|limit-variables=", "limit the number of variables that any code is allowed to use at most; default is 100",
v => { v => {
if (!tryParseValue(v,out limitVariables)) if (!tryParseValue(v,out limitVariables))
{ {
...@@ -86,7 +86,7 @@ namespace LWSimulatorCons ...@@ -86,7 +86,7 @@ namespace LWSimulatorCons
} }
} }, } },
{ {
"s|limit-steps=", "limit the number of steps that any program is allowed to do at most before being interrupted; default is 0 (off)", "s|limit-steps=", "limit the number of steps that any code is allowed to do at most before being interrupted; default is 0 (off)",
v => { v => {
if (!tryParseValue(v,out limitSteps)) if (!tryParseValue(v,out limitSteps))
{ {
...@@ -159,7 +159,7 @@ namespace LWSimulatorCons ...@@ -159,7 +159,7 @@ namespace LWSimulatorCons
if (!errors[0] && limitVariables != long.MaxValue) if (!errors[0] && limitVariables != long.MaxValue)
{ {
if(limitVariables <= 0 || !simulator.setOptionVal("maxRegAm",limitVariables)) if(limitVariables <= 0 || !simulator.setOptionVal("maxVarAm",limitVariables))
{ {
errorInd = true; errorInd = true;
errors[1] = true; errors[1] = true;
...@@ -218,9 +218,9 @@ namespace LWSimulatorCons ...@@ -218,9 +218,9 @@ namespace LWSimulatorCons
{ {
if(!simulator.allInitialized()) if(!simulator.allInitialized())
{ {
printLog("WARNING: The LWSimulator DLL uses callback functions unknown to this console application."); printLog(new List<string> { "WARNING: The LWSimulator DLL uses callback functions unknown to this console application." });
} }
simulator.runProgram(program); simulator.runProgram(program,inputPath);
waitForFinish.WaitOne(); waitForFinish.WaitOne();
#if (DEBUG) #if (DEBUG)
Console.ReadLine(); Console.ReadLine();
...@@ -294,15 +294,18 @@ namespace LWSimulatorCons ...@@ -294,15 +294,18 @@ namespace LWSimulatorCons
return true; return true;
} }
private static void printLog(string s) private static void printLog(List<string> s)
{ {
if (logLevel == 2 && !s.StartsWith("Code returned") && !s.StartsWith("Syntax")) for (int i = 0; i < s.Count; i++)
return; {
if (logLevel == 1 && !(s.StartsWith("WARNING") || s.StartsWith("ERROR") || s.StartsWith("Code returned") || s.StartsWith("Syntax"))) if (logLevel == 2 && !s[i].StartsWith("Code returned") && !s[i].StartsWith("Syntax"))
return; continue;
if (logLevel == 0 && s.StartsWith("DEBUG")) if (logLevel == 1 && !(s[i].StartsWith("WARNING") || s[i].StartsWith("ERROR") || s[i].StartsWith("Code returned") || s[i].StartsWith("Syntax")))
return; continue;
Console.WriteLine(s); if (logLevel == 0 && s[i].StartsWith("DEBUG"))
continue;
Console.WriteLine(s[i]);
}
} }
/// <summary> /// <summary>
......
...@@ -18,9 +18,9 @@ namespace LWSimulatorGUI ...@@ -18,9 +18,9 @@ namespace LWSimulatorGUI
{ {
InitializeComponent(); InitializeComponent();
simul = coord; simul = coord;
nUDValue.Value = simul.getOptionVal("defRegVal"); nUDValue.Value = simul.getOptionVal("defVarVal");
nUDVariable.Maximum = simul.getVariableAmount() - 1; nUDVariable.Maximum = simul.getVariableAmount() - 1;
nUDVariableAm.Maximum = simul.getOptionVal("maxRegAm") - simul.getVariableAmount(); nUDVariableAm.Maximum = simul.getOptionVal("maxVarAm") - simul.getVariableAmount();
// Attempt to get some uniformity between platforms // Attempt to get some uniformity between platforms
nUDVariableAm.Location = new Point(lInsert.Location.X + lInsert.Width + 6, nUDVariableAm.Location.Y); nUDVariableAm.Location = new Point(lInsert.Location.X + lInsert.Width + 6, nUDVariableAm.Location.Y);
......
...@@ -93,23 +93,23 @@ ...@@ -93,23 +93,23 @@
<Compile Include="CustomRichTextBox.cs"> <Compile Include="CustomRichTextBox.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="DeleteRegisters.cs"> <Compile Include="DeleteVariables.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="DeleteRegisters.Designer.cs"> <Compile Include="DeleteVariables.Designer.cs">
<DependentUpon>DeleteRegisters.cs</DependentUpon> <DependentUpon>DeleteVariables.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="ShiftRegisters.cs"> <Compile Include="ShiftVariables.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="ShiftRegisters.Designer.cs"> <Compile Include="ShiftVariables.Designer.cs">
<DependentUpon>ShiftRegisters.cs</DependentUpon> <DependentUpon>ShiftVariables.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="InsertRegisters.cs"> <Compile Include="InsertVariables.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="InsertRegisters.Designer.cs"> <Compile Include="InsertVariables.Designer.cs">
<DependentUpon>InsertRegisters.cs</DependentUpon> <DependentUpon>InsertVariables.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="DoubleBufferedListBox.cs"> <Compile Include="DoubleBufferedListBox.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
...@@ -140,14 +140,14 @@ ...@@ -140,14 +140,14 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<Compile Include="SimpleGUISimulation.cs" /> <Compile Include="SimpleGUISimulation.cs" />
<EmbeddedResource Include="DeleteRegisters.resx"> <EmbeddedResource Include="DeleteVariables.resx">
<DependentUpon>DeleteRegisters.cs</DependentUpon> <DependentUpon>DeleteVariables.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="ShiftRegisters.resx"> <EmbeddedResource Include="ShiftVariables.resx">
<DependentUpon>ShiftRegisters.cs</DependentUpon> <DependentUpon>ShiftVariables.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="InsertRegisters.resx"> <EmbeddedResource Include="InsertVariables.resx">
<DependentUpon>InsertRegisters.cs</DependentUpon> <DependentUpon>InsertVariables.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="LogWindow.resx"> <EmbeddedResource Include="LogWindow.resx">
<DependentUpon>LogWindow.cs</DependentUpon> <DependentUpon>LogWindow.cs</DependentUpon>
......
...@@ -191,16 +191,19 @@ namespace LWSimulatorGUI ...@@ -191,16 +191,19 @@ namespace LWSimulatorGUI
/// Makes the GUI add a line. /// Makes the GUI add a line.
/// </summary> /// </summary>
/// <param name="line">The line to be added.</param> /// <param name="line">The line to be added.</param>
internal void addLine_Notify(string line) internal void addLine_Notify(List<string> lines)
{ {
if (line.StartsWith("DEBUG"))
if(simulator.getOptionVal("advancedLog") == 0)
return;
lock(toAddToLog) lock(toAddToLog)
{ {
if (toAddToLog.Count >= simulator.getOptionVal("maxLogLines")) for (int i = 0; i < lines.Count; i++)
toAddToLog.RemoveFirst(); {
toAddToLog.AddLast(line); if (lines[i].StartsWith("DEBUG"))
if (simulator.getOptionVal("advancedLog") == 0)
continue;
if (toAddToLog.Count >= simulator.getOptionVal("maxLogLines"))
toAddToLog.RemoveFirst();
toAddToLog.AddLast(lines[i]);
}
} }
if (InvokeRequired) if (InvokeRequired)
this.Invoke((MethodInvoker)delegate this.Invoke((MethodInvoker)delegate
......
...@@ -429,7 +429,7 @@ namespace LWSimulatorGUI ...@@ -429,7 +429,7 @@ namespace LWSimulatorGUI
changeCurCharIndex(curCharIndex); changeCurCharIndex(curCharIndex);
// create & set Point pt to (0,0) // create & set Point pt to (0,0)
Point pt = new Point(0, 0); Point pt = new Point(0, 0);
// get First Index & First Line from richTextBox1 // get First Index & First Line
int First_Index = fCTBProgram.GetCharIndexFromPosition(pt); int First_Index = fCTBProgram.GetCharIndexFromPosition(pt);
int First_Line = fCTBProgram.GetLineFromCharIndex(First_Index); int First_Line = fCTBProgram.GetLineFromCharIndex(First_Index);
// set X & Y coordinates of Point pt to ClientRectangle Width & Height respectively // set X & Y coordinates of Point pt to ClientRectangle Width & Height respectively
...@@ -803,7 +803,7 @@ namespace LWSimulatorGUI ...@@ -803,7 +803,7 @@ namespace LWSimulatorGUI
/// <param name="e">Arguments of the type <see cref="ElapsedEventArgs">ElapsedEventArgs</see></param> /// <param name="e">Arguments of the type <see cref="ElapsedEventArgs">ElapsedEventArgs</see></param>
private void FailSafeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void FailSafeTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
log.addLine_Notify("DEBUG: FailSafe timed out; Rechecking state."); log.addLine_Notify(new List<string> { "DEBUG: FailSafe timed out; Rechecking state." });
UpdateRunningStateChange(); UpdateRunningStateChange();
} }
...@@ -991,7 +991,7 @@ namespace LWSimulatorGUI ...@@ -991,7 +991,7 @@ namespace LWSimulatorGUI
if (lineNumb == -1) if (lineNumb == -1)
lineNumb = fCTBProgram.Lines.Length; lineNumb = fCTBProgram.Lines.Length;
log.addLine_Notify(string.Format("Syntax error in line {0}, position {1}: {2}", lineNumb, p.Position - totalCount, p.Message)); log.addLine_Notify(new List<string> { string.Format("Syntax error in line {0}, position {1}: {2}", lineNumb, p.Position - totalCount, p.Message) });
} }
} }
} }
...@@ -1118,7 +1118,7 @@ namespace LWSimulatorGUI ...@@ -1118,7 +1118,7 @@ namespace LWSimulatorGUI
if (!string.IsNullOrEmpty(currentFilePath)) if (!string.IsNullOrEmpty(currentFilePath))
oFDRegs.InitialDirectory = Path.GetDirectoryName(currentFilePath); oFDRegs.InitialDirectory = Path.GetDirectoryName(currentFilePath);
oFDRegs.Filter = "LWVariable files (*.lwreg)|*.lwreg|txt files (*.txt)|*.txt|All files (*.*)|*.*"; oFDRegs.Filter = "LWVariable files (*.lwVar)|*.lwVar|txt files (*.txt)|*.txt|All files (*.*)|*.*";
oFDRegs.FilterIndex = 1; oFDRegs.FilterIndex = 1;
oFDRegs.RestoreDirectory = true; oFDRegs.RestoreDirectory = true;
oFDRegs.CheckFileExists = true; oFDRegs.CheckFileExists = true;
...@@ -1160,12 +1160,12 @@ namespace LWSimulatorGUI ...@@ -1160,12 +1160,12 @@ namespace LWSimulatorGUI
else else
suggestedName = String.Format("{0}_Variables", Path.GetFileNameWithoutExtension(currentFilePath)); suggestedName = String.Format("{0}_Variables", Path.GetFileNameWithoutExtension(currentFilePath));
SaveFileDialog save = new SaveFileDialog(); SaveFileDialog save = new SaveFileDialog();
save.Filter = "LWVariable files (*.lwreg)|*.lwreg|txt files (*.txt)|*.txt|All files (*.*)|*.*"; save.Filter = "LWVariable files (*.lwVar)|*.lwVar|txt files (*.txt)|*.txt|All files (*.*)|*.*";
save.FilterIndex = 1; save.FilterIndex = 1;
save.RestoreDirectory = true; save.RestoreDirectory = true;
save.OverwritePrompt = true; save.OverwritePrompt = true;
save.CheckPathExists = true; save.CheckPathExists = true;
save.FileName = suggestedName + ".lwreg"; save.FileName = suggestedName + ".lwVar";
if (save.ShowDialog() == DialogResult.OK) if (save.ShowDialog() == DialogResult.OK)
{ {
......
...@@ -23,8 +23,8 @@ namespace LWSimulatorGUI ...@@ -23,8 +23,8 @@ namespace LWSimulatorGUI
new ToolTip().SetToolTip(pBHelpRegDefVal, "Initializes every newly added variable with given number."); new ToolTip().SetToolTip(pBHelpRegDefVal, "Initializes every newly added variable with given number.");
new ToolTip().SetToolTip(pBHelpAdvancedLog, "Log will not only display actions of the program\nbut also debug information."); new ToolTip().SetToolTip(pBHelpAdvancedLog, "Log will not only display actions of the program\nbut also debug information.");
simulator = simul; simulator = simul;
nUDVariables.Value = simul.getOptionVal("maxRegAm"); nUDVariables.Value = simul.getOptionVal("maxVarAm");
nUDRegDefVal.Value = simul.getOptionVal("defRegVal"); nUDRegDefVal.Value = simul.getOptionVal("defVarVal");
nUDLogLines.Value = simul.getOptionVal("maxLogLines"); nUDLogLines.Value = simul.getOptionVal("maxLogLines");
chBClearLog.Checked = (simul.getOptionVal("clearLog") != 0); chBClearLog.Checked = (simul.getOptionVal("clearLog") != 0);
chBAdvancedLog.Checked = (simul.getOptionVal("advancedLog") != 0); chBAdvancedLog.Checked = (simul.getOptionVal("advancedLog") != 0);
...@@ -84,9 +84,9 @@ namespace LWSimulatorGUI ...@@ -84,9 +84,9 @@ namespace LWSimulatorGUI
{ {
List<string> unableOptions = new List<string>(); List<string> unableOptions = new List<string>();
bool validDir = Directory.Exists(tBDirPath.Text); bool validDir = Directory.Exists(tBDirPath.Text);
if (!simulator.setOptionVal("maxRegAm", (long)nUDVariables.Value)) if (!simulator.setOptionVal("maxVarAm", (long)nUDVariables.Value))
unableOptions.Add("-Maximum number of variables"); unableOptions.Add("-Maximum number of variables");
if(!simulator.setOptionVal("defRegVal", (long)nUDRegDefVal.Value)) if(!simulator.setOptionVal("defVarVal", (long)nUDRegDefVal.Value))
unableOptions.Add("-Default value of variables"); unableOptions.Add("-Default value of variables");
if(!simulator.setOptionVal("maxLogLines", (long)nUDLogLines.Value)) if(!simulator.setOptionVal("maxLogLines", (long)nUDLogLines.Value))
unableOptions.Add("-Maximum number of log lines"); unableOptions.Add("-Maximum number of log lines");
......
...@@ -45,8 +45,8 @@ namespace LWSimulatorGUI ...@@ -45,8 +45,8 @@ namespace LWSimulatorGUI
clearLog = emptyDummyMethod; clearLog = emptyDummyMethod;
updateOptions = dummyMethod<string>; updateOptions = dummyMethod<string>;
logMessage = dummyMethod<string>; logMessage = dummyMethod<string>;
optionVals.Add("maxRegAm", 100); optionVals.Add("maxVarAm", 100);
optionVals.Add("defRegVal", 0); optionVals.Add("defVarVal", 0);
optionVals.Add("maxLogLines", 300); optionVals.Add("maxLogLines", 300);
optionVals.Add("clearLog", 1); optionVals.Add("clearLog", 1);
optionVals.Add("timePerStep", 100); optionVals.Add("timePerStep", 100);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -70,8 +70,8 @@ namespace TinyPG ...@@ -70,8 +70,8 @@ namespace TinyPG
} }
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE);
if (tok.Type == TokenType.REGISTERCALL if (tok.Type == TokenType.VARIABLECALL
|| tok.Type == TokenType.BRACKETOPEN || tok.Type == TokenType.BRACKETOPEN
|| tok.Type == TokenType.LOOP || tok.Type == TokenType.LOOP
|| tok.Type == TokenType.WHILE) || tok.Type == TokenType.WHILE)
...@@ -1083,10 +1083,10 @@ namespace TinyPG ...@@ -1083,10 +1083,10 @@ namespace TinyPG
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE);
switch (tok.Type) switch (tok.Type)
{ {
case TokenType.REGISTERCALL: case TokenType.VARIABLECALL:
case TokenType.BRACKETOPEN: case TokenType.BRACKETOPEN:
ParseAssignment(node); ParseAssignment(node);
break; break;
...@@ -1130,10 +1130,10 @@ namespace TinyPG ...@@ -1130,10 +1130,10 @@ namespace TinyPG
ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Expression), "Expression"); ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Expression), "Expression");
parent.Nodes.Add(node); parent.Nodes.Add(node);
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.ZERO, TokenType.NUMBER_OPERATION); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.ZERO, TokenType.NUMBER_OPERATION);
switch (tok.Type) switch (tok.Type)
{ {
case TokenType.REGISTERCALL: case TokenType.VARIABLECALL:
ParseVariable(node); ParseVariable(node);
...@@ -1164,10 +1164,10 @@ namespace TinyPG ...@@ -1164,10 +1164,10 @@ namespace TinyPG
ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Assignment), "Assignment"); ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Assignment), "Assignment");
parent.Nodes.Add(node); parent.Nodes.Add(node);
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.BRACKETOPEN); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.BRACKETOPEN);
switch (tok.Type) switch (tok.Type)
{ {
case TokenType.REGISTERCALL: case TokenType.VARIABLECALL:
ParseVariable(node); ParseVariable(node);
...@@ -1183,10 +1183,10 @@ namespace TinyPG ...@@ -1183,10 +1183,10 @@ namespace TinyPG
} }
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.ZERO, TokenType.NUMBER_OPERATION, TokenType.NAME); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.ZERO, TokenType.NUMBER_OPERATION, TokenType.NAME);
switch (tok.Type) switch (tok.Type)
{ {
case TokenType.REGISTERCALL: case TokenType.VARIABLECALL:
case TokenType.ZERO: case TokenType.ZERO:
case TokenType.NUMBER_OPERATION: case TokenType.NUMBER_OPERATION:
ParseValue(node); ParseValue(node);
...@@ -1232,10 +1232,10 @@ namespace TinyPG ...@@ -1232,10 +1232,10 @@ namespace TinyPG
ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Value), "Value"); ParseNode node = parent.CreateNode(scanner.GetToken(TokenType.Value), "Value");
parent.Nodes.Add(node); parent.Nodes.Add(node);
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.ZERO, TokenType.NUMBER_OPERATION); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.ZERO, TokenType.NUMBER_OPERATION);
switch (tok.Type) switch (tok.Type)
{ {
case TokenType.REGISTERCALL: case TokenType.VARIABLECALL:
ParseVariable(node); ParseVariable(node);
break; break;
case TokenType.ZERO: case TokenType.ZERO:
...@@ -1322,12 +1322,12 @@ namespace TinyPG ...@@ -1322,12 +1322,12 @@ namespace TinyPG
tok = scanner.Scan(TokenType.REGISTERCALL); tok = scanner.Scan(TokenType.VARIABLECALL);
n = node.CreateNode(tok, tok.ToString() ); n = node.CreateNode(tok, tok.ToString() );
node.Token.UpdateRange(tok); node.Token.UpdateRange(tok);
node.Nodes.Add(n); node.Nodes.Add(n);
if (tok.Type != TokenType.REGISTERCALL) { if (tok.Type != TokenType.VARIABLECALL) {
tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.REGISTERCALL.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length)); tree.Errors.Add(new ParseError("Unexpected token '" + tok.Text.Replace("\n", "") + "' found. Expected " + TokenType.VARIABLECALL.ToString(), 0x1001, 0, tok.StartPos, tok.StartPos, tok.Length));
return; return;
} }
...@@ -1431,8 +1431,8 @@ namespace TinyPG ...@@ -1431,8 +1431,8 @@ namespace TinyPG
} }
tok = scanner.LookAhead(TokenType.REGISTERCALL); tok = scanner.LookAhead(TokenType.VARIABLECALL);
if (tok.Type == TokenType.REGISTERCALL) if (tok.Type == TokenType.VARIABLECALL)
{ {
ParseVariableEnum(node); ParseVariableEnum(node);
} }
...@@ -1482,8 +1482,8 @@ namespace TinyPG ...@@ -1482,8 +1482,8 @@ namespace TinyPG
} }
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE);
if (tok.Type == TokenType.REGISTERCALL if (tok.Type == TokenType.VARIABLECALL
|| tok.Type == TokenType.BRACKETOPEN || tok.Type == TokenType.BRACKETOPEN
|| tok.Type == TokenType.LOOP || tok.Type == TokenType.LOOP
|| tok.Type == TokenType.WHILE) || tok.Type == TokenType.WHILE)
...@@ -1536,8 +1536,8 @@ namespace TinyPG ...@@ -1536,8 +1536,8 @@ namespace TinyPG
} }
tok = scanner.LookAhead(TokenType.REGISTERCALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE); tok = scanner.LookAhead(TokenType.VARIABLECALL, TokenType.BRACKETOPEN, TokenType.LOOP, TokenType.WHILE);
if (tok.Type == TokenType.REGISTERCALL if (tok.Type == TokenType.VARIABLECALL
|| tok.Type == TokenType.BRACKETOPEN || tok.Type == TokenType.BRACKETOPEN
|| tok.Type == TokenType.LOOP || tok.Type == TokenType.LOOP
|| tok.Type == TokenType.WHILE) || tok.Type == TokenType.WHILE)
......
...@@ -49,7 +49,7 @@ namespace TinyPG ...@@ -49,7 +49,7 @@ namespace TinyPG
Patterns.Add(TokenType.PROGRAMTYPE, regex); Patterns.Add(TokenType.PROGRAMTYPE, regex);
Tokens.Add(TokenType.PROGRAMTYPE); Tokens.Add(TokenType.PROGRAMTYPE);
regex = new Regex(@"#MAXREG", RegexOptions.Compiled); regex = new Regex(@"#MAXREG|#MAXVAR", RegexOptions.Compiled);
Patterns.Add(TokenType.PRE_EXEC_COMS_INT, regex); Patterns.Add(TokenType.PRE_EXEC_COMS_INT, regex);
Tokens.Add(TokenType.PRE_EXEC_COMS_INT); Tokens.Add(TokenType.PRE_EXEC_COMS_INT);
...@@ -74,8 +74,8 @@ namespace TinyPG ...@@ -74,8 +74,8 @@ namespace TinyPG
Tokens.Add(TokenType.NAME); Tokens.Add(TokenType.NAME);
regex = new Regex(@"x", RegexOptions.Compiled); regex = new Regex(@"x", RegexOptions.Compiled);
Patterns.Add(TokenType.REGISTERCALL, regex); Patterns.Add(TokenType.VARIABLECALL, regex);
Tokens.Add(TokenType.REGISTERCALL); Tokens.Add(TokenType.VARIABLECALL);
regex = new Regex(@"def", RegexOptions.Compiled); regex = new Regex(@"def", RegexOptions.Compiled);
Patterns.Add(TokenType.DEFINE, regex); Patterns.Add(TokenType.DEFINE, regex);
...@@ -335,7 +335,7 @@ namespace TinyPG ...@@ -335,7 +335,7 @@ namespace TinyPG
ZERO = 43, ZERO = 43,
INTEGER = 44, INTEGER = 44,
NAME = 45, NAME = 45,
REGISTERCALL= 46, VARIABLECALL= 46,
DEFINE = 47, DEFINE = 47,
ENDDEFINE= 48, ENDDEFINE= 48,
INPUT = 49, INPUT = 49,
......
...@@ -3,19 +3,19 @@ ...@@ -3,19 +3,19 @@
<% @TinyPG Language="c#" %> <% @TinyPG Language="c#" %>
// Language to disallow natural numbers in registers. // Language to disallow natural numbers in Variables.
// Terminals // Terminals
BRACKETOPEN -> @"\("; BRACKETOPEN -> @"\(";
BRACKETCLOSE -> @"\)"; BRACKETCLOSE -> @"\)";
PROGRAMTYPE -> @"#(LOOP|WHILE)"; PROGRAMTYPE -> @"#(LOOP|WHILE)";
PRE_EXEC_COMS_INT -> @"#MAXREG"; PRE_EXEC_COMS_INT -> @"#MAXREG|#MAXVAR";
PRE_EXEC_COMS_STRING -> @"#IMPORT"; PRE_EXEC_COMS_STRING -> @"#IMPORT";
STRING -> @"[A-Za-z0-9-_,.]+[A-Za-z0-9-_]"; STRING -> @"[A-Za-z0-9-_,.]+[A-Za-z0-9-_]";
ZERO -> @"0"; ZERO -> @"0";
INTEGER -> @"0|[1-9][0-9]*"; INTEGER -> @"0|[1-9][0-9]*";
NAME -> @"[A-Z][a-zA-Z_0-9]*"; NAME -> @"[A-Z][a-zA-Z_0-9]*";
REGISTERCALL -> @"x"; VARIABLECALL -> @"x";
DEFINE -> @"def"; DEFINE -> @"def";
ENDDEFINE -> @"enddef"; ENDDEFINE -> @"enddef";
INPUT -> @"in"; INPUT -> @"in";
...@@ -52,41 +52,41 @@ COMMENTBLOCK -> @"/\*[^*]*\*+(?:[^/*][^*]*\*+)*/"; ...@@ -52,41 +52,41 @@ COMMENTBLOCK -> @"/\*[^*]*\*+(?:[^/*][^*]*\*+)*/";
Start -> PROGRAMTYPE (PreExecComs)* (MacroDef)* (Instruction)? EOF; Start -> PROGRAMTYPE (PreExecComs)* (MacroDef)* (Instruction)? EOF;
PreExecComs -> (PRE_EXEC_COMS_INT INTEGER) |(PRE_EXEC_COMS_STRING STRING); PreExecComs -> (PRE_EXEC_COMS_INT INTEGER) |(PRE_EXEC_COMS_STRING STRING);
MacroDef -> DEFINE NAME OutputDef InputDef AuxDef DO InstructionM ENDDEFINE; MacroDef -> DEFINE NAME OutputDef InputDef AuxDef DO InstructionM ENDDEFINE;
OutputDef -> OUTPUT COLON OutputRegister (COMMA OutputRegister)*; OutputDef -> OUTPUT COLON OutputVariable (COMMA OutputVariable)*;
OutputRegister -> OUTPUTCALL INTEGER; OutputVariable -> OUTPUTCALL INTEGER;
InputDef -> INPUT COLON ( InputRegister (COMMA InputRegister)* )?; InputDef -> INPUT COLON ( InputVariable (COMMA InputVariable)* )?;
InputRegister -> INPUTCALL INTEGER; InputVariable -> INPUTCALL INTEGER;
AuxDef -> AUX COLON (AuxRegister (COMMA AuxRegister)* )?; AuxDef -> AUX COLON (AuxVariable (COMMA AuxVariable)* )?;
AuxRegister -> AUXCALL INTEGER; AuxVariable -> AUXCALL INTEGER;
AnyRegisterM -> (INPUTCALL | (OUTPUTCALL | AUXCALL)) INTEGER; AnyVariableM -> (INPUTCALL | (OUTPUTCALL | AUXCALL)) INTEGER;
InstructionM -> (AssignmentM | LoopBodyM | WhileBodyM) (SEMICOLON InstructionM)? ; InstructionM -> (AssignmentM | LoopBodyM | WhileBodyM) (SEMICOLON InstructionM)? ;
ExpressionM -> (AnyRegisterM (ExpressionMakroM)? )| NumberM; ExpressionM -> (AnyVariableM (ExpressionMakroM)? )| NumberM;
AssignmentM -> (AnyRegisterM ASSIGN (ValueM | MacroM)) | (RegisterArrayM ASSIGN MacroM); AssignmentM -> (AnyVariableM ASSIGN (ValueM | MacroM)) | (VariableArrayM ASSIGN MacroM);
ValueM -> AnyRegisterM | NumberM; ValueM -> AnyVariableM | NumberM;
NumberM -> ZERO | (NUMBER_OPERATION BRACKETOPEN ValueM BRACKETCLOSE); NumberM -> ZERO | (NUMBER_OPERATION BRACKETOPEN ValueM BRACKETCLOSE);
RegisterEnumM -> AnyRegisterM (COMMA AnyRegisterM)* ; VariableEnumM -> AnyVariableM (COMMA AnyVariableM)* ;
RegisterArrayM -> BRACKETOPEN RegisterEnumM BRACKETCLOSE; VariableArrayM -> BRACKETOPEN VariableEnumM BRACKETCLOSE;
RegisterArrayEmpM -> BRACKETOPEN (RegisterEnumM)? BRACKETCLOSE; VariableArrayEmpM -> BRACKETOPEN (VariableEnumM)? BRACKETCLOSE;
LoopBodyM -> LOOP ValueM DO (InstructionM)? END; LoopBodyM -> LOOP ValueM DO (InstructionM)? END;
WhileBodyM -> WHILE ExpressionM DO (InstructionM)? END; WhileBodyM -> WHILE ExpressionM DO (InstructionM)? END;
MacroM -> NAME RegisterArrayEmpM RegisterArrayEmpM; MacroM -> NAME VariableArrayEmpM VariableArrayEmpM;
ExpressionMakroM -> AS MacroM; ExpressionMakroM -> AS MacroM;
Instruction -> (Assignment | LoopBody | WhileBody) (SEMICOLON Instruction)? ; Instruction -> (Assignment | LoopBody | WhileBody) (SEMICOLON Instruction)? ;
Expression -> (Register (ExpressionMakro)? )| Number; Expression -> (Variable (ExpressionMakro)? )| Number;
Assignment -> (Register ASSIGN (Value | Macro)) | (RegisterArray ASSIGN Macro); Assignment -> (Variable ASSIGN (Value | Macro)) | (VariableArray ASSIGN Macro);
Value -> Register | Number; Value -> Variable | Number;
Number -> ZERO | (NUMBER_OPERATION BRACKETOPEN Value BRACKETCLOSE); Number -> ZERO | (NUMBER_OPERATION BRACKETOPEN Value BRACKETCLOSE);
Register -> REGISTERCALL INTEGER; Variable -> VARIABLECALL INTEGER;
RegisterEnum -> Register (COMMA Register)* ; VariableEnum -> Variable (COMMA Variable)* ;
RegisterArray -> BRACKETOPEN RegisterEnum BRACKETCLOSE; VariableArray -> BRACKETOPEN VariableEnum BRACKETCLOSE;
RegisterArrayEmp -> BRACKETOPEN (RegisterEnum)? BRACKETCLOSE; VariableArrayEmp -> BRACKETOPEN (VariableEnum)? BRACKETCLOSE;
LoopBody -> LOOP Value DO (Instruction)? END; LoopBody -> LOOP Value DO (Instruction)? END;
WhileBody -> WHILE Expression DO (Instruction)? END; WhileBody -> WHILE Expression DO (Instruction)? END;
Macro -> NAME RegisterArrayEmp RegisterArrayEmp; Macro -> NAME VariableArrayEmp VariableArrayEmp;
ExpressionMakro -> AS Macro; ExpressionMakro -> AS Macro;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment