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 ...
 
随机推荐
- ubuntu上安装mysql及导入导出
			
ubuntu上安装mysql: 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client3. sudo apt-get ...
 - 1. Maven - 开始
			
今天开始记录Maven的学习过程. ☞ 相关明细 操作系统:win7 参考书籍:<maven-definitive-guide_zh>(Maven权威指南) maven版本:3.3.3 ☞ ...
 - 图灵杯 E 简单的RMQ(UVA 11235)(RMQ)
			
E: 简单的RMQ 时间限制: 2 Sec 内存限制: 64 MB提交: 934 解决: 165[提交][状态][讨论版] 题目描述 给定一个数组,其中的元素满足非递减顺序.任意给定一个区间[i, ...
 - JZYZOJ 1385 拉灯游戏 状态压缩 搜索
			
http://172.20.6.3/Problem_Show.asp?id=1385 刚开始想的时候一直以为同一排不同的拉灯顺序对结果是有影响的,手推了好多遍才发现拉灯结果只和拉的灯有关,这也要打 ...
 - [USACO] 2017 DEC Bronze&Silver
			
link:http://www.usaco.org/index.php?page=dec17results Problem A(Bronze) 这是一道非常简单的判断重叠面积的题目,但第一次提交仍会出 ...
 - python 多继承详解
			
class A(object): # A must be new-style class def __init__(self): print "enter A" print &qu ...
 - python学习第九十天:vue补习2
			
Vue 八.重要指令 v-bind <!-- 值a --> <div v-bind:class='"a"'></div> <!-- 变量a ...
 - [转]Windows7下如何在MyEclipse更改JSP默认编码
			
分步阅读 一般情况下,用MyEclipse创建Web项目,在WebRoot目录下新建JSP页面,页面的编码格式是:ISO-8859-1,而这个编码格式不 可以解决多种语言文本显示问题,特别是中文,容易 ...
 - CentOS 6.9下iptables通过raw表实现日志输出和调试
			
说明:iptables调试的最好方式应该是输出日志了.并且iptables有个raw的表,优先级别最好,且调试时针对icmp协议(ping)进行,那么日志输出就是整条链路串起来输出的,非常的清晰. 前 ...
 - 莫名其妙的float:left; 不能使元素紧贴父级的坑
			
这是项目中遇到的一个CSS的坑,做个记录,主要的原因还是浮动后脱离文档流,两个浮动的元素处于同一文档流中会相互影响位置的问题: 先上代码吧: 效果预览地址:浮动不能靠左的情况; 原本红色模块应该处于蓝 ...