CocoSourcesCS 1
CocoSourcesCS 1
/*-------------------------------------------------------------------------
Compiler Generator Coco/R,
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
extended by M. Loeberbauer & A. Woess, Univ. of Linz
with improvements by Pat Terry, Rhodes University This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version. This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details. You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As an exception, it is allowed to write an extension of Coco/R that is
used as a plugin in non-free software. If not otherwise stated, any source code generated by Coco/R (other than
Coco/R itself) does not fall under the GNU General Public License.
-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------
Trace output options
0 | A: prints the states of the scanner automaton
1 | F: prints the First and Follow sets of all nonterminals
2 | G: prints the syntax graph of the productions
3 | I: traces the computation of the First sets
4 | J: prints the sets associated with ANYs and synchronisation sets
6 | S: prints the symbol table (terminals, nonterminals, pragmas)
7 | X: prints a cross reference list of all syntax symbols
8 | P: prints statistics about the Coco run Trace output can be switched on by the pragma
$ { digit | letter }
in the attributed grammar or as a command-line option
-------------------------------------------------------------------------*/ using System;
using System.IO; namespace at.jku.ssw.Coco { public class Coco { public static int Main (string[] arg) {
Console.WriteLine("Coco/R (Apr 19, 2011)");
string srcName = null, nsName = null, frameDir = null, ddtString = null,
traceFileName = null, outDir = null;
bool emitLines = false;
int retVal = ;
for (int i = ; i < arg.Length; i++) {
if (arg[i] == "-namespace" && i < arg.Length - ) nsName = arg[++i].Trim();
else if (arg[i] == "-frames" && i < arg.Length - ) frameDir = arg[++i].Trim();
else if (arg[i] == "-trace" && i < arg.Length - ) ddtString = arg[++i].Trim();
else if (arg[i] == "-o" && i < arg.Length - ) outDir = arg[++i].Trim();
else if (arg[i] == "-lines") emitLines = true;
else srcName = arg[i];
}
if (arg.Length > && srcName != null) {
try {
string srcDir = Path.GetDirectoryName(srcName); Scanner scanner = new Scanner(srcName);
Parser parser = new Parser(scanner); traceFileName = Path.Combine(srcDir, "trace.txt");
parser.trace = new StreamWriter(new FileStream(traceFileName, FileMode.Create));
parser.tab = new Tab(parser);
parser.dfa = new DFA(parser);
parser.pgen = new ParserGen(parser); parser.tab.srcName = srcName;
parser.tab.srcDir = srcDir;
parser.tab.nsName = nsName;
parser.tab.frameDir = frameDir;
parser.tab.outDir = (outDir != null) ? outDir : srcDir;
parser.tab.emitLines = emitLines;
if (ddtString != null) parser.tab.SetDDT(ddtString); parser.Parse(); parser.trace.Close();
FileInfo f = new FileInfo(traceFileName);
if (f.Length == ) f.Delete();
else Console.WriteLine("trace output is in " + traceFileName);
Console.WriteLine("{0} errors detected", parser.errors.count);
if (parser.errors.count == ) { retVal = ; }
} catch (IOException) {
Console.WriteLine("-- could not open " + traceFileName);
} catch (FatalError e) {
Console.WriteLine("-- " + e.Message);
}
} else {
Console.WriteLine("Usage: Coco Grammar.ATG {{Option}}{0}"
+ "Options:{0}"
+ " -namespace <namespaceName>{0}"
+ " -frames <frameFilesDirectory>{0}"
+ " -trace <traceString>{0}"
+ " -o <outputDirectory>{0}"
+ " -lines{0}"
+ "Valid characters in the trace string:{0}"
+ " A trace automaton{0}"
+ " F list first/follow sets{0}"
+ " G print syntax graph{0}"
+ " I trace computation of first sets{0}"
+ " J list ANY and SYNC sets{0}"
+ " P print statistics{0}"
+ " S list symbol table{0}"
+ " X list cross reference table{0}"
+ "Scanner.frame and Parser.frame files needed in ATG directory{0}"
+ "or in a directory specified in the -frames option.",
Environment.NewLine);
}
return retVal;
} } // end Coco } // end namespace
CocoSourcesCS 1的更多相关文章
- CocoSourcesCS 3
CocoSourcesCS 3 /*---------------------------------------------------------------------- Compiler Ge ...
- CocoSourcesCS 2
CocoSourcesCS 2 /*------------------------------------------------------------------------- DFA.cs - ...
- CocoSourcesCS 4
/*------------------------------------------------------------------------- ParserGen.cs -- Generati ...
随机推荐
- Linux用户和用户组的初步知识
用户组相关:在Linux系统下,当创建一个如叫tom的用户,那么系统同时会创建一个叫tom的用户组linux中用户的信息都是放在/etc/passwd下的,用户的密码经过加密后放在/etc/shado ...
- 学习LoadRunner之C语言函数
学习LoadRunner之C语言函数 Action() { /*strchr和strrchr的区别*/ /* char *strTest1="citms citms"; char ...
- 【ASP.NET MVC】提高页面加载速度:脚本优化
在这里我们说一下脚本优化的三个方法: 一.在我们做Web开发的时候,当我们引用Js文件的时候,我们一般会将js文件放在文档的head标签中,这时当页面加载的时候,浏览器会按着由上到下的顺序,当浏览器遇 ...
- Attacking JavaScript Engines: A case study of JavaScriptCore and CVE-2016-4622(转)
转:http://phrack.org/papers/attacking_javascript_engines.html Title : Attacking JavaScript Engines: A ...
- php漏洞tips
1.php后缀限制 'php,php3,php4,php5,php6,php7,phpsh,inc,phtml','PHT'; 2.php木马 <?php echo shell_exec($_G ...
- UGUI的优点新UI系统三效率高效果好
UGUI的优点新UI系统三效率高效果好 通过对批处理(batching).纹理图集(texture atlasing)和新的canvas组件的支持,新UI系统提供了一个经过优化的解决方案,使得开发者添 ...
- BZOJ 2888 资源运输(启发式合并LCT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2888 [题目大意] 不断加边,问每个连通块的重心到其它点的距离和的和 [题解] 启发式 ...
- xcode在调试时无法查看变量值
现象:在xcode中调试程序的时候,无论是鼠标指在变量上,还是在gdb中po命令都看不到内存中变量的值. 解决办法:在Project的Build中把 Optimization Level 设置成 No ...
- 使用 Google Code Prettify 实现代码高亮
今天这篇文章主要讲述使用 google-code-prettify 来实现代码的高亮显示,以前我使用 highlight.js 来实现文章中代码的高亮显示. prettify 非常小巧且配置简单,使用 ...
- SNAT的作用是什么
SNAT,可能有人觉得奇怪,好好的为什么要进行ip地址转换啊,为了弄懂这个问题,我们要看一下局域网用户上公网的原理,假设内网主机A(192.168.2.8)要和外网主机B(61.132.62.131) ...