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 ...
随机推荐
- 03 java 基础:注释 关键字 标识符 JShell
Java 10 中已有 Jshell 工具,方便用户在其中直接输入相关 java 代码. 注释:java 中分为单行注释 // 多行注释 /* */ 文档注释 /** */ 关键字:在 ...
- Aras Innovator DB备份与还原
错误信息 确认到该问题是因为孤立帐号的问题,在解决孤立帐号之前,可以通过语句查看,另外,还原了DB后,系统不会自动创建原来的登陆帐号的,需要手动新增登陆帐号 #查看孤立帐号列表exec sp_chan ...
- 【转载】RecyclerView源码解析
原文地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0307/4032.html 概述 之前面试的时候经常有人问是否用过Re ...
- SQL练习总结
[SQL语句练习] 1. 表1: Person +-------------+---------+ | 列名 | 类型 | +-------------+---------+ | PersonId | ...
- CodeVS1169 传纸条 [DP补完计划]
题目传送门 题目描述 Description 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端, ...
- go chapter 8 - 初始化对象
http://blog.haohtml.com/archives/14239 struct定义的属性如果是小写开头的,那么该属性不是public的,不能跨包调用 (implicit assignmen ...
- 线段树+扫描线【bzoj1645】[USACO07OPEN]城市的地平线City Horizon
Description 约翰带着奶牛去都市观光.在落日的余晖里,他们看到了一幢接一幢的摩天高楼的轮廓在地平线 上形成美丽的图案.以地平线为 X 轴,每幢高楼的轮廓是一个位于地平线上的矩形,彼此间可能有 ...
- 树链剖分【CF165D】Beard Graph
Description 给定一棵树,有m次操作. 1 x 把第x条边染成黑色 2 x 把第x条边染成白色 3 x y 查询x~y之间的黑边数,存在白边输出-1 Input 第1行为一个整数\(n\), ...
- HZAU 1203 One Stroke(倍增)
题目链接:http://acm.hzau.edu.cn/problem.php?id=1203 [题意]给你一颗完全二叉树每个节点都有一个权值,然后要你从上往下找一条链,值得链上权值的和<K,且 ...
- ASP.NET总结——更改后
这篇重新整理的总结,我做了很久,也在草稿箱中放了很久,一直感觉没有达到和老师谈话后的水平,感觉还是需要增加一些修改,希望读者能提出宝贵意见.既这篇博客之前,我发表了一篇ASP.net的总结,在结构上, ...