?? program.cs
字號:
?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Scanner
{
class Program
{
public static String[,] collection = new String[,] { { "BEGIN", "1" }, { "END", "1" }, { "LET", "1" }, { "READ", "1" }, { "WRITE", "1" }, { "IF", "1" }, { "FI", "1" }, { "ELSE", "1" }, { "WHILE", "1" }, { "WEND", "1" }, { "+", "2" }, { "-", "2" }, { "*", "2" }, { "/", "2" }, { "%", "2" } };
public static String[] tokens = new String[] { "identifier", "keyword", "operand" };
static void Main(string[] args)
{
/*this code simply reads a file and then replaces all the contents in the file
*with their equivalents in the programming language in another output file.
*/
//take input file name from the current directory
Console.Clear();
String file_name, input;
Console.WriteLine("\n\t-< SIMPLE SCANNER >-");
if (args.Length == 0)
{
Console.Beep();
Console.WriteLine("Too Many/few Parameters");
Console.Write("Enter a valid .in file:");
file_name = Console.ReadLine();
}
else
{
file_name = args[0];
}
if (!File.Exists(file_name))
{
Console.Beep();
Console.WriteLine("ERROR: FILE NOT FOUND");
}//endIF
//readfile and then create a variable output and then append the output
//to the variable, finally write the output variable to .out file.
StreamReader stream = new StreamReader(file_name);
input = stream.ReadToEnd();
Console.WriteLine("\n\nFile Data:\n-----------------------\n");
Console.WriteLine(input);
String [] words = new String[100];
char [] sep = new char[]{' '};
words = input.Split(sep);
Console.WriteLine("\n\nScanned Tokens:\n--------------------\n");
foreach (string str in words)
{
String index = "";
index = find(str);
Console.Write("{0} ", replace(index));
}
Console.ReadKey();
}//endMAIN
public static string find(string str)
{
string index = "0";
for (int n = 0; n < collection.GetLength(0); n++)
{
if (str.CompareTo(collection[n,0]) == 0)
{
index = collection[n,1];
return(index);
}
}
return "0";
}
public static string replace(string index)
{
int ind = Convert.ToInt32(index);
return (tokens[ind]);
}
}//endClassProgam
}//endNAMESPACEScanner
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -