本文整理汇总了C#中Scanner类的典型用法代码示例。如果您正苦于以下问题:C# Scanner类的具体用法?C# Scanner怎么用?C# Scanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Scanner类属于命名空间,在下文中一共展示了Scanner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadInvalidRepeatedTagDirective
public void ReadInvalidRepeatedTagDirective()
{
using (var reader = new StreamReader(string.Format("TestData{0}example-6.17_invalid-repeated-tag-directive.yml", Path.DirectorySeparatorChar)))
{
var scanner = new Scanner(reader);
var tokens = scanner.ReadTokens().ToList();
Assert.That(tokens.Count, Is.EqualTo(9));
var directiveTokens = tokens.FindAll(t => t is DirectiveToken).Select(t => t as DirectiveToken).ToList();
Assert.AreEqual(2, directiveTokens.Count);
Assert.IsNotNull(directiveTokens[0]);
Assert.That(directiveTokens[0].Name, Is.EqualTo("TAG"));
Assert.IsNotNull(directiveTokens[1]);
Assert.That(directiveTokens[1].Name, Is.EqualTo("TAG"));
var directiveParameters0 = directiveTokens[0].Parameters.ToList();
Assert.That(directiveParameters0.Count, Is.EqualTo(2));
Assert.That(directiveParameters0[0], Is.EqualTo("!"));
Assert.That(directiveParameters0[1], Is.EqualTo("!foo"));
var directiveParameters1 = directiveTokens[1].Parameters.ToList();
Assert.That(directiveParameters1.Count, Is.EqualTo(2));
Assert.That(directiveParameters1[0], Is.EqualTo("!"));
Assert.That(directiveParameters1[1], Is.EqualTo("!foo"));
var documentContentToken = tokens.Find(t => t is DocumentContentToken) as DocumentContentToken;
Assert.IsNotNull(documentContentToken);
Assert.AreEqual("bar", documentContentToken.Content.TrimEnd());
}
}
示例2: Scan
public static IEnumerable<Token> Scan(string source)
{
var se = new SymbolsEnumerator(source);
var result = new Scanner(se).Scan();
se.Dispose();
return result;
}
示例3: Run
void Run()
{
Scanner input = new Scanner(Console.In);
long A = input.NextInt();
long B = input.NextInt();
int N = input.NextInt();
Bignum a = new Bignum(0);
Bignum b = new Bignum(0);
Bignum one = new Bignum(1);
int last = 0;
for (int i = 0; i < N; i++) {
while (A % 2 == 0 && B % 2 == 0) { A /= 2; B /= 2; }
if (A > B || (A == B && last == 0)) {
B *= 2;
last = 0;
a.Add(a);
a.Add(one);
} else {
A *= 2;
last = 1;
b.Add(b);
b.Add(one);
}
}
a.Add(b);
Console.WriteLine(a);
}
示例4: Run
void Run()
{
Scanner input = new Scanner(Console.In);
string[] a = new string[3];
for (int i = 0; i < 3; i++)
a[i] = input.Next();
int max = 0, min = 0, max_c = 1;
for (int i = 1; i < 3; i++) {
if (a[i].Length > a[max].Length ||
(a[i].Length == a[max].Length && a[i].CompareTo(a[max]) > 0)) {
max = i;
max_c = 1;
} else if (a[i] == a[max]) {
max_c++;
} else {
min = i;
}
}
string[] names = new string[] { "Mary", "Klaus", "Peter" };
if (max_c == 1)
Console.WriteLine(names[max]);
else if (max_c == 2)
Console.WriteLine(names[min]);
else
Console.WriteLine("Draw");
}
示例5: Run
void Run()
{
Scanner input = new Scanner(Console.In);
long R = input.NextInt();
long xc = input.NextInt();
long yc = input.NextInt();
long x = input.NextInt() - xc;
long y = input.NextInt() - yc;
long dx = input.NextInt() - xc - x;
long dy = input.NextInt() - yc - y;
long a = dx * dx + dy * dy;
long b = 2 * x * dx + 2 * y * dy;
long c = x * x + y * y - R * R;
long det = b * b - 4 * a * c;
if (det == 0)
Console.WriteLine("0");
else if (det < 0)
Console.WriteLine("-1");
else {
double res = Math.Sqrt(det) / a * Math.Sqrt(dx * dx + dy * dy);
Console.WriteLine("{0:0.00000000}", res);
}
}
示例6: Keywords
public void Keywords(string keyword)
{
var lexer = new Scanner(keyword);
Token next = lexer.NextToken();
Assert.That(next, Is.InstanceOf<KeywordToken>());
Assert.That(((KeywordToken)next).Value, Is.EqualTo(keyword));
}
示例7: test_lex
public void test_lex()
{
Scanner lex = new Scanner();
lex.src = "int main() { return 0; }";
lex.Lex();
String output = lex.ToString();
}
示例8: ParseSource
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req)
{
Babel.Source source = (Babel.Source)this.GetSource(req.FileName);
bool yyparseResult = false;
// req.DirtySpan seems to be set even though no changes have occurred
// source.IsDirty also behaves strangely
// might be possible to use source.ChangeCount to sync instead
if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex
|| req.DirtySpan.iStartLine != req.DirtySpan.iEndLine) {
ErrorHandler handler = new ErrorHandler();
Scanner scanner = new Scanner(); // string interface
Parser parser = new Parser(); // use noarg constructor
parser.scanner = scanner;
scanner.Handler = handler;
parser.SetHandler(handler);
scanner.SetSource(req.Text, 0);
parser.MBWInit(req);
yyparseResult = parser.Parse();
// store the parse results
// source.ParseResult = aast;
source.ParseResult = null;
source.Braces = parser.Braces;
// for the time being, just pull errors back from the error handler
if (handler.ErrNum > 0) {
foreach (Babel.Parser.Error error in handler.SortedErrorList()) {
TextSpan span = new TextSpan();
span.iStartLine = span.iEndLine = error.line - 1;
span.iStartIndex = error.column;
span.iEndIndex = error.column + error.length;
req.Sink.AddError(req.FileName, error.message, span, Severity.Error);
}
}
}
switch (req.Reason) {
case ParseReason.Check:
case ParseReason.HighlightBraces:
case ParseReason.MatchBraces:
case ParseReason.MemberSelectAndHighlightBraces:
// send matches to sink
// this should (probably?) be filtered on req.Line / col
if (source.Braces != null) {
foreach (TextSpan[] brace in source.Braces) {
if (brace.Length == 2)
req.Sink.MatchPair(brace[0], brace[1], 1);
else if (brace.Length >= 3)
req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1);
}
}
break;
default:
break;
}
return new AuthoringScope(req.Text);
}
示例9: Parser
public Parser(string exp, ICalcFunction calcFunc)
{
this.exp = exp;
tree = null;
scanner = new Scanner(exp);
this.icalcfunc = calcFunc;
}
示例10: Run
void Run()
{
Scanner input = new Scanner(Console.In);
N = input.NextInt();
value = new int[N + 1];
for (int i = 1; i <= N; i++)
value[i] = input.NextInt();
kid = new int[N + 1];
sib = new int[N + 1];
parent = new int[N + 1];
for (int i = 1; i < N; i++) {
int x = input.NextInt();
int p = input.NextInt();
sib[x] = kid[p];
kid[p] = x;
parent[x] = p;
}
int root = 0;
for (int i = 1; i <= N; i++)
if (parent[i] == 0) root = i;
memo = new int[N + 1, 2];
got = new bool[N + 1, 2];
int res = Math.Max(vertCov(root, 0), vertCov(root, 1));
Console.WriteLine(res);
}
示例11: ReadBareDocuments
public void ReadBareDocuments()
{
using (var reader = new StreamReader(Path.Combine("TestData", "example-9.3_bare-documents.yml")))
{
var scanner = new Scanner(reader);
var tokens = scanner.ReadTokens().ToList();
Assert.That(tokens.Count, Is.EqualTo(12));
Assert.That(tokens[0], Is.InstanceOf(typeof(StreamStartToken)));
Assert.That(tokens[1], Is.InstanceOf(typeof(DirectivesStartToken)));
Assert.That(tokens[2], Is.InstanceOf(typeof(DirectivesEndToken)));
Assert.That(tokens[3], Is.InstanceOf(typeof(DocumentStartToken)));
Assert.That(tokens[4], Is.InstanceOf(typeof(DocumentContentToken)));
Assert.That(tokens[5], Is.InstanceOf(typeof(DocumentEndToken)));
Assert.That(tokens[6], Is.InstanceOf(typeof(DirectivesStartToken)));
Assert.That(tokens[7], Is.InstanceOf(typeof(DirectivesEndToken)));
Assert.That(tokens[8], Is.InstanceOf(typeof(DocumentStartToken)));
Assert.That(tokens[9], Is.InstanceOf(typeof(DocumentContentToken)));
Assert.That(tokens[10], Is.InstanceOf(typeof(DocumentEndToken)));
Assert.That(tokens[11], Is.InstanceOf(typeof(StreamEndToken)));
Assert.That(((DocumentContentToken)tokens[4]).Content, Is.Not.Empty);
Assert.That(((DocumentContentToken)tokens[9]).Content, Is.Not.Empty);
}
}
示例12: Evaluate
public override object Evaluate(Frame environment)
{
if (environment == null)
{
throw new ArgumentNullException("Environment can not be null.");
}
string path = environment.FindBindingValue(Parameters[0]).ToString();
if (!File.Exists(path))
{
throw new Exception("Could not find file: " + path);
}
using (StreamReader codeReader = new StreamReader(File.Open(path, FileMode.Open)))
{
Scanner scanner = new Scanner(codeReader);
Expression expr = scanner.NextExpression;
string evaluation = string.Empty;
while (expr != null)
{
evaluation = environment.Evaluate(expr).ToString();
expr = scanner.NextExpression;
}
return evaluation;
}
}
示例13: Parser
// constructs a parser for a string in memory (used for test purposes)
// ts is the string to be parsed, source is a name to be used as the
// filename in any error messages.
public Parser( string source, string ts )
{
this.filename = source;
sc = new Scanner(source, ts);
DeclaredFunctionList = new List<Function>();
UsedFunctions = new List<Function>();
}
示例14: button2_Click
private void button2_Click(object sender, EventArgs e)
{
label2.ForeColor = Color.Cyan;
label2.Text = "Being Compiled.";
try
{
Scanner scanner = null;
using (TextReader input = File.OpenText(openFileDialog1.FileName))
{
scanner = new Scanner(input);
}
Parser parser = new Parser(scanner.Tokens);
CodeGen codeGen = new CodeGen(parser.Result, Path.GetFileNameWithoutExtension(openFileDialog1.FileName) + ".exe");
label2.ForeColor = Color.Lime;
label2.Text = "Compiled! Check the directory this program is in, or click 'Test File' and check the console.";
button3.Enabled = true;
}
catch (Exception ex)
{
textBox3.Show();
textBox3.Text = ex.Message;
label2.ForeColor = Color.Red;
label2.Text = "Error!";
button3.Enabled = false;
}
}
示例15: Main
public static void Main(string[] arg)
{
if (arg.Length == 2)
{
Scanner scanner = new Scanner(arg[0]);
Parser parser = new Parser(scanner);
parser.Parse();
if (parser.errors.count != 0)
{
Console.WriteLine("*** " + parser.errors.count + " Parsing errors ***");
return;
}
parser.Write("output.ir");
IRStream tuples = parser.GetStream();
// Code Optimizations - 100% doesn't work yet
// tuples = SSA.DoSSAOptimizations(tuples);
// Register Allocation
List<IRTuple> tuples_out = Allocate.run(tuples);
// backenders should write ARM out to arg[1]
CodeGen.IRListToArmFile(tuples_out, arg[1]);
Console.Write("\n");
}
else Console.WriteLine("Usage: tcdscc <program.swift> <output.asm>");
}