Download source files - 97.0 Kb
Introduction
I made this application for my semester project for the subject of the Computer Architecture in which i decide to made a project which will use my capabilites for Data Structure for implement on the Computer Architecture so i decide to made a project for the Addressing Modes
What is This:
It is an application which shows the addrssing mode works according to the Reverse Polish notation rulse.
Domain of Project:
In this project there are the follwing restrictions
- 0-9 digits you can use for expression
- for -ve digit u will use the # special character for exaple for -1+2 will use as #1+2
- you can not use it for increment or decrement expression as ++1 is invalid
- You can enter only 0 to 3 addressing modes
Techniques For the Project
In this project i use the following techniques
class ProgramException : Exception
{
public ProgramException()
{
}
public ProgramException(string message)
: base(message)
{
}
public ProgramException(string message, Exception inner)
: base(message, inner)
{
}
}
Converting into Post Fix expression
class postfix
{
public string conversion(string infix)
{
int c = 0;
string rpn = "";
int size = infix.Length, i = 0;
stack stk = new stack(size);
while (i < size)
{
char ch = infix[i];
if (ch == '(' || ch == '{' || ch == '[' || ch == ')'
|| ch == '}' || ch == ']')
{
if (ch == '(' || ch == '{' || ch == '[')
{
c++;
stk.push(ch);
}
else if (ch == ')' || ch == '}' || ch == ']')
{
if (ch == ')')
{
while (true)
{
char sp = stk.pop();
if (sp == '(' || sp=='e')
break;
rpn = rpn + "" + sp;
}
}
else if (ch == '}')
{
while (true)
{
char sp = stk.pop();
if (sp == 'e')
break;
if (sp == '{')
break;
rpn = rpn + "" + sp;
}
}
else
{
while (true)
{
char sp = stk.pop();
if (sp == '[' || sp=='e')
break;
rpn = rpn + "" + sp;
sp = stk.pop();
}
}
}
}
else if (ch == '#')
{
rpn = rpn + "" + ch;
rpn = rpn + "" + infix[++i];
}
else if (ch >= '0' && ch <= '9')
{
rpn = rpn + "" + ch;
}
else if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
{
while (true)
{
char sp = stk.pop();
if (ch == '+' || ch == '-')
{
if (sp == 'e' || sp == '(' || sp == '{' || sp == '[')
{
if (sp == '(' || sp == '{' || sp == '[')
{
stk.push(sp);
}
stk.push(ch);
break;
}
else if (sp == '/' || sp == '*')
{
rpn = rpn + "" + sp;
stk.push(ch);
break;
}
else if (sp == '+' || sp == '-')
{
rpn = rpn + "" + sp;
stk.push(ch);
break;
}
else
rpn = rpn + "" + sp;
}
else if (ch == '*' || ch == '/')
{
if (sp == 'e' || sp == '(' || sp=='{' || sp=='[')
{
if (sp == '(' || sp == '{' || sp == '[')
stk.push(sp);
stk.push(ch);
break;
}
else if (sp == '/' || sp == '*')
{
rpn = rpn + "" + sp;
stk.push(ch);
break;
}
else if (sp == '+' || sp == '-')
{
stk.push(sp);
stk.push(ch);
break;
}
else
rpn = rpn + "" + sp;
}
}
}
i++;
}
while (true)
{
char sp = stk.pop();
if (sp == 'e')
break;
if ( sp == '[')
Console.WriteLine("Pakistan6");
rpn = rpn + "" + sp;
}
return rpn;
}
}
Control Key information
#region For Key Pressing
protected static void myHandler(object sender, ConsoleCancelEventArgs args)
{
Console.WriteLine("\nThe read operation has been interrupted.");
Console.WriteLine(" Key pressed: {0}", args.SpecialKey);
Console.WriteLine(" Cancel property: {0}", args.Cancel);
Console.WriteLine("Setting the Cancel property to true...");
args.Cancel = true;
Console.WriteLine(" Cancel property: {0}", args.Cancel);
Console.WriteLine("The read operation will resume...\n");
}
#endregion
Hetrogenius Testing
class Heterogeneous_Brackets_Validity
{
public int check(string exp)
{
stack stk = new stack(exp.Length);
int i = 0;
while (i < exp.Length)
{
char ch = exp[i];
if (ch == '(' || ch == '{' || ch == '[')
stk.push(ch);
else if (ch == ')' || ch == '}' || ch == ']')
{
char sp = stk.pop();
if (sp == 'e')
return 0;
else if (ch == ')' && sp == '(') { }
else if (ch == '}' && sp == '{') { }
else if (ch == ']' && sp == '[') { }
else return 0;
}
i++;
}
if(stk .pop ()=='e')
return 1;
else
return 0;
}
}
How to use it?
first u by pressing the right arrow u will enter in the process then u will give the express for example 1+2 and then u will give the addressing mode for example 0,1,2 or 3
Output:
You can see the output on the console window but also in the C drive with the name of output file
Instruction:
Please if u have any file of .txt by the name of output in C drive first cut that file from there because it will be change with the output of the expression
And there are so many others techniques are used in the project.
Please reply me with your useful comments related to the project.
At this email address smarty4u13@yahoo.com
Your thankful Abbas Ali Butt
My name is Abbas Ali Butt. I am a student of Punjab University Information and Technology.