CocoSourcesCS 3

 /*----------------------------------------------------------------------
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.
-----------------------------------------------------------------------*/
using System.IO; using System; namespace at.jku.ssw.Coco { public class Parser {
public const int _EOF = ;
public const int _ident = ;
public const int _number = ;
public const int _string = ;
public const int _badString = ;
public const int _char = ;
public const int maxT = ;
public const int _ddtSym = ;
public const int _optionSym = ; const bool _T = true;
const bool _x = false;
const int minErrDist = ; public Scanner scanner;
public Errors errors; public Token t; // last recognized token
public Token la; // lookahead token
int errDist = minErrDist; const int id = ;
const int str = ; public TextWriter trace; // other Coco objects referenced in this ATG
public Tab tab;
public DFA dfa;
public ParserGen pgen; bool genScanner;
string tokenString; // used in declarations of literal tokens
string noString = "-none-"; // used in declarations of literal tokens /*-------------------------------------------------------------------------*/ public Parser(Scanner scanner) {
this.scanner = scanner;
errors = new Errors();
} void SynErr (int n) {
if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n);
errDist = ;
} public void SemErr (string msg) {
if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg);
errDist = ;
} void Get () {
for (;;) {
t = la;
la = scanner.Scan();
if (la.kind <= maxT) { ++errDist; break; }
if (la.kind == ) {
tab.SetDDT(la.val);
}
if (la.kind == ) {
tab.SetOption(la.val);
} la = t;
}
} void Expect (int n) {
if (la.kind==n) Get(); else { SynErr(n); }
} bool StartOf (int s) {
return set[s, la.kind];
} void ExpectWeak (int n, int follow) {
if (la.kind == n) Get();
else {
SynErr(n);
while (!StartOf(follow)) Get();
}
} bool WeakSeparator(int n, int syFol, int repFol) {
int kind = la.kind;
if (kind == n) {Get(); return true;}
else if (StartOf(repFol)) {return false;}
else {
SynErr(n);
while (!(set[syFol, kind] || set[repFol, kind] || set[, kind])) {
Get();
kind = la.kind;
}
return StartOf(syFol);
}
} void Coco() {
Symbol sym; Graph g, g1, g2; string gramName; CharSet s; int beg, line;
if (StartOf()) {
Get();
beg = t.pos; line = t.line;
while (StartOf()) {
Get();
}
pgen.usingPos = new Position(beg, la.pos, , line);
}
Expect();
genScanner = true;
tab.ignored = new CharSet();
Expect();
gramName = t.val;
beg = la.pos; line = la.line; while (StartOf()) {
Get();
}
tab.semDeclPos = new Position(beg, la.pos, , line);
if (la.kind == ) {
Get();
dfa.ignoreCase = true;
}
if (la.kind == ) {
Get();
while (la.kind == ) {
SetDecl();
}
}
if (la.kind == ) {
Get();
while (la.kind == || la.kind == || la.kind == ) {
TokenDecl(Node.t);
}
}
if (la.kind == ) {
Get();
while (la.kind == || la.kind == || la.kind == ) {
TokenDecl(Node.pr);
}
}
while (la.kind == ) {
Get();
bool nested = false;
Expect();
TokenExpr(out g1);
Expect();
TokenExpr(out g2);
if (la.kind == ) {
Get();
nested = true;
}
dfa.NewComment(g1.l, g2.l, nested);
}
while (la.kind == ) {
Get();
Set(out s);
tab.ignored.Or(s);
}
while (!(la.kind == || la.kind == )) {SynErr(); Get();}
Expect();
if (genScanner) dfa.MakeDeterministic();
tab.DeleteNodes(); while (la.kind == ) {
Get();
sym = tab.FindSym(t.val);
bool undef = sym == null;
if (undef) sym = tab.NewSym(Node.nt, t.val, t.line);
else {
if (sym.typ == Node.nt) {
if (sym.graph != null) SemErr("name declared twice");
} else SemErr("this symbol kind not allowed on left side of production");
sym.line = t.line;
}
bool noAttrs = sym.attrPos == null;
sym.attrPos = null; if (la.kind == || la.kind == ) {
AttrDecl(sym);
}
if (!undef)
if (noAttrs != (sym.attrPos == null))
SemErr("attribute mismatch between declaration and use of this symbol"); if (la.kind == ) {
SemText(out sym.semPos);
}
ExpectWeak(, );
Expression(out g);
sym.graph = g.l;
tab.Finish(g); ExpectWeak(, );
}
Expect();
Expect();
if (gramName != t.val)
SemErr("name does not match grammar name");
tab.gramSy = tab.FindSym(gramName);
if (tab.gramSy == null)
SemErr("missing production for grammar name");
else {
sym = tab.gramSy;
if (sym.attrPos != null)
SemErr("grammar symbol must not have attributes");
}
tab.noSym = tab.NewSym(Node.t, "???", ); // noSym gets highest number
tab.SetupAnys();
tab.RenumberPragmas();
if (tab.ddt[]) tab.PrintNodes();
if (errors.count == ) {
Console.WriteLine("checking");
tab.CompSymbolSets();
if (tab.ddt[]) tab.XRef();
if (tab.GrammarOk()) {
Console.Write("parser");
pgen.WriteParser();
if (genScanner) {
Console.Write(" + scanner");
dfa.WriteScanner();
if (tab.ddt[]) dfa.PrintStates();
}
Console.WriteLine(" generated");
if (tab.ddt[]) pgen.WriteStatistics();
}
}
if (tab.ddt[]) tab.PrintSymbolTable(); Expect();
} void SetDecl() {
CharSet s;
Expect();
string name = t.val;
CharClass c = tab.FindCharClass(name);
if (c != null) SemErr("name declared twice"); Expect();
Set(out s);
if (s.Elements() == ) SemErr("character set must not be empty");
tab.NewCharClass(name, s); Expect();
} void TokenDecl(int typ) {
string name; int kind; Symbol sym; Graph g;
Sym(out name, out kind);
sym = tab.FindSym(name);
if (sym != null) SemErr("name declared twice");
else {
sym = tab.NewSym(typ, name, t.line);
sym.tokenKind = Symbol.fixedToken;
}
tokenString = null; while (!(StartOf())) {SynErr(); Get();}
if (la.kind == ) {
Get();
TokenExpr(out g);
Expect();
if (kind == str) SemErr("a literal must not be declared with a structure");
tab.Finish(g);
if (tokenString == null || tokenString.Equals(noString))
dfa.ConvertToStates(g.l, sym);
else { // TokenExpr is a single string
if (tab.literals[tokenString] != null)
SemErr("token string declared twice");
tab.literals[tokenString] = sym;
dfa.MatchLiteral(tokenString, sym);
} } else if (StartOf()) {
if (kind == id) genScanner = false;
else dfa.MatchLiteral(sym.name, sym); } else SynErr();
if (la.kind == ) {
SemText(out sym.semPos);
if (typ != Node.pr) SemErr("semantic action not allowed here");
}
} void TokenExpr(out Graph g) {
Graph g2;
TokenTerm(out g);
bool first = true;
while (WeakSeparator(,,) ) {
TokenTerm(out g2);
if (first) { tab.MakeFirstAlt(g); first = false; }
tab.MakeAlternative(g, g2); }
} void Set(out CharSet s) {
CharSet s2;
SimSet(out s);
while (la.kind == || la.kind == ) {
if (la.kind == ) {
Get();
SimSet(out s2);
s.Or(s2);
} else {
Get();
SimSet(out s2);
s.Subtract(s2);
}
}
} void AttrDecl(Symbol sym) {
if (la.kind == ) {
Get();
int beg = la.pos; int col = la.col; int line = la.line;
while (StartOf()) {
if (StartOf()) {
Get();
} else {
Get();
SemErr("bad string in attributes");
}
}
Expect();
if (t.pos > beg)
sym.attrPos = new Position(beg, t.pos, col, line);
} else if (la.kind == ) {
Get();
int beg = la.pos; int col = la.col; int line = la.line;
while (StartOf()) {
if (StartOf()) {
Get();
} else {
Get();
SemErr("bad string in attributes");
}
}
Expect();
if (t.pos > beg)
sym.attrPos = new Position(beg, t.pos, col, line);
} else SynErr();
} void SemText(out Position pos) {
Expect();
int beg = la.pos; int col = la.col; int line = la.line;
while (StartOf()) {
if (StartOf()) {
Get();
} else if (la.kind == ) {
Get();
SemErr("bad string in semantic action");
} else {
Get();
SemErr("missing end of previous semantic action");
}
}
Expect();
pos = new Position(beg, t.pos, col, line);
} void Expression(out Graph g) {
Graph g2;
Term(out g);
bool first = true;
while (WeakSeparator(,,) ) {
Term(out g2);
if (first) { tab.MakeFirstAlt(g); first = false; }
tab.MakeAlternative(g, g2); }
} void SimSet(out CharSet s) {
int n1, n2;
s = new CharSet();
if (la.kind == ) {
Get();
CharClass c = tab.FindCharClass(t.val);
if (c == null) SemErr("undefined name"); else s.Or(c.set); } else if (la.kind == ) {
Get();
string name = t.val;
name = tab.Unescape(name.Substring(, name.Length-));
foreach (char ch in name)
if (dfa.ignoreCase) s.Set(char.ToLower(ch));
else s.Set(ch);
} else if (la.kind == ) {
Char(out n1);
s.Set(n1);
if (la.kind == ) {
Get();
Char(out n2);
for (int i = n1; i <= n2; i++) s.Set(i);
}
} else if (la.kind == ) {
Get();
s = new CharSet(); s.Fill();
} else SynErr();
} void Char(out int n) {
Expect();
string name = t.val; n = ;
name = tab.Unescape(name.Substring(, name.Length-));
if (name.Length == ) n = name[];
else SemErr("unacceptable character value");
if (dfa.ignoreCase && (char)n >= 'A' && (char)n <= 'Z') n += ; } void Sym(out string name, out int kind) {
name = "???"; kind = id;
if (la.kind == ) {
Get();
kind = id; name = t.val;
} else if (la.kind == || la.kind == ) {
if (la.kind == ) {
Get();
name = t.val;
} else {
Get();
name = "\"" + t.val.Substring(, t.val.Length-) + "\"";
}
kind = str;
if (dfa.ignoreCase) name = name.ToLower();
if (name.IndexOf(' ') >= )
SemErr("literal tokens must not contain blanks");
} else SynErr();
} void Term(out Graph g) {
Graph g2; Node rslv = null; g = null;
if (StartOf()) {
if (la.kind == ) {
rslv = tab.NewNode(Node.rslv, null, la.line);
Resolver(out rslv.pos);
g = new Graph(rslv);
}
Factor(out g2);
if (rslv != null) tab.MakeSequence(g, g2);
else g = g2; while (StartOf()) {
Factor(out g2);
tab.MakeSequence(g, g2);
}
} else if (StartOf()) {
g = new Graph(tab.NewNode(Node.eps, null, ));
} else SynErr();
if (g == null) // invalid start of Term
g = new Graph(tab.NewNode(Node.eps, null, )); } void Resolver(out Position pos) {
Expect();
Expect();
int beg = la.pos; int col = la.col; int line = la.line;
Condition();
pos = new Position(beg, t.pos, col, line);
} void Factor(out Graph g) {
string name; int kind; Position pos; bool weak = false;
g = null; switch (la.kind) {
case : case : case : case : {
if (la.kind == ) {
Get();
weak = true;
}
Sym(out name, out kind);
Symbol sym = tab.FindSym(name);
if (sym == null && kind == str)
sym = tab.literals[name] as Symbol;
bool undef = sym == null;
if (undef) {
if (kind == id)
sym = tab.NewSym(Node.nt, name, ); // forward nt
else if (genScanner) {
sym = tab.NewSym(Node.t, name, t.line);
dfa.MatchLiteral(sym.name, sym);
} else { // undefined string in production
SemErr("undefined string in production");
sym = tab.eofSy; // dummy
}
}
int typ = sym.typ;
if (typ != Node.t && typ != Node.nt)
SemErr("this symbol kind is not allowed in a production");
if (weak)
if (typ == Node.t) typ = Node.wt;
else SemErr("only terminals may be weak");
Node p = tab.NewNode(typ, sym, t.line);
g = new Graph(p); if (la.kind == || la.kind == ) {
Attribs(p);
if (kind != id) SemErr("a literal must not have attributes");
}
if (undef)
sym.attrPos = p.pos; // dummy
else if ((p.pos == null) != (sym.attrPos == null))
SemErr("attribute mismatch between declaration and use of this symbol"); break;
}
case : {
Get();
Expression(out g);
Expect();
break;
}
case : {
Get();
Expression(out g);
Expect();
tab.MakeOption(g);
break;
}
case : {
Get();
Expression(out g);
Expect();
tab.MakeIteration(g);
break;
}
case : {
SemText(out pos);
Node p = tab.NewNode(Node.sem, null, );
p.pos = pos;
g = new Graph(p); break;
}
case : {
Get();
Node p = tab.NewNode(Node.any, null, ); // p.set is set in tab.SetupAnys
g = new Graph(p); break;
}
case : {
Get();
Node p = tab.NewNode(Node.sync, null, );
g = new Graph(p); break;
}
default: SynErr(); break;
}
if (g == null) // invalid start of Factor
g = new Graph(tab.NewNode(Node.eps, null, )); } void Attribs(Node p) {
if (la.kind == ) {
Get();
int beg = la.pos; int col = la.col; int line = la.line;
while (StartOf()) {
if (StartOf()) {
Get();
} else {
Get();
SemErr("bad string in attributes");
}
}
Expect();
if (t.pos > beg) p.pos = new Position(beg, t.pos, col, line);
} else if (la.kind == ) {
Get();
int beg = la.pos; int col = la.col; int line = la.line;
while (StartOf()) {
if (StartOf()) {
Get();
} else {
Get();
SemErr("bad string in attributes");
}
}
Expect();
if (t.pos > beg) p.pos = new Position(beg, t.pos, col, line);
} else SynErr();
} void Condition() {
while (StartOf()) {
if (la.kind == ) {
Get();
Condition();
} else {
Get();
}
}
Expect();
} void TokenTerm(out Graph g) {
Graph g2;
TokenFactor(out g);
while (StartOf()) {
TokenFactor(out g2);
tab.MakeSequence(g, g2);
}
if (la.kind == ) {
Get();
Expect();
TokenExpr(out g2);
tab.SetContextTrans(g2.l); dfa.hasCtxMoves = true;
tab.MakeSequence(g, g2);
Expect();
}
} void TokenFactor(out Graph g) {
string name; int kind;
g = null;
if (la.kind == || la.kind == || la.kind == ) {
Sym(out name, out kind);
if (kind == id) {
CharClass c = tab.FindCharClass(name);
if (c == null) {
SemErr("undefined name");
c = tab.NewCharClass(name, new CharSet());
}
Node p = tab.NewNode(Node.clas, null, ); p.val = c.n;
g = new Graph(p);
tokenString = noString;
} else { // str
g = tab.StrToGraph(name);
if (tokenString == null) tokenString = name;
else tokenString = noString;
} } else if (la.kind == ) {
Get();
TokenExpr(out g);
Expect();
} else if (la.kind == ) {
Get();
TokenExpr(out g);
Expect();
tab.MakeOption(g); tokenString = noString;
} else if (la.kind == ) {
Get();
TokenExpr(out g);
Expect();
tab.MakeIteration(g); tokenString = noString;
} else SynErr();
if (g == null) // invalid start of TokenFactor
g = new Graph(tab.NewNode(Node.eps, null, ));
} public void Parse() {
la = new Token();
la.val = "";
Get();
Coco();
Expect(); } static readonly bool[,] set = {
{_T,_T,_x,_T, _x,_T,_x,_x, _x,_x,_T,_T, _x,_x,_x,_T, _T,_T,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_T, _x,_x,_x},
{_x,_T,_T,_T, _T,_T,_x,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_x},
{_x,_T,_T,_T, _T,_T,_T,_x, _x,_x,_x,_x, _T,_T,_T,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},
{_x,_T,_x,_T, _x,_T,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_T, _x,_x,_x,_x, _x,_T,_T,_x, _T,_x,_T,_x, _T,_x,_x,_T, _x,_x,_x},
{_x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_x,_x, _x,_x,_T,_x, _x,_x,_x,_x, _x,_x,_x,_x, _T,_x,_x,_T, _x,_T,_x,_T, _x,_x,_x,_x, _x,_x,_x},
{_x,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_T,_x, _T,_T,_T,_T, _T,_T,_T,_T, _T,_T,_x} };
} // end Parser public class Errors {
public int count = ; // number of errors detected
public System.IO.TextWriter errorStream = Console.Out; // error messages go to this stream
public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text public virtual void SynErr (int line, int col, int n) {
string s;
switch (n) {
case : s = "EOF expected"; break;
case : s = "ident expected"; break;
case : s = "number expected"; break;
case : s = "string expected"; break;
case : s = "badString expected"; break;
case : s = "char expected"; break;
case : s = "\"COMPILER\" expected"; break;
case : s = "\"IGNORECASE\" expected"; break;
case : s = "\"CHARACTERS\" expected"; break;
case : s = "\"TOKENS\" expected"; break;
case : s = "\"PRAGMAS\" expected"; break;
case : s = "\"COMMENTS\" expected"; break;
case : s = "\"FROM\" expected"; break;
case : s = "\"TO\" expected"; break;
case : s = "\"NESTED\" expected"; break;
case : s = "\"IGNORE\" expected"; break;
case : s = "\"PRODUCTIONS\" expected"; break;
case : s = "\"=\" expected"; break;
case : s = "\".\" expected"; break;
case : s = "\"END\" expected"; break;
case : s = "\"+\" expected"; break;
case : s = "\"-\" expected"; break;
case : s = "\"..\" expected"; break;
case : s = "\"ANY\" expected"; break;
case : s = "\"<\" expected"; break;
case : s = "\">\" expected"; break;
case : s = "\"<.\" expected"; break;
case : s = "\".>\" expected"; break;
case : s = "\"|\" expected"; break;
case : s = "\"WEAK\" expected"; break;
case : s = "\"(\" expected"; break;
case : s = "\")\" expected"; break;
case : s = "\"[\" expected"; break;
case : s = "\"]\" expected"; break;
case : s = "\"{\" expected"; break;
case : s = "\"}\" expected"; break;
case : s = "\"SYNC\" expected"; break;
case : s = "\"IF\" expected"; break;
case : s = "\"CONTEXT\" expected"; break;
case : s = "\"(.\" expected"; break;
case : s = "\".)\" expected"; break;
case : s = "??? expected"; break;
case : s = "this symbol not expected in Coco"; break;
case : s = "this symbol not expected in TokenDecl"; break;
case : s = "invalid TokenDecl"; break;
case : s = "invalid AttrDecl"; break;
case : s = "invalid SimSet"; break;
case : s = "invalid Sym"; break;
case : s = "invalid Term"; break;
case : s = "invalid Factor"; break;
case : s = "invalid Attribs"; break;
case : s = "invalid TokenFactor"; break; default: s = "error " + n; break;
}
errorStream.WriteLine(errMsgFormat, line, col, s);
count++;
} public virtual void SemErr (int line, int col, string s) {
errorStream.WriteLine(errMsgFormat, line, col, s);
count++;
} public virtual void SemErr (string s) {
errorStream.WriteLine(s);
count++;
} public virtual void Warning (int line, int col, string s) {
errorStream.WriteLine(errMsgFormat, line, col, s);
} public virtual void Warning(string s) {
errorStream.WriteLine(s);
}
} // Errors public class FatalError: Exception {
public FatalError(string m): base(m) {}
}
}

CocoSourcesCS 3的更多相关文章

  1. CocoSourcesCS 2

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

  2. CocoSourcesCS 1

    CocoSourcesCS 1 /*------------------------------------------------------------------------- Compiler ...

  3. CocoSourcesCS 4

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

随机推荐

  1. Django2.x版本路由系统的正则写法以及视图函数的返回问题

    一.关于url.py urlpatterns每个元素的不再用url(),而是path(),最重要的一点是,正则的使用需要你自己手动导入re_path,并且在每个使用正则匹配的的元素用re_path() ...

  2. Ubuntu 下配置 SSH服务全过程及问题解决

    Windows下做Linux开发,装虚拟机里,怎么可以不用SSH呢.有人说,“做Linux开发,还不直接装机器上跑起来了,还挂虚拟机,开SSH……闲的蛋疼了吧”,不管怎样,我接触Linux算是3年了, ...

  3. Java基础:类加载机制

    之前的<java基础:内存模型>当中,我们大体了解了在java当中,不同类型的信息,都存放于java当中哪个部位当中,那么有了对于堆.栈.方法区.的基本理解以后,今天我们来好好剖析一下,j ...

  4. java中常用的String方法

    1 length()字符串的长度 String a = "Hello Word!"; System.out.println(a.length); 输出的结果是字符串长度10. 2 ...

  5. 转:java-Servlet开发

    转:http://www.cnblogs.com/xdp-gacl/p/3760336.html 一.Servlet简介 Servlet是sun公司提供的一门用于开发动态web资源的技术. Sun公司 ...

  6. 《深入理解Android2》读书笔记(三)

    接上篇<深入理解Android2>读书笔记(二) PackageManagerService PackageManagerService负责系统中Package的管理,应用程序的安装.卸载 ...

  7. 【BZOJ 1084】 1084: [SCOI2005]最大子矩阵 (DP)

    1084: [SCOI2005]最大子矩阵 Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. Input 第 ...

  8. [BZOJ 1857] 传送带

    Link: BZOJ 1857 传送门 Solution: 首先中间的两个拐点$C,D$肯定都在传送带$A,B$上 接下来感性发现固定点A/C,另一个点C/D时间随位置的变化为单峰函数 这样就是三分套 ...

  9. 【FFT(母函数)+容斥】BZOJ3771-Triple

    [题目大意] 给出 n个物品,价值为别为Xi且各不相同,现在可以取1个.2个或3个,问每种价值和有几种情况? *顺序不同算一种 [思路] 显然是个母函数,A表示每种物品取一个的情况,B表示每种物品取二 ...

  10. 【最大流】POJ3236-ACM Computer Factory

    [题意] 装配一个电脑需要P个零件,现在给出N机器的信息,每个机器可以将k个电脑由状态{S1,S2..,Sp}转变为{Q1,Q2..,Qp},问最多能装配多少台电脑以及对应的方案? [思路] 1A.. ...