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的更多相关文章

  1. CocoSourcesCS 3

    CocoSourcesCS 3 /*---------------------------------------------------------------------- Compiler Ge ...

  2. CocoSourcesCS 2

    CocoSourcesCS 2 /*------------------------------------------------------------------------- DFA.cs - ...

  3. CocoSourcesCS 4

    /*------------------------------------------------------------------------- ParserGen.cs -- Generati ...

随机推荐

  1. Power BI连接至Mogo Altas Connector For BI

    我需要使用Power BI连接至Connector For BI ,现在Connect For BI存放在Mongo Atlas中,详细的来自于官方文档,https://docs.atlas.mong ...

  2. 一个Apache安装多个版本的PHP

    我的服务器centos6.5安装了xampp,php6.5版本的.已经有好几个网站在上面运行了,但是后面要安装该死的ecshop,无奈要装php5.2,因此就想如何能在一个apache上安装多个版本的 ...

  3. WebService的网络协议

    SOAP协议.XML-RPC以及Hessian 是WebService的主要传输(编码)协议 SOAP即简单对象访问协议(Simple Object Access Protocol),它是用于交换XM ...

  4. 开发Android逆向工具

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha  313134555@qq.com 源代码及演示程序,请点击这里下载 下载地址: [北方网通]    [电信网通] [下载说明] ...

  5. [Arc074E] RGB Sequence

    [Arc074E] RGB Sequence Description 今天也在愉快地玩Minecraft!现在MM有一块1?N的空地,每个格子按照顺序标记为1到N.MM想要在这块空地上铺上红石块.绿宝 ...

  6. 【贪心】hdu5969 最大的位或

    对于右端点r和左端点l,考虑他们的二进制位从高到低,直到第一位不同的为止. 更高的都取成相同的,更低的都取成1. 比如 101011110001 101011101001 101011111111 # ...

  7. python3-开发进阶Django-form组件中model form组件

    Django的model form组件 这是一个神奇的组件,通过名字我们可以看出来,这个组件的功能就是把model和form组合起来,先来一个简单的例子来看一下这个东西怎么用:比如我们的数据库中有这样 ...

  8. [PKUSC2018]真实排名

    [PKUSC2018]真实排名 题目大意: 有\(n(n\le10^5)\)个人,每个人有一个成绩\(A_i(0\le A_i\le10^9)\).定义一个人的排名为\(n\)个人中成绩不小于他的总人 ...

  9. Activit(活动)实践--知晓当前活动

    实际上,我们可能用的不是自己写的项目,而是从别人那里接手过来的代码,因为你刚进公司就有一个新项目开始的概率十分低.阅读别人代码时会有一个很头疼的问题,就是当你需要在某个界面上修改一些非常简单的东西时, ...

  10. Problem G: 部分复制字符串

    #include <stdio.h> #include <string.h> int main() { void copystr(char *,char *,int); int ...