本文整理汇总了C#中Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.parse方法的具体用法?C# Parser.parse怎么用?C# Parser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.parse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
void Start () {
nodes = new List<GameObject> ();
Parser parser = new Parser ("F:\\cse165\\p2\\project\\Assets\\Scripts\\dolphinNetwork.gml");
graph = parser.parse();
if (graph == null)
return;
layout = new Layout (graph);
layout.init ();
cubeInit ();
}
示例2: parse
public static void parse(IEnumerable<char> input)
{
IEnumerable<char> preprocessed = removeFormatControlCharacters(input);
Parser parser = new Parser('\n');
try
{
// note: cannot process regexps for now, these are syntax dependent and
// only makes sense when we implement the syntax here!
#if TEST_LEXER
parser.parseAny(new List<char>(preprocessed).ToArray(), InputElementDiv);
#else
char[] file = new List<char>(preprocessed).ToArray();
uint? consumed = parser.parse(new List<char>(preprocessed).ToArray(), Program);
if (consumed == null)
throw new Exception("unable to parse JavaScript");
if (consumed.Value != file.Length)
throw new Exception(string.Format("unable to parse JavaScript, consumed {0} of {1} input characters", consumed.Value, file.Length));
#endif
}
catch (Parser.Exception e)
{
uint offset = e.Offset;
List<char> content = new List<char>(input);
int line = 1;
int column = 1;
for (int i = 0; i != offset; ++i, ++column)
{
// todo: use official line terminators
if (content[i] == '\n')
{
++line;
column = 1;
}
}
string eStr = string.Format("parse error at line {0}, column {1}", line, column);
throw new Exception(eStr, e);
}
}
示例3: run
public override int run(String[] args)
{
//
// Terminate cleanly on receipt of a signal.
//
shutdownOnInterrupt();
//
// Create a proxy for the root directory
//
var @base = communicator().stringToProxy("RootDir:default -h localhost -p 10000");
//
// Down-cast the proxy to a Directory proxy.
//
var rootDir = DirectoryPrxHelper.checkedCast(@base);
if(rootDir == null)
{
throw new Error("Invalid proxy");
}
var p = new Parser(rootDir);
return p.parse();
}
示例4: parse
public static Expression parse(string s)
{
Parser p = new Parser(s);
return p.parse();
}
示例5: Main
//.........这里部分代码省略.........
if (option.StartsWith("target:"))
desiredTarget = option.Remove(0, 7);
else
desiredTarget = option.Remove(0, 2);
if (desiredTarget == "exe")
PEmitter.Target = PEmitter.EXECUTABLE;
else if (desiredTarget == "library")
PEmitter.Target = PEmitter.LIBRARY;
else {
Report.Error(005, desiredTarget);
return;
}
}
// reference option
if (option.StartsWith("reference:") || option.StartsWith("r:")) {
string desiredReferences;
if (option.StartsWith("reference:"))
desiredReferences = option.Remove(0, 10);
else
desiredReferences = option.Remove(0, 2);
char[] separators = new char[] {',', ';'};
string[] references = desiredReferences.Split(separators);
foreach (string reference in references)
if (reference != "")
SymbolTable.GetInstance().AddExternalAssembly(reference);
}
// nowarn option
if (option == "nowarn") {
Report.WarningsEnabled = false;
}
}
// if no output file specified, use souce file name and adjust file extension
if (PEmitter.OutputFile == null)
PEmitter.OutputFile = new FileInfo(sourceFile.FullName);
if (PEmitter.Target == PEmitter.EXECUTABLE && !PEmitter.OutputFile.Name.EndsWith(".exe")) {
int indexLastDot = PEmitter.OutputFile.FullName.LastIndexOf('.');
if (indexLastDot == -1)
PEmitter.OutputFile = new FileInfo(PEmitter.OutputFile.FullName + ".exe");
else
PEmitter.OutputFile = new FileInfo(PEmitter.OutputFile.FullName.Substring(0, indexLastDot) + ".exe");
}
else if (PEmitter.Target == PEmitter.LIBRARY && !PEmitter.OutputFile.Name.EndsWith(".dll")) {
int indexLastDot = PEmitter.OutputFile.FullName.LastIndexOf('.');
if (indexLastDot == -1)
PEmitter.OutputFile = new FileInfo(PEmitter.OutputFile.FullName + ".dll");
else
PEmitter.OutputFile = new FileInfo(PEmitter.OutputFile.FullName.Substring(0, indexLastDot) + ".dll");
}
// set formatting to US Amiercan (needed e.g. for type Double)
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
// initialize parser
Console.WriteLine("Parsing from file " + sourceFile.FullName + "...");
Parser yy = new Parser(new Scanner(sourceFileStreamReader));
// parse input stream
AST ast = (AST)yy.parse().value;
// create module
PEmitter.BeginModule();
// transform AST to create class __MAIN and function __MAIN()
//Console.WriteLine("Working on class __MAIN and function __MAIN()...");
new MainMethodVisitor().Visit(ast);
// ensure every class (except __MAIN) has a constructor
//Console.WriteLine("Working on constructors...");
new ConstructorVisitor().Visit(ast);
// ensure every method has a return statement and cut unreachable statements after a return
//Console.WriteLine("Working on return statements...");
new ReturnStatementVisitor().Visit(ast);
// ensure there is no break/continue without a loop
//Console.WriteLine("Working on loops...");
new LoopVisitor().Visit(ast);
// reorder class declarations by inheritance
//Console.WriteLine("Working on interitance...");
new InheritanceVisitor().Visit(ast);
// collect all types so they may be used before being declared
//Console.WriteLine("Working on types...");
new TypesVisitor().Visit(ast);
// collect all class variables and functions so they may be used before being declared
//Console.WriteLine("Working on class variables and functions...");
new ClassVariableAndFunctionsVisitor().Visit(ast);
// build symbol table
//Console.WriteLine("Building symbol table...");
new SymbolTableVisitor().Visit(ast);
// emit CIL code
//Console.WriteLine("Emitting CIL code...");
new EmitterVisitor().Visit(ast);
// save module
PEmitter.EndModule();
// report success
string success = "Compiling to file " + PEmitter.OutputFile.FullName + " succeeded";
if (Report.NumberOfWarnings > 1)
success += " with " + Report.NumberOfWarnings + " warnings";
else if (Report.NumberOfWarnings == 1)
success += " with 1 warning";
Console.WriteLine(success);
}
catch (Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
示例6: Main
//.........这里部分代码省略.........
}
catch (Exception) {
Report.Error(001, sourceFile.FullName);
return;
}
// other options
int outputTarget = 0;
foreach (string option in desiredOptions) {
// out option
if (option.StartsWith("out:")) {
outputFilename = option.Remove(0, 4);
if (outputFilename.IndexOf('\\') != -1 || outputFilename.IndexOf('/') != -1) {
Report.Error(003, outputFilename);
return;
}
if (!outputFilename.EndsWith(".exe"))
outputFilename = outputFilename + ".exe";
}
// target option
if (option.StartsWith("target:") || option.StartsWith("t:")) {
string desiredTarget;
if (option.StartsWith("target:"))
desiredTarget = option.Remove(0, 7);
else
desiredTarget = option.Remove(0, 2);
if (desiredTarget == "exe")
outputTarget = PEmitter.EXE;
else if (desiredTarget == "library")
outputTarget = PEmitter.LIBRARY;
else {
Report.Error(005, desiredTarget);
return;
}
PEmitter.target = outputTarget;
}
// nowarn option
if (option == "nowarn") {
Report.warningsEnabled = false;
}
}
// if no output file specified, use and modify souce file name
if (outputFilename == null) {
string extension = null;
if (outputTarget == PEmitter.EXE)
extension = ".exe";
else if (outputTarget == PEmitter.LIBRARY)
extension = ".dll";
int indexLastDot = sourceFile.Name.LastIndexOf('.');
if (indexLastDot == -1)
outputFilename = sourceFile.Name + extension;
else
outputFilename = sourceFile.Name.Substring(0, indexLastDot) + extension;
}
// set formatting to US Amiercan (needed e.g. for type Double)
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
// initialize parser
Console.WriteLine("Parsing from file " + sourceFile.FullName + "...");
Parser yy = new Parser(new Scanner(sourceFileStreamReader));
// parse input stream
AST ast = (AST)yy.parse().value;
// set output filename
PEmitter.fileName = outputFilename;
// transform AST to create class __MAIN and function __MAIN()
//Console.WriteLine("Working on class __MAIN and function __MAIN()...");
new MainMethodVisitor().Visit(ast);
// ensure every class (except __MAIN) has a constructor
//Console.WriteLine("Working on constructors...");
new ConstructorVisitor().Visit(ast);
// ensure every method has a return statement and cut unreachable statements after a return
//Console.WriteLine("Working on return statements...");
new ReturnStatementVisitor().Visit(ast);
// ensure there is no break/continue without a loop
//Console.WriteLine("Working on loops...");
new LoopVisitor().Visit(ast);
// reorder class declarations by inheritance
//Console.WriteLine("Working on interitance...");
new InheritanceVisitor().Visit(ast);
// collect all delcarations which may be called before being declared
//Console.WriteLine("Working on declarations...");
new DeclarationsVisitor().Visit(ast);
// build symbol table
//Console.WriteLine("Building symbol table...");
new SymbolTableVisitor().Visit(ast);
// emit CIL code
//Console.WriteLine("Emitting CIL code...");
new EmitterVisitor().Visit(ast);
// report success
string success = "Compiling to file " + Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + outputFilename + " succeeded";
if (Report.numberOfWarnings > 1)
success += " with " + Report.numberOfWarnings + " warnings";
else if (Report.numberOfWarnings == 1)
success += " with 1 warning";
Console.WriteLine(success);
}
catch (System.Exception e) {
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}