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. AC日记——聪明的质监员 洛谷 P1314

    聪明的质监员 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define l ...

  2. react native android应用启动画面

    参考地址:https://www.youtube.com/watch?v=rnLR65OGtic 第一步:生成启动画面的背景图片 生成一个2048*2048的背景图片,打开网站https://apet ...

  3. android ListView 在初始化时多次调用getView()原因分析

    今天在做一个功能:在初始化ListView时,把第一行背景置为黄色,同时保存第一行对象,用于在点击其他行时将该行重新置为白色. if(position==0){ convertView.setBack ...

  4. thinkphp之url的seo优化

    1.网站url做seo优化的原因 SEO是由英文Search Engine Optimization缩写而来, 中文意译为“搜索引擎优化”.SEO是指通过对网站进行站内优化(网站结构调整.网站内容建设 ...

  5. Eclipse generate javadoc

    注:若遇到导出文档乱码,则点击上图的[next]按钮,在vm options的输入框输入 -J-Xmx180m        —- 设置内存大小 (若遇到内存溢出时) -encoding utf-8 ...

  6. cookies和session区别

    session原理:1.session是保存在服务器端,理论上是没有是没有限制,只要你的内存够大   2.浏览器第一次访问服务器时会创建一个session对象并返回一个JSESSIONID=ID的值, ...

  7. Java 获取JVM内存和物理内存信息

    package com.sysinfo; public class MonitorInfo { /** jvm可使用内存. */ private long totalMemory; /** jvm剩余 ...

  8. [BZOJ4003][JLOI2015]城池攻占(左偏树)

    这题有多种做法,一种是倍增预处理出每个点往上走2^i步最少需要的初始战斗力,一种是裸的启发式合并带标记splay. 每个点合并能攻占其儿子的所有骑士,删去所有无法攻占这个城市的骑士并记录答案. 注意到 ...

  9. [NOIp2016提高组]换教室

    题目大意: 有n节课,第i节课在c[i]上课,同时d[i]也有一节课d[i]. 你有权利向教务处发出m次申请把自己的教室改到d[i],相应的批准概率是k[i]. 教室是图上的一些点,其中每条边都有边权 ...

  10. 输入sql语句,将结果写入到xml文件

    import java.io.FileOutputStream; import java.sql.Connection; import java.sql.DriverManager; import j ...