--- coco-java-20110419.orig/cocoj +++ coco-java-20110419/cocoj @@ -0,0 +1,3 @@ +#!/bin/sh +java -jar /usr/share/coco-java/Coco.jar "$@" + --- coco-java-20110419.orig/Scanner.java +++ coco-java-20110419/Scanner.java @@ -25,7 +25,7 @@ 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. -------------------------------------------------------------------------*/ -package Coco; +package Coco; import java.io.InputStream; import java.io.IOException; @@ -278,8 +278,8 @@ public class Scanner { static final char EOL = '\n'; static final int eofSym = 0; - static final int maxT = 44; - static final int noSym = 44; + static final int maxT = 44; + static final int noSym = 44; public Buffer buffer; // scanner buffer @@ -304,47 +304,47 @@ static { start = new StartStates(); literals = new HashMap(); - for (int i = 65; i <= 90; ++i) start.set(i, 1); - for (int i = 95; i <= 95; ++i) start.set(i, 1); - for (int i = 97; i <= 122; ++i) start.set(i, 1); - for (int i = 48; i <= 57; ++i) start.set(i, 2); - start.set(34, 12); - start.set(39, 5); - start.set(36, 13); - start.set(61, 16); - start.set(46, 33); - start.set(43, 17); - start.set(45, 18); - start.set(60, 34); - start.set(94, 20); - start.set(62, 21); - start.set(44, 22); - start.set(91, 25); - start.set(93, 26); - start.set(124, 27); - start.set(40, 35); - start.set(41, 28); - start.set(123, 29); - start.set(125, 30); - start.set(Buffer.EOF, -1); - literals.put("COMPILER", new Integer(6)); - literals.put("IGNORECASE", new Integer(7)); - literals.put("CHARACTERS", new Integer(8)); - literals.put("TOKENS", new Integer(9)); - literals.put("PRAGMAS", new Integer(10)); - literals.put("COMMENTS", new Integer(11)); - literals.put("FROM", new Integer(12)); - literals.put("TO", new Integer(13)); - literals.put("NESTED", new Integer(14)); - literals.put("IGNORE", new Integer(15)); - literals.put("PRODUCTIONS", new Integer(16)); - literals.put("END", new Integer(19)); - literals.put("ANY", new Integer(23)); - literals.put("out", new Integer(26)); - literals.put("WEAK", new Integer(34)); - literals.put("SYNC", new Integer(39)); - literals.put("IF", new Integer(40)); - literals.put("CONTEXT", new Integer(41)); + for (int i = 65; i <= 90; ++i) start.set(i, 1); + for (int i = 95; i <= 95; ++i) start.set(i, 1); + for (int i = 97; i <= 122; ++i) start.set(i, 1); + for (int i = 48; i <= 57; ++i) start.set(i, 2); + start.set(34, 12); + start.set(39, 5); + start.set(36, 13); + start.set(61, 16); + start.set(46, 33); + start.set(43, 17); + start.set(45, 18); + start.set(60, 34); + start.set(94, 20); + start.set(62, 21); + start.set(44, 22); + start.set(91, 25); + start.set(93, 26); + start.set(124, 27); + start.set(40, 35); + start.set(41, 28); + start.set(123, 29); + start.set(125, 30); + start.set(Buffer.EOF, -1); + literals.put("COMPILER", new Integer(6)); + literals.put("IGNORECASE", new Integer(7)); + literals.put("CHARACTERS", new Integer(8)); + literals.put("TOKENS", new Integer(9)); + literals.put("PRAGMAS", new Integer(10)); + literals.put("COMMENTS", new Integer(11)); + literals.put("FROM", new Integer(12)); + literals.put("TO", new Integer(13)); + literals.put("NESTED", new Integer(14)); + literals.put("IGNORE", new Integer(15)); + literals.put("PRODUCTIONS", new Integer(16)); + literals.put("END", new Integer(19)); + literals.put("ANY", new Integer(23)); + literals.put("out", new Integer(26)); + literals.put("WEAK", new Integer(34)); + literals.put("SYNC", new Integer(39)); + literals.put("IF", new Integer(40)); + literals.put("CONTEXT", new Integer(41)); } @@ -395,59 +395,59 @@ tval = newBuf; } if (ch != Buffer.EOF) { - tval[tlen++] = (char)ch; + tval[tlen++] = (char)ch; NextCh(); } } - - boolean Comment0() { - int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos; - NextCh(); - if (ch == '/') { - NextCh(); - for(;;) { - if (ch == 10) { - level--; - if (level == 0) { oldEols = line - line0; NextCh(); return true; } - NextCh(); - } else if (ch == Buffer.EOF) return false; - else NextCh(); - } - } else { - buffer.setPos(pos0); NextCh(); line = line0; col = col0; charPos = charPos0; - } - return false; - } - - boolean Comment1() { - int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos; - NextCh(); - if (ch == '*') { - NextCh(); - for(;;) { - if (ch == '*') { - NextCh(); - if (ch == '/') { - level--; - if (level == 0) { oldEols = line - line0; NextCh(); return true; } - NextCh(); - } - } else if (ch == '/') { - NextCh(); - if (ch == '*') { - level++; NextCh(); - } - } else if (ch == Buffer.EOF) return false; - else NextCh(); - } - } else { - buffer.setPos(pos0); NextCh(); line = line0; col = col0; charPos = charPos0; - } - return false; - } + + boolean Comment0() { + int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos; + NextCh(); + if (ch == '/') { + NextCh(); + for(;;) { + if (ch == 10) { + level--; + if (level == 0) { oldEols = line - line0; NextCh(); return true; } + NextCh(); + } else if (ch == Buffer.EOF) return false; + else NextCh(); + } + } else { + buffer.setPos(pos0); NextCh(); line = line0; col = col0; charPos = charPos0; + } + return false; + } + + boolean Comment1() { + int level = 1, pos0 = pos, line0 = line, col0 = col, charPos0 = charPos; + NextCh(); + if (ch == '*') { + NextCh(); + for(;;) { + if (ch == '*') { + NextCh(); + if (ch == '/') { + level--; + if (level == 0) { oldEols = line - line0; NextCh(); return true; } + NextCh(); + } + } else if (ch == '/') { + NextCh(); + if (ch == '*') { + level++; NextCh(); + } + } else if (ch == Buffer.EOF) return false; + else NextCh(); + } + } else { + buffer.setPos(pos0); NextCh(); line = line0; col = col0; charPos = charPos0; + } + return false; + } void CheckLiteral() { @@ -481,110 +481,110 @@ } t.kind = recKind; break loop; } // NextCh already done - case 1: - recEnd = pos; recKind = 1; - if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 1; break;} - else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} - case 2: - recEnd = pos; recKind = 2; - if (ch >= '0' && ch <= '9') {AddCh(); state = 2; break;} - else {t.kind = 2; break loop;} - case 3: - {t.kind = 3; break loop;} - case 4: - {t.kind = 4; break loop;} - case 5: - if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '&' || ch >= '(' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 6; break;} - else if (ch == 92) {AddCh(); state = 7; break;} - else {state = 0; break;} - case 6: - if (ch == 39) {AddCh(); state = 9; break;} - else {state = 0; break;} - case 7: - if (ch >= ' ' && ch <= '~') {AddCh(); state = 8; break;} - else {state = 0; break;} - case 8: - if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); state = 8; break;} - else if (ch == 39) {AddCh(); state = 9; break;} - else {state = 0; break;} - case 9: - {t.kind = 5; break loop;} - case 10: - recEnd = pos; recKind = 45; - if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 10; break;} - else {t.kind = 45; break loop;} - case 11: - recEnd = pos; recKind = 46; - if (ch >= '-' && ch <= '.' || ch >= '0' && ch <= ':' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 11; break;} - else {t.kind = 46; break loop;} - case 12: - if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 12; break;} - else if (ch == 10 || ch == 13) {AddCh(); state = 4; break;} - else if (ch == '"') {AddCh(); state = 3; break;} - else if (ch == 92) {AddCh(); state = 14; break;} - else {state = 0; break;} - case 13: - recEnd = pos; recKind = 45; - if (ch >= '0' && ch <= '9') {AddCh(); state = 10; break;} - else if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 15; break;} - else {t.kind = 45; break loop;} - case 14: - if (ch >= ' ' && ch <= '~') {AddCh(); state = 12; break;} - else {state = 0; break;} - case 15: - recEnd = pos; recKind = 45; - if (ch >= '0' && ch <= '9') {AddCh(); state = 10; break;} - else if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 15; break;} - else if (ch == '=') {AddCh(); state = 11; break;} - else {t.kind = 45; break loop;} - case 16: - {t.kind = 17; break loop;} - case 17: - {t.kind = 20; break loop;} - case 18: - {t.kind = 21; break loop;} - case 19: - {t.kind = 22; break loop;} - case 20: - {t.kind = 25; break loop;} - case 21: - {t.kind = 27; break loop;} - case 22: - {t.kind = 28; break loop;} - case 23: - {t.kind = 29; break loop;} - case 24: - {t.kind = 30; break loop;} - case 25: - {t.kind = 31; break loop;} - case 26: - {t.kind = 32; break loop;} - case 27: - {t.kind = 33; break loop;} - case 28: - {t.kind = 36; break loop;} - case 29: - {t.kind = 37; break loop;} - case 30: - {t.kind = 38; break loop;} - case 31: - {t.kind = 42; break loop;} - case 32: - {t.kind = 43; break loop;} - case 33: - recEnd = pos; recKind = 18; - if (ch == '.') {AddCh(); state = 19; break;} - else if (ch == '>') {AddCh(); state = 24; break;} - else if (ch == ')') {AddCh(); state = 32; break;} - else {t.kind = 18; break loop;} - case 34: - recEnd = pos; recKind = 24; - if (ch == '.') {AddCh(); state = 23; break;} - else {t.kind = 24; break loop;} - case 35: - recEnd = pos; recKind = 35; - if (ch == '.') {AddCh(); state = 31; break;} - else {t.kind = 35; break loop;} + case 1: + recEnd = pos; recKind = 1; + if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 1; break;} + else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} + case 2: + recEnd = pos; recKind = 2; + if (ch >= '0' && ch <= '9') {AddCh(); state = 2; break;} + else {t.kind = 2; break loop;} + case 3: + {t.kind = 3; break loop;} + case 4: + {t.kind = 4; break loop;} + case 5: + if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '&' || ch >= '(' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 6; break;} + else if (ch == 92) {AddCh(); state = 7; break;} + else {state = 0; break;} + case 6: + if (ch == 39) {AddCh(); state = 9; break;} + else {state = 0; break;} + case 7: + if (ch >= ' ' && ch <= '~') {AddCh(); state = 8; break;} + else {state = 0; break;} + case 8: + if (ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'f') {AddCh(); state = 8; break;} + else if (ch == 39) {AddCh(); state = 9; break;} + else {state = 0; break;} + case 9: + {t.kind = 5; break loop;} + case 10: + recEnd = pos; recKind = 45; + if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 10; break;} + else {t.kind = 45; break loop;} + case 11: + recEnd = pos; recKind = 46; + if (ch >= '-' && ch <= '.' || ch >= '0' && ch <= ':' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 11; break;} + else {t.kind = 46; break loop;} + case 12: + if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); state = 12; break;} + else if (ch == 10 || ch == 13) {AddCh(); state = 4; break;} + else if (ch == '"') {AddCh(); state = 3; break;} + else if (ch == 92) {AddCh(); state = 14; break;} + else {state = 0; break;} + case 13: + recEnd = pos; recKind = 45; + if (ch >= '0' && ch <= '9') {AddCh(); state = 10; break;} + else if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 15; break;} + else {t.kind = 45; break loop;} + case 14: + if (ch >= ' ' && ch <= '~') {AddCh(); state = 12; break;} + else {state = 0; break;} + case 15: + recEnd = pos; recKind = 45; + if (ch >= '0' && ch <= '9') {AddCh(); state = 10; break;} + else if (ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); state = 15; break;} + else if (ch == '=') {AddCh(); state = 11; break;} + else {t.kind = 45; break loop;} + case 16: + {t.kind = 17; break loop;} + case 17: + {t.kind = 20; break loop;} + case 18: + {t.kind = 21; break loop;} + case 19: + {t.kind = 22; break loop;} + case 20: + {t.kind = 25; break loop;} + case 21: + {t.kind = 27; break loop;} + case 22: + {t.kind = 28; break loop;} + case 23: + {t.kind = 29; break loop;} + case 24: + {t.kind = 30; break loop;} + case 25: + {t.kind = 31; break loop;} + case 26: + {t.kind = 32; break loop;} + case 27: + {t.kind = 33; break loop;} + case 28: + {t.kind = 36; break loop;} + case 29: + {t.kind = 37; break loop;} + case 30: + {t.kind = 38; break loop;} + case 31: + {t.kind = 42; break loop;} + case 32: + {t.kind = 43; break loop;} + case 33: + recEnd = pos; recKind = 18; + if (ch == '.') {AddCh(); state = 19; break;} + else if (ch == '>') {AddCh(); state = 24; break;} + else if (ch == ')') {AddCh(); state = 32; break;} + else {t.kind = 18; break loop;} + case 34: + recEnd = pos; recKind = 24; + if (ch == '.') {AddCh(); state = 23; break;} + else {t.kind = 24; break loop;} + case 35: + recEnd = pos; recKind = 35; + if (ch == '.') {AddCh(); state = 31; break;} + else {t.kind = 35; break loop;} } } --- coco-java-20110419.orig/Makefile +++ coco-java-20110419/Makefile @@ -0,0 +1,13 @@ +all: + javac -d . -source 1.4 -target 1.4 Trace.java Scanner.java Tab.java DFA.java ParserGen.java Parser.java Coco.java + jar cfm Coco.jar Coco.manifest Coco/*.class + rm -rf Coco + +clean: + rm -f Coco.jar + +install: + install -m 0755 cocoj $(DESTDIR)/usr/bin + install -m 0644 Coco.jar $(DESTDIR)/usr/share/coco-java + install -m 0644 *frame $(DESTDIR)/usr/share/coco-java + --- coco-java-20110419.orig/Parser.java +++ coco-java-20110419/Parser.java @@ -28,15 +28,15 @@ package Coco; public class Parser { - public static final int _EOF = 0; - public static final int _ident = 1; - public static final int _number = 2; - public static final int _string = 3; - public static final int _badString = 4; - public static final int _char = 5; - public static final int maxT = 44; - public static final int _ddtSym = 45; - public static final int _optionSym = 46; + public static final int _EOF = 0; + public static final int _ident = 1; + public static final int _number = 2; + public static final int _string = 3; + public static final int _badString = 4; + public static final int _char = 5; + public static final int maxT = 44; + public static final int _ddtSym = 45; + public static final int _optionSym = 46; static final boolean T = true; static final boolean x = false; @@ -49,20 +49,20 @@ public Scanner scanner; public Errors errors; - static final int id = 0; - static final int str = 1; - - public Trace trace; // other Coco objects referenced by this ATG - public Tab tab; - public DFA dfa; - public ParserGen pgen; - - boolean genScanner; - String tokenString; // used in declarations of literal tokens - String noString = "-none-"; // used in declarations of literal tokens - -/*-------------------------------------------------------------------------*/ - + static final int id = 0; + static final int str = 1; + + public Trace trace; // other Coco objects referenced by this ATG + public Tab tab; + public DFA dfa; + public ParserGen pgen; + + boolean genScanner; + String tokenString; // used in declarations of literal tokens + String noString = "-none-"; // used in declarations of literal tokens + +/*-------------------------------------------------------------------------*/ + public Parser(Scanner scanner) { @@ -88,12 +88,12 @@ ++errDist; break; } - - if (la.kind == 45) { - tab.SetDDT(la.val); - } - if (la.kind == 46) { - tab.SetOption(la.val); + + if (la.kind == 45) { + tab.SetDDT(la.val); + } + if (la.kind == 46) { + tab.SetOption(la.val); } la = t; } @@ -129,817 +129,817 @@ } } - void Coco() { - Symbol sym; Graph g, g1, g2; String gramName; CharSet s; int beg; - if (StartOf(1)) { - Get(); - beg = t.pos; - while (StartOf(1)) { - Get(); - } - pgen.usingPos = new Position(beg, la.pos, 0); - } - Expect(6); - genScanner = true; - tab.ignored = new CharSet(); - Expect(1); - gramName = t.val; - beg = la.pos; - - while (StartOf(2)) { - Get(); - } - tab.semDeclPos = new Position(beg, la.pos, 0); - if (la.kind == 7) { - Get(); - dfa.ignoreCase = true; - } - if (la.kind == 8) { - Get(); - while (la.kind == 1) { - SetDecl(); - } - } - if (la.kind == 9) { - Get(); - while (la.kind == 1 || la.kind == 3 || la.kind == 5) { - TokenDecl(Node.t); - } - } - if (la.kind == 10) { - Get(); - while (la.kind == 1 || la.kind == 3 || la.kind == 5) { - TokenDecl(Node.pr); - } - } - while (la.kind == 11) { - Get(); - boolean nested = false; - Expect(12); - g1 = TokenExpr(); - Expect(13); - g2 = TokenExpr(); - if (la.kind == 14) { - Get(); - nested = true; - } - dfa.NewComment(g1.l, g2.l, nested); - } - while (la.kind == 15) { - Get(); - s = Set(); - tab.ignored.Or(s); - } - while (!(la.kind == 0 || la.kind == 16)) {SynErr(45); Get();} - Expect(16); - if (genScanner) dfa.MakeDeterministic(); - tab.DeleteNodes(); - - while (la.kind == 1) { - Get(); - sym = tab.FindSym(t.val); - boolean 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; - } - boolean noAttrs = sym.attrPos == null; - sym.attrPos = null; - boolean noRet = sym.retVar==null; - sym.retVar = null; - - if (la.kind == 24 || la.kind == 29) { - AttrDecl(sym); - } - if (!undef) - if (noAttrs != (sym.attrPos == null) - || noRet != (sym.retVar == null)) - SemErr("attribute mismatch between declaration and use of this symbol"); - - if (la.kind == 42) { - sym.semPos = SemText(); - } - ExpectWeak(17, 3); - g = Expression(); - sym.graph = g.l; - tab.Finish(g); - - ExpectWeak(18, 4); - } - Expect(19); - Expect(1); - if (gramName.compareTo(t.val) != 0) - 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, "???", 0); // noSym gets highest number - tab.SetupAnys(); - tab.RenumberPragmas(); - if (tab.ddt[2]) tab.PrintNodes(); - if (errors.count == 0) { - System.out.println("checking"); - tab.CompSymbolSets(); - if (tab.ddt[7]) tab.XRef(); - if (tab.GrammarOk()) { - System.out.print("parser"); - pgen.WriteParser(); - if (genScanner) { - System.out.print(" + scanner"); - dfa.WriteScanner(); - if (tab.ddt[0]) dfa.PrintStates(); - } - System.out.println(" generated"); - if (tab.ddt[8]) pgen.WriteStatistics(); - } - } - if (tab.ddt[6]) tab.PrintSymbolTable(); - - Expect(18); - } - - void SetDecl() { - CharSet s; - Expect(1); - String name = t.val; - CharClass c = tab.FindCharClass(name); - if (c != null) SemErr("name declared twice"); - - Expect(17); - s = Set(); - if (s.Elements() == 0) SemErr("character set must not be empty"); - c = tab.NewCharClass(name, s); - - Expect(18); - } - - void TokenDecl(int typ) { - SymInfo s; Symbol sym; Graph g; - s = Sym(); - sym = tab.FindSym(s.name); - if (sym != null) SemErr("name declared twice"); - else { - sym = tab.NewSym(typ, s.name, t.line); - sym.tokenKind = Symbol.fixedToken; - } - tokenString = null; - - while (!(StartOf(5))) {SynErr(46); Get();} - if (la.kind == 17) { - Get(); - g = TokenExpr(); - Expect(18); - if (s.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.get(tokenString) != null) - SemErr("token string declared twice"); - tab.literals.put(tokenString, sym); - dfa.MatchLiteral(tokenString, sym); - } - - } else if (StartOf(6)) { - if (s.kind == id) genScanner = false; - else dfa.MatchLiteral(sym.name, sym); - - } else SynErr(47); - if (la.kind == 42) { - sym.semPos = SemText(); - if (typ != Node.pr) SemErr("semantic action not allowed here"); - } - } - - Graph TokenExpr() { - Graph g; - Graph g2; - g = TokenTerm(); - boolean first = true; - while (WeakSeparator(33,7,8) ) { - g2 = TokenTerm(); - if (first) { tab.MakeFirstAlt(g); first = false; } - tab.MakeAlternative(g, g2); - - } - return g; - } - - CharSet Set() { - CharSet s; - CharSet s2; - s = SimSet(); - while (la.kind == 20 || la.kind == 21) { - if (la.kind == 20) { - Get(); - s2 = SimSet(); - s.Or(s2); - } else { - Get(); - s2 = SimSet(); - s.Subtract(s2); - } - } - return s; - } - - void AttrDecl(Symbol sym) { - int beg, col; - if (la.kind == 24) { - Get(); - if (la.kind == 25 || la.kind == 26) { - if (la.kind == 25) { - Get(); - } else { - Get(); - } - beg = la.pos; - TypeName(); - sym.retType = scanner.buffer.GetString(beg, la.pos); - Expect(1); - sym.retVar = t.val; - if (la.kind == 27) { - Get(); - } else if (la.kind == 28) { - Get(); - beg = la.pos; col = la.col; - while (StartOf(9)) { - if (StartOf(10)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(27); - if (t.pos > beg) - sym.attrPos = new Position(beg, t.pos, col); - } else SynErr(48); - } else if (StartOf(11)) { - beg = la.pos; col = la.col; - while (StartOf(12)) { - if (StartOf(13)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(27); - if (t.pos > beg) - sym.attrPos = new Position(beg, t.pos, col); - } else SynErr(49); - } else if (la.kind == 29) { - Get(); - if (la.kind == 25 || la.kind == 26) { - if (la.kind == 25) { - Get(); - } else { - Get(); - } - beg = la.pos; - TypeName(); - sym.retType = scanner.buffer.GetString(beg, la.pos); - Expect(1); - sym.retVar = t.val; - if (la.kind == 30) { - Get(); - } else if (la.kind == 28) { - Get(); - beg = la.pos; col = la.col; - while (StartOf(14)) { - if (StartOf(15)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(30); - if (t.pos > beg) - sym.attrPos = new Position(beg, t.pos, col); - } else SynErr(50); - } else if (StartOf(11)) { - beg = la.pos; col = la.col; - while (StartOf(16)) { - if (StartOf(17)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(30); - if (t.pos > beg) - sym.attrPos = new Position(beg, t.pos, col); - } else SynErr(51); - } else SynErr(52); - } - - Position SemText() { - Position pos; - Expect(42); - int beg = la.pos; int col = la.col; - while (StartOf(18)) { - if (StartOf(19)) { - Get(); - } else if (la.kind == 4) { - Get(); - SemErr("bad string in semantic action"); - } else { - Get(); - SemErr("missing end of previous semantic action"); - } - } - Expect(43); - pos = new Position(beg, t.pos, col); - return pos; - } - - Graph Expression() { - Graph g; - Graph g2; - g = Term(); - boolean first = true; - while (WeakSeparator(33,20,21) ) { - g2 = Term(); - if (first) { tab.MakeFirstAlt(g); first = false; } - tab.MakeAlternative(g, g2); - - } - return g; - } - - CharSet SimSet() { - CharSet s; - int n1, n2; - s = new CharSet(); - if (la.kind == 1) { - Get(); - CharClass c = tab.FindCharClass(t.val); - if (c == null) SemErr("undefined name"); else s.Or(c.set); - - } else if (la.kind == 3) { - Get(); - String name = t.val; - name = tab.Unescape(name.substring(1, name.length()-1)); - for (int i = 0; i < name.length(); i++) - if (dfa.ignoreCase) s.Set(Character.toLowerCase(name.charAt(i))); - else s.Set(name.charAt(i)); - } else if (la.kind == 5) { - n1 = Char(); - s.Set(n1); - if (la.kind == 22) { - Get(); - n2 = Char(); - for (int i = n1; i <= n2; i++) s.Set(i); - } - } else if (la.kind == 23) { - Get(); - s = new CharSet(); s.Fill(); - } else SynErr(53); - return s; - } - - int Char() { - int n; - Expect(5); - String name = t.val; n = 0; - name = tab.Unescape(name.substring(1, name.length()-1)); - if (name.length() == 1) n = name.charAt(0); - else SemErr("unacceptable character value"); - if (dfa.ignoreCase && (char)n >= 'A' && (char)n <= 'Z') n += 32; - - return n; - } - - SymInfo Sym() { - SymInfo s; - s = new SymInfo(); s.name = "???"; s.kind = id; - if (la.kind == 1) { - Get(); - s.kind = id; s.name = t.val; - } else if (la.kind == 3 || la.kind == 5) { - if (la.kind == 3) { - Get(); - s.name = t.val; - } else { - Get(); - s.name = "\"" + t.val.substring(1, t.val.length()-1) + "\""; - } - s.kind = str; - if (dfa.ignoreCase) s.name = s.name.toLowerCase(); - if (s.name.indexOf(' ') >= 0) - SemErr("literal tokens must not contain blanks"); - } else SynErr(54); - return s; - } - - void TypeName() { - Expect(1); - while (la.kind == 18 || la.kind == 24 || la.kind == 31) { - if (la.kind == 18) { - Get(); - Expect(1); - } else if (la.kind == 31) { - Get(); - Expect(32); - } else { - Get(); - TypeName(); - while (la.kind == 28) { - Get(); - TypeName(); - } - Expect(27); - } - } - } - - Graph Term() { - Graph g; - Graph g2; Node rslv = null; g = null; - if (StartOf(22)) { - if (la.kind == 40) { - rslv = tab.NewNode(Node.rslv, null, la.line); - rslv.pos = Resolver(); - g = new Graph(rslv); - } - g2 = Factor(); - if (rslv != null) tab.MakeSequence(g, g2); - else g = g2; - - while (StartOf(23)) { - g2 = Factor(); - tab.MakeSequence(g, g2); - } - } else if (StartOf(24)) { - g = new Graph(tab.NewNode(Node.eps, null, 0)); - } else SynErr(55); - if (g == null) // invalid start of Term - g = new Graph(tab.NewNode(Node.eps, null, 0)); - - return g; - } - - Position Resolver() { - Position pos; - Expect(40); - Expect(35); - int beg = la.pos; int col = la.col; - Condition(); - pos = new Position(beg, t.pos, col); - return pos; - } - - Graph Factor() { - Graph g; - SymInfo s; Position pos; boolean weak = false; - g = null; - switch (la.kind) { - case 1: case 3: case 5: case 34: { - if (la.kind == 34) { - Get(); - weak = true; - } - s = Sym(); - Symbol sym = tab.FindSym(s.name); - if (sym == null && s.kind == str) - sym = (Symbol)tab.literals.get(s.name); - boolean undef = sym == null; - if (undef) { - if (s.kind == id) - sym = tab.NewSym(Node.nt, s.name, 0); // forward nt - else if (genScanner) { - sym = tab.NewSym(Node.t, s.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 == 24 || la.kind == 29) { - Attribs(p); - if (s.kind != id) SemErr("a literal must not have attributes"); - } - if (undef) { - sym.attrPos = p.pos; // dummy - sym.retVar = p.retVar; // AH - dummy - } else if ((p.pos == null) != (sym.attrPos == null) - || (p.retVar == null) != (sym.retVar == null)) - SemErr("attribute mismatch between declaration and use of this symbol"); - - break; - } - case 35: { - Get(); - g = Expression(); - Expect(36); - break; - } - case 31: { - Get(); - g = Expression(); - Expect(32); - tab.MakeOption(g); - break; - } - case 37: { - Get(); - g = Expression(); - Expect(38); - tab.MakeIteration(g); - break; - } - case 42: { - pos = SemText(); - Node p = tab.NewNode(Node.sem, null, 0); - p.pos = pos; - g = new Graph(p); - - break; - } - case 23: { - Get(); - Node p = tab.NewNode(Node.any, null, 0); // p.set is set in tab.SetupAnys - g = new Graph(p); - - break; - } - case 39: { - Get(); - Node p = tab.NewNode(Node.sync, null, 0); - g = new Graph(p); - - break; - } - default: SynErr(56); break; - } - if (g == null) // invalid start of Factor - g = new Graph(tab.NewNode(Node.eps, null, 0)); - - return g; - } - - void Attribs(Node n) { - int beg, col; - if (la.kind == 24) { - Get(); - if (la.kind == 25 || la.kind == 26) { - if (la.kind == 25) { - Get(); - } else { - Get(); - } - beg = la.pos; - while (StartOf(25)) { - if (StartOf(26)) { - Get(); - } else if (la.kind == 31 || la.kind == 35) { - Bracketed(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - n.retVar = scanner.buffer.GetString(beg, la.pos); - if (la.kind == 27) { - Get(); - } else if (la.kind == 28) { - Get(); - beg = la.pos; col = la.col; - while (StartOf(9)) { - if (StartOf(10)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(27); - if (t.pos > beg) n.pos = new Position(beg, t.pos, col); - } else SynErr(57); - } else if (StartOf(11)) { - beg = la.pos; col = la.col; - while (StartOf(12)) { - if (StartOf(13)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(27); - if (t.pos > beg) n.pos = new Position(beg, t.pos, col); - } else SynErr(58); - } else if (la.kind == 29) { - Get(); - if (la.kind == 25 || la.kind == 26) { - if (la.kind == 25) { - Get(); - } else { - Get(); - } - beg = la.pos; - while (StartOf(27)) { - if (StartOf(28)) { - Get(); - } else if (la.kind == 31 || la.kind == 35) { - Bracketed(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - n.retVar = scanner.buffer.GetString(beg, la.pos); - if (la.kind == 30) { - Get(); - } else if (la.kind == 28) { - Get(); - beg = la.pos; col = la.col; - while (StartOf(14)) { - if (StartOf(15)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(30); - if (t.pos > beg) n.pos = new Position(beg, t.pos, col); - } else SynErr(59); - } else if (StartOf(11)) { - beg = la.pos; col = la.col; - while (StartOf(16)) { - if (StartOf(17)) { - Get(); - } else { - Get(); - SemErr("bad string in attributes"); - } - } - Expect(30); - if (t.pos > beg) n.pos = new Position(beg, t.pos, col); - } else SynErr(60); - } else SynErr(61); - } - - void Condition() { - while (StartOf(29)) { - if (la.kind == 35) { - Get(); - Condition(); - } else { - Get(); - } - } - Expect(36); - } - - Graph TokenTerm() { - Graph g; - Graph g2; - g = TokenFactor(); - while (StartOf(7)) { - g2 = TokenFactor(); - tab.MakeSequence(g, g2); - } - if (la.kind == 41) { - Get(); - Expect(35); - g2 = TokenExpr(); - tab.SetContextTrans(g2.l); dfa.hasCtxMoves = true; - tab.MakeSequence(g, g2); - Expect(36); - } - return g; - } - - Graph TokenFactor() { - Graph g; - SymInfo s; - g = null; - if (la.kind == 1 || la.kind == 3 || la.kind == 5) { - s = Sym(); - if (s.kind == id) { - CharClass c = tab.FindCharClass(s.name); - if (c == null) { - SemErr("undefined name"); - c = tab.NewCharClass(s.name, new CharSet()); - } - Node p = tab.NewNode(Node.clas, null, 0); p.val = c.n; - g = new Graph(p); - tokenString = noString; - } else { // str - g = tab.StrToGraph(s.name); - if (tokenString == null) tokenString = s.name; - else tokenString = noString; - } - - } else if (la.kind == 35) { - Get(); - g = TokenExpr(); - Expect(36); - } else if (la.kind == 31) { - Get(); - g = TokenExpr(); - Expect(32); - tab.MakeOption(g); tokenString = noString; - } else if (la.kind == 37) { - Get(); - g = TokenExpr(); - Expect(38); - tab.MakeIteration(g); tokenString = noString; - } else SynErr(62); - if (g == null) // invalid start of TokenFactor - g = new Graph(tab.NewNode(Node.eps, null, 0)); - return g; - } - - void Bracketed() { - if (la.kind == 35) { - Get(); - while (StartOf(29)) { - if (la.kind == 31 || la.kind == 35) { - Bracketed(); - } else { - Get(); - } - } - Expect(36); - } else if (la.kind == 31) { - Get(); - while (StartOf(30)) { - if (la.kind == 31 || la.kind == 35) { - Bracketed(); - } else { - Get(); - } - } - Expect(32); - } else SynErr(63); - } - + void Coco() { + Symbol sym; Graph g, g1, g2; String gramName; CharSet s; int beg; + if (StartOf(1)) { + Get(); + beg = t.pos; + while (StartOf(1)) { + Get(); + } + pgen.usingPos = new Position(beg, la.pos, 0); + } + Expect(6); + genScanner = true; + tab.ignored = new CharSet(); + Expect(1); + gramName = t.val; + beg = la.pos; + + while (StartOf(2)) { + Get(); + } + tab.semDeclPos = new Position(beg, la.pos, 0); + if (la.kind == 7) { + Get(); + dfa.ignoreCase = true; + } + if (la.kind == 8) { + Get(); + while (la.kind == 1) { + SetDecl(); + } + } + if (la.kind == 9) { + Get(); + while (la.kind == 1 || la.kind == 3 || la.kind == 5) { + TokenDecl(Node.t); + } + } + if (la.kind == 10) { + Get(); + while (la.kind == 1 || la.kind == 3 || la.kind == 5) { + TokenDecl(Node.pr); + } + } + while (la.kind == 11) { + Get(); + boolean nested = false; + Expect(12); + g1 = TokenExpr(); + Expect(13); + g2 = TokenExpr(); + if (la.kind == 14) { + Get(); + nested = true; + } + dfa.NewComment(g1.l, g2.l, nested); + } + while (la.kind == 15) { + Get(); + s = Set(); + tab.ignored.Or(s); + } + while (!(la.kind == 0 || la.kind == 16)) {SynErr(45); Get();} + Expect(16); + if (genScanner) dfa.MakeDeterministic(); + tab.DeleteNodes(); + + while (la.kind == 1) { + Get(); + sym = tab.FindSym(t.val); + boolean 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; + } + boolean noAttrs = sym.attrPos == null; + sym.attrPos = null; + boolean noRet = sym.retVar==null; + sym.retVar = null; + + if (la.kind == 24 || la.kind == 29) { + AttrDecl(sym); + } + if (!undef) + if (noAttrs != (sym.attrPos == null) + || noRet != (sym.retVar == null)) + SemErr("attribute mismatch between declaration and use of this symbol"); + + if (la.kind == 42) { + sym.semPos = SemText(); + } + ExpectWeak(17, 3); + g = Expression(); + sym.graph = g.l; + tab.Finish(g); + + ExpectWeak(18, 4); + } + Expect(19); + Expect(1); + if (gramName.compareTo(t.val) != 0) + 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, "???", 0); // noSym gets highest number + tab.SetupAnys(); + tab.RenumberPragmas(); + if (tab.ddt[2]) tab.PrintNodes(); + if (errors.count == 0) { + System.out.println("checking"); + tab.CompSymbolSets(); + if (tab.ddt[7]) tab.XRef(); + if (tab.GrammarOk()) { + System.out.print("parser"); + pgen.WriteParser(); + if (genScanner) { + System.out.print(" + scanner"); + dfa.WriteScanner(); + if (tab.ddt[0]) dfa.PrintStates(); + } + System.out.println(" generated"); + if (tab.ddt[8]) pgen.WriteStatistics(); + } + } + if (tab.ddt[6]) tab.PrintSymbolTable(); + + Expect(18); + } + + void SetDecl() { + CharSet s; + Expect(1); + String name = t.val; + CharClass c = tab.FindCharClass(name); + if (c != null) SemErr("name declared twice"); + + Expect(17); + s = Set(); + if (s.Elements() == 0) SemErr("character set must not be empty"); + c = tab.NewCharClass(name, s); + + Expect(18); + } + + void TokenDecl(int typ) { + SymInfo s; Symbol sym; Graph g; + s = Sym(); + sym = tab.FindSym(s.name); + if (sym != null) SemErr("name declared twice"); + else { + sym = tab.NewSym(typ, s.name, t.line); + sym.tokenKind = Symbol.fixedToken; + } + tokenString = null; + + while (!(StartOf(5))) {SynErr(46); Get();} + if (la.kind == 17) { + Get(); + g = TokenExpr(); + Expect(18); + if (s.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.get(tokenString) != null) + SemErr("token string declared twice"); + tab.literals.put(tokenString, sym); + dfa.MatchLiteral(tokenString, sym); + } + + } else if (StartOf(6)) { + if (s.kind == id) genScanner = false; + else dfa.MatchLiteral(sym.name, sym); + + } else SynErr(47); + if (la.kind == 42) { + sym.semPos = SemText(); + if (typ != Node.pr) SemErr("semantic action not allowed here"); + } + } + + Graph TokenExpr() { + Graph g; + Graph g2; + g = TokenTerm(); + boolean first = true; + while (WeakSeparator(33,7,8) ) { + g2 = TokenTerm(); + if (first) { tab.MakeFirstAlt(g); first = false; } + tab.MakeAlternative(g, g2); + + } + return g; + } + + CharSet Set() { + CharSet s; + CharSet s2; + s = SimSet(); + while (la.kind == 20 || la.kind == 21) { + if (la.kind == 20) { + Get(); + s2 = SimSet(); + s.Or(s2); + } else { + Get(); + s2 = SimSet(); + s.Subtract(s2); + } + } + return s; + } + + void AttrDecl(Symbol sym) { + int beg, col; + if (la.kind == 24) { + Get(); + if (la.kind == 25 || la.kind == 26) { + if (la.kind == 25) { + Get(); + } else { + Get(); + } + beg = la.pos; + TypeName(); + sym.retType = scanner.buffer.GetString(beg, la.pos); + Expect(1); + sym.retVar = t.val; + if (la.kind == 27) { + Get(); + } else if (la.kind == 28) { + Get(); + beg = la.pos; col = la.col; + while (StartOf(9)) { + if (StartOf(10)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(27); + if (t.pos > beg) + sym.attrPos = new Position(beg, t.pos, col); + } else SynErr(48); + } else if (StartOf(11)) { + beg = la.pos; col = la.col; + while (StartOf(12)) { + if (StartOf(13)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(27); + if (t.pos > beg) + sym.attrPos = new Position(beg, t.pos, col); + } else SynErr(49); + } else if (la.kind == 29) { + Get(); + if (la.kind == 25 || la.kind == 26) { + if (la.kind == 25) { + Get(); + } else { + Get(); + } + beg = la.pos; + TypeName(); + sym.retType = scanner.buffer.GetString(beg, la.pos); + Expect(1); + sym.retVar = t.val; + if (la.kind == 30) { + Get(); + } else if (la.kind == 28) { + Get(); + beg = la.pos; col = la.col; + while (StartOf(14)) { + if (StartOf(15)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(30); + if (t.pos > beg) + sym.attrPos = new Position(beg, t.pos, col); + } else SynErr(50); + } else if (StartOf(11)) { + beg = la.pos; col = la.col; + while (StartOf(16)) { + if (StartOf(17)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(30); + if (t.pos > beg) + sym.attrPos = new Position(beg, t.pos, col); + } else SynErr(51); + } else SynErr(52); + } + + Position SemText() { + Position pos; + Expect(42); + int beg = la.pos; int col = la.col; + while (StartOf(18)) { + if (StartOf(19)) { + Get(); + } else if (la.kind == 4) { + Get(); + SemErr("bad string in semantic action"); + } else { + Get(); + SemErr("missing end of previous semantic action"); + } + } + Expect(43); + pos = new Position(beg, t.pos, col); + return pos; + } + + Graph Expression() { + Graph g; + Graph g2; + g = Term(); + boolean first = true; + while (WeakSeparator(33,20,21) ) { + g2 = Term(); + if (first) { tab.MakeFirstAlt(g); first = false; } + tab.MakeAlternative(g, g2); + + } + return g; + } + + CharSet SimSet() { + CharSet s; + int n1, n2; + s = new CharSet(); + if (la.kind == 1) { + Get(); + CharClass c = tab.FindCharClass(t.val); + if (c == null) SemErr("undefined name"); else s.Or(c.set); + + } else if (la.kind == 3) { + Get(); + String name = t.val; + name = tab.Unescape(name.substring(1, name.length()-1)); + for (int i = 0; i < name.length(); i++) + if (dfa.ignoreCase) s.Set(Character.toLowerCase(name.charAt(i))); + else s.Set(name.charAt(i)); + } else if (la.kind == 5) { + n1 = Char(); + s.Set(n1); + if (la.kind == 22) { + Get(); + n2 = Char(); + for (int i = n1; i <= n2; i++) s.Set(i); + } + } else if (la.kind == 23) { + Get(); + s = new CharSet(); s.Fill(); + } else SynErr(53); + return s; + } + + int Char() { + int n; + Expect(5); + String name = t.val; n = 0; + name = tab.Unescape(name.substring(1, name.length()-1)); + if (name.length() == 1) n = name.charAt(0); + else SemErr("unacceptable character value"); + if (dfa.ignoreCase && (char)n >= 'A' && (char)n <= 'Z') n += 32; + + return n; + } + + SymInfo Sym() { + SymInfo s; + s = new SymInfo(); s.name = "???"; s.kind = id; + if (la.kind == 1) { + Get(); + s.kind = id; s.name = t.val; + } else if (la.kind == 3 || la.kind == 5) { + if (la.kind == 3) { + Get(); + s.name = t.val; + } else { + Get(); + s.name = "\"" + t.val.substring(1, t.val.length()-1) + "\""; + } + s.kind = str; + if (dfa.ignoreCase) s.name = s.name.toLowerCase(); + if (s.name.indexOf(' ') >= 0) + SemErr("literal tokens must not contain blanks"); + } else SynErr(54); + return s; + } + + void TypeName() { + Expect(1); + while (la.kind == 18 || la.kind == 24 || la.kind == 31) { + if (la.kind == 18) { + Get(); + Expect(1); + } else if (la.kind == 31) { + Get(); + Expect(32); + } else { + Get(); + TypeName(); + while (la.kind == 28) { + Get(); + TypeName(); + } + Expect(27); + } + } + } + + Graph Term() { + Graph g; + Graph g2; Node rslv = null; g = null; + if (StartOf(22)) { + if (la.kind == 40) { + rslv = tab.NewNode(Node.rslv, null, la.line); + rslv.pos = Resolver(); + g = new Graph(rslv); + } + g2 = Factor(); + if (rslv != null) tab.MakeSequence(g, g2); + else g = g2; + + while (StartOf(23)) { + g2 = Factor(); + tab.MakeSequence(g, g2); + } + } else if (StartOf(24)) { + g = new Graph(tab.NewNode(Node.eps, null, 0)); + } else SynErr(55); + if (g == null) // invalid start of Term + g = new Graph(tab.NewNode(Node.eps, null, 0)); + + return g; + } + + Position Resolver() { + Position pos; + Expect(40); + Expect(35); + int beg = la.pos; int col = la.col; + Condition(); + pos = new Position(beg, t.pos, col); + return pos; + } + + Graph Factor() { + Graph g; + SymInfo s; Position pos; boolean weak = false; + g = null; + switch (la.kind) { + case 1: case 3: case 5: case 34: { + if (la.kind == 34) { + Get(); + weak = true; + } + s = Sym(); + Symbol sym = tab.FindSym(s.name); + if (sym == null && s.kind == str) + sym = (Symbol)tab.literals.get(s.name); + boolean undef = sym == null; + if (undef) { + if (s.kind == id) + sym = tab.NewSym(Node.nt, s.name, 0); // forward nt + else if (genScanner) { + sym = tab.NewSym(Node.t, s.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 == 24 || la.kind == 29) { + Attribs(p); + if (s.kind != id) SemErr("a literal must not have attributes"); + } + if (undef) { + sym.attrPos = p.pos; // dummy + sym.retVar = p.retVar; // AH - dummy + } else if ((p.pos == null) != (sym.attrPos == null) + || (p.retVar == null) != (sym.retVar == null)) + SemErr("attribute mismatch between declaration and use of this symbol"); + + break; + } + case 35: { + Get(); + g = Expression(); + Expect(36); + break; + } + case 31: { + Get(); + g = Expression(); + Expect(32); + tab.MakeOption(g); + break; + } + case 37: { + Get(); + g = Expression(); + Expect(38); + tab.MakeIteration(g); + break; + } + case 42: { + pos = SemText(); + Node p = tab.NewNode(Node.sem, null, 0); + p.pos = pos; + g = new Graph(p); + + break; + } + case 23: { + Get(); + Node p = tab.NewNode(Node.any, null, 0); // p.set is set in tab.SetupAnys + g = new Graph(p); + + break; + } + case 39: { + Get(); + Node p = tab.NewNode(Node.sync, null, 0); + g = new Graph(p); + + break; + } + default: SynErr(56); break; + } + if (g == null) // invalid start of Factor + g = new Graph(tab.NewNode(Node.eps, null, 0)); + + return g; + } + + void Attribs(Node n) { + int beg, col; + if (la.kind == 24) { + Get(); + if (la.kind == 25 || la.kind == 26) { + if (la.kind == 25) { + Get(); + } else { + Get(); + } + beg = la.pos; + while (StartOf(25)) { + if (StartOf(26)) { + Get(); + } else if (la.kind == 31 || la.kind == 35) { + Bracketed(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + n.retVar = scanner.buffer.GetString(beg, la.pos); + if (la.kind == 27) { + Get(); + } else if (la.kind == 28) { + Get(); + beg = la.pos; col = la.col; + while (StartOf(9)) { + if (StartOf(10)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(27); + if (t.pos > beg) n.pos = new Position(beg, t.pos, col); + } else SynErr(57); + } else if (StartOf(11)) { + beg = la.pos; col = la.col; + while (StartOf(12)) { + if (StartOf(13)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(27); + if (t.pos > beg) n.pos = new Position(beg, t.pos, col); + } else SynErr(58); + } else if (la.kind == 29) { + Get(); + if (la.kind == 25 || la.kind == 26) { + if (la.kind == 25) { + Get(); + } else { + Get(); + } + beg = la.pos; + while (StartOf(27)) { + if (StartOf(28)) { + Get(); + } else if (la.kind == 31 || la.kind == 35) { + Bracketed(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + n.retVar = scanner.buffer.GetString(beg, la.pos); + if (la.kind == 30) { + Get(); + } else if (la.kind == 28) { + Get(); + beg = la.pos; col = la.col; + while (StartOf(14)) { + if (StartOf(15)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(30); + if (t.pos > beg) n.pos = new Position(beg, t.pos, col); + } else SynErr(59); + } else if (StartOf(11)) { + beg = la.pos; col = la.col; + while (StartOf(16)) { + if (StartOf(17)) { + Get(); + } else { + Get(); + SemErr("bad string in attributes"); + } + } + Expect(30); + if (t.pos > beg) n.pos = new Position(beg, t.pos, col); + } else SynErr(60); + } else SynErr(61); + } + + void Condition() { + while (StartOf(29)) { + if (la.kind == 35) { + Get(); + Condition(); + } else { + Get(); + } + } + Expect(36); + } + + Graph TokenTerm() { + Graph g; + Graph g2; + g = TokenFactor(); + while (StartOf(7)) { + g2 = TokenFactor(); + tab.MakeSequence(g, g2); + } + if (la.kind == 41) { + Get(); + Expect(35); + g2 = TokenExpr(); + tab.SetContextTrans(g2.l); dfa.hasCtxMoves = true; + tab.MakeSequence(g, g2); + Expect(36); + } + return g; + } + + Graph TokenFactor() { + Graph g; + SymInfo s; + g = null; + if (la.kind == 1 || la.kind == 3 || la.kind == 5) { + s = Sym(); + if (s.kind == id) { + CharClass c = tab.FindCharClass(s.name); + if (c == null) { + SemErr("undefined name"); + c = tab.NewCharClass(s.name, new CharSet()); + } + Node p = tab.NewNode(Node.clas, null, 0); p.val = c.n; + g = new Graph(p); + tokenString = noString; + } else { // str + g = tab.StrToGraph(s.name); + if (tokenString == null) tokenString = s.name; + else tokenString = noString; + } + + } else if (la.kind == 35) { + Get(); + g = TokenExpr(); + Expect(36); + } else if (la.kind == 31) { + Get(); + g = TokenExpr(); + Expect(32); + tab.MakeOption(g); tokenString = noString; + } else if (la.kind == 37) { + Get(); + g = TokenExpr(); + Expect(38); + tab.MakeIteration(g); tokenString = noString; + } else SynErr(62); + if (g == null) // invalid start of TokenFactor + g = new Graph(tab.NewNode(Node.eps, null, 0)); + return g; + } + + void Bracketed() { + if (la.kind == 35) { + Get(); + while (StartOf(29)) { + if (la.kind == 31 || la.kind == 35) { + Bracketed(); + } else { + Get(); + } + } + Expect(36); + } else if (la.kind == 31) { + Get(); + while (StartOf(30)) { + if (la.kind == 31 || la.kind == 35) { + Bracketed(); + } else { + Get(); + } + } + Expect(32); + } else SynErr(63); + } + public void Parse() { la = new Token(); la.val = ""; Get(); - Coco(); - Expect(0); + Coco(); + Expect(0); } private static final boolean[][] 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,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,T,T, T,x}, - {x,T,T,T, T,T,T,x, x,x,x,x, T,T,T,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,x}, - {T,T,x,T, x,T,x,x, x,x,T,T, x,x,x,T, T,T,T,x, x,x,x,T, x,x,x,x, x,x,x,T, x,T,T,T, x,T,x,T, T,x,T,x, x,x}, - {T,T,x,T, x,T,x,x, x,x,T,T, x,x,x,T, T,T,x,T, x,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}, - {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,x, x,x,T,x, x,x}, - {x,T,x,T, x,T,x,x, x,x,T,T, x,x,x,T, T,x,x,x, x,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,x,T, x,T,x,x, x,x,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,T, x,T,x,x, x,x,x,x, x,x}, - {x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,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,x, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, - {x,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,x, 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,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,T,T,T, T,T,T,T, T,T,T,T, T,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,x,x,x, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, - {x,T,T,T, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, 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,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,T,T,T, T,x}, - {x,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,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,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,x,x,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, - {x,T,T,T, x,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,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,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,T, T,T,T,T, T,T,T,T, T,T,T,x, T,x}, - {x,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, T,T,x,x, T,x}, - {x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,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, x,x,x,x, T,x,x,x, T,x,T,x, x,x,x,x, x,x}, - {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,x,x,T, x,x,T,T, x,T,x,T, T,x,T,x, x,x}, - {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,x,x,T, x,x,T,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, x,x,x,x, T,T,x,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,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, - {x,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,x, x,T,T,x, T,T,T,x, T,T,T,T, T,T,T,T, T,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, x,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, - {x,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, x,T,x,x, T,T,T,x, T,T,T,T, T,T,T,T, T,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,T, T,T,T,T, x,T,T,T, T,T,T,T, T,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,T, x,T,T,T, T,T,T,T, T,T,T,T, T,x} + {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,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,T,T, T,x}, + {x,T,T,T, T,T,T,x, x,x,x,x, T,T,T,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,x}, + {T,T,x,T, x,T,x,x, x,x,T,T, x,x,x,T, T,T,T,x, x,x,x,T, x,x,x,x, x,x,x,T, x,T,T,T, x,T,x,T, T,x,T,x, x,x}, + {T,T,x,T, x,T,x,x, x,x,T,T, x,x,x,T, T,T,x,T, x,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}, + {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,x, x,x,T,x, x,x}, + {x,T,x,T, x,T,x,x, x,x,T,T, x,x,x,T, T,x,x,x, x,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,x,T, x,T,x,x, x,x,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,T, x,T,x,x, x,x,x,x, x,x}, + {x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,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,x, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, + {x,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,x, 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,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,T,T,T, T,T,T,T, T,T,T,T, T,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,x,x,x, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, + {x,T,T,T, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x,x, 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,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,T,T,T, T,x}, + {x,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,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,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,x,x,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, + {x,T,T,T, x,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,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,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,T, T,T,T,T, T,T,T,T, T,T,T,x, T,x}, + {x,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, T,T,x,x, T,x}, + {x,T,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,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, x,x,x,x, T,x,x,x, T,x,T,x, x,x,x,x, x,x}, + {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,x,x,T, x,x,T,T, x,T,x,T, T,x,T,x, x,x}, + {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,x,x,T, x,x,T,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, x,x,x,x, T,T,x,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,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, + {x,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,x, x,T,T,x, T,T,T,x, T,T,T,T, T,T,T,T, T,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, x,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x}, + {x,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, x,T,x,x, T,T,T,x, T,T,T,T, T,T,T,T, T,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,T, T,T,T,T, x,T,T,T, T,T,T,T, T,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,T, x,T,T,T, T,T,T,T, T,T,T,T, T,x} }; } // end Parser @@ -963,70 +963,70 @@ public void SynErr (int line, int col, int n) { String s; - switch (n) { - case 0: s = "EOF expected"; break; - case 1: s = "ident expected"; break; - case 2: s = "number expected"; break; - case 3: s = "string expected"; break; - case 4: s = "badString expected"; break; - case 5: s = "char expected"; break; - case 6: s = "\"COMPILER\" expected"; break; - case 7: s = "\"IGNORECASE\" expected"; break; - case 8: s = "\"CHARACTERS\" expected"; break; - case 9: s = "\"TOKENS\" expected"; break; - case 10: s = "\"PRAGMAS\" expected"; break; - case 11: s = "\"COMMENTS\" expected"; break; - case 12: s = "\"FROM\" expected"; break; - case 13: s = "\"TO\" expected"; break; - case 14: s = "\"NESTED\" expected"; break; - case 15: s = "\"IGNORE\" expected"; break; - case 16: s = "\"PRODUCTIONS\" expected"; break; - case 17: s = "\"=\" expected"; break; - case 18: s = "\".\" expected"; break; - case 19: s = "\"END\" expected"; break; - case 20: s = "\"+\" expected"; break; - case 21: s = "\"-\" expected"; break; - case 22: s = "\"..\" expected"; break; - case 23: s = "\"ANY\" expected"; break; - case 24: s = "\"<\" expected"; break; - case 25: s = "\"^\" expected"; break; - case 26: s = "\"out\" expected"; break; - case 27: s = "\">\" expected"; break; - case 28: s = "\",\" expected"; break; - case 29: s = "\"<.\" expected"; break; - case 30: s = "\".>\" expected"; break; - case 31: s = "\"[\" expected"; break; - case 32: s = "\"]\" expected"; break; - case 33: s = "\"|\" expected"; break; - case 34: s = "\"WEAK\" expected"; break; - case 35: s = "\"(\" expected"; break; - case 36: s = "\")\" expected"; break; - case 37: s = "\"{\" expected"; break; - case 38: s = "\"}\" expected"; break; - case 39: s = "\"SYNC\" expected"; break; - case 40: s = "\"IF\" expected"; break; - case 41: s = "\"CONTEXT\" expected"; break; - case 42: s = "\"(.\" expected"; break; - case 43: s = "\".)\" expected"; break; - case 44: s = "??? expected"; break; - case 45: s = "this symbol not expected in Coco"; break; - case 46: s = "this symbol not expected in TokenDecl"; break; - case 47: s = "invalid TokenDecl"; break; - case 48: s = "invalid AttrDecl"; break; - case 49: s = "invalid AttrDecl"; break; - case 50: s = "invalid AttrDecl"; break; - case 51: s = "invalid AttrDecl"; break; - case 52: s = "invalid AttrDecl"; break; - case 53: s = "invalid SimSet"; break; - case 54: s = "invalid Sym"; break; - case 55: s = "invalid Term"; break; - case 56: s = "invalid Factor"; break; - case 57: s = "invalid Attribs"; break; - case 58: s = "invalid Attribs"; break; - case 59: s = "invalid Attribs"; break; - case 60: s = "invalid Attribs"; break; - case 61: s = "invalid Attribs"; break; - case 62: s = "invalid TokenFactor"; break; + switch (n) { + case 0: s = "EOF expected"; break; + case 1: s = "ident expected"; break; + case 2: s = "number expected"; break; + case 3: s = "string expected"; break; + case 4: s = "badString expected"; break; + case 5: s = "char expected"; break; + case 6: s = "\"COMPILER\" expected"; break; + case 7: s = "\"IGNORECASE\" expected"; break; + case 8: s = "\"CHARACTERS\" expected"; break; + case 9: s = "\"TOKENS\" expected"; break; + case 10: s = "\"PRAGMAS\" expected"; break; + case 11: s = "\"COMMENTS\" expected"; break; + case 12: s = "\"FROM\" expected"; break; + case 13: s = "\"TO\" expected"; break; + case 14: s = "\"NESTED\" expected"; break; + case 15: s = "\"IGNORE\" expected"; break; + case 16: s = "\"PRODUCTIONS\" expected"; break; + case 17: s = "\"=\" expected"; break; + case 18: s = "\".\" expected"; break; + case 19: s = "\"END\" expected"; break; + case 20: s = "\"+\" expected"; break; + case 21: s = "\"-\" expected"; break; + case 22: s = "\"..\" expected"; break; + case 23: s = "\"ANY\" expected"; break; + case 24: s = "\"<\" expected"; break; + case 25: s = "\"^\" expected"; break; + case 26: s = "\"out\" expected"; break; + case 27: s = "\">\" expected"; break; + case 28: s = "\",\" expected"; break; + case 29: s = "\"<.\" expected"; break; + case 30: s = "\".>\" expected"; break; + case 31: s = "\"[\" expected"; break; + case 32: s = "\"]\" expected"; break; + case 33: s = "\"|\" expected"; break; + case 34: s = "\"WEAK\" expected"; break; + case 35: s = "\"(\" expected"; break; + case 36: s = "\")\" expected"; break; + case 37: s = "\"{\" expected"; break; + case 38: s = "\"}\" expected"; break; + case 39: s = "\"SYNC\" expected"; break; + case 40: s = "\"IF\" expected"; break; + case 41: s = "\"CONTEXT\" expected"; break; + case 42: s = "\"(.\" expected"; break; + case 43: s = "\".)\" expected"; break; + case 44: s = "??? expected"; break; + case 45: s = "this symbol not expected in Coco"; break; + case 46: s = "this symbol not expected in TokenDecl"; break; + case 47: s = "invalid TokenDecl"; break; + case 48: s = "invalid AttrDecl"; break; + case 49: s = "invalid AttrDecl"; break; + case 50: s = "invalid AttrDecl"; break; + case 51: s = "invalid AttrDecl"; break; + case 52: s = "invalid AttrDecl"; break; + case 53: s = "invalid SimSet"; break; + case 54: s = "invalid Sym"; break; + case 55: s = "invalid Term"; break; + case 56: s = "invalid Factor"; break; + case 57: s = "invalid Attribs"; break; + case 58: s = "invalid Attribs"; break; + case 59: s = "invalid Attribs"; break; + case 60: s = "invalid Attribs"; break; + case 61: s = "invalid Attribs"; break; + case 62: s = "invalid TokenFactor"; break; case 63: s = "invalid Bracketed"; break; default: s = "error " + n; break; } --- coco-java-20110419.orig/build.xml +++ coco-java-20110419/build.xml @@ -16,7 +16,7 @@ - + --- coco-java-20110419.orig/debian/rules +++ coco-java-20110419/debian/rules @@ -0,0 +1,130 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + +CFLAGS = -Wall -g + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + + touch configure-stamp + + +build: build-arch build-indep + +build-arch: build-stamp + +build-indep: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + $(MAKE) + #docbook-to-man debian/coco-java.sgml > coco-java.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_prep + dh_installdirs + + # Add here commands to install the package into debian/coco-java. + $(MAKE) install DESTDIR=$(CURDIR)/debian/coco-java + + +# Build architecture-independent files here. +binary-indep: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman debian/cocoj.1 + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + + +# Build architecture-dependent files here. +#binary-arch: build install +# dh_testdir +# dh_testroot +# dh_installchangelogs +# dh_installdocs +# dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo +# dh_installman debian/cocoj.1 +# dh_link +# dh_strip +# dh_compress +# dh_fixperms +# dh_perl +# dh_makeshlibs +# dh_installdeb +# dh_shlibdeps +# dh_gencontrol +# dh_md5sums +# dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure --- coco-java-20110419.orig/debian/dirs +++ coco-java-20110419/debian/dirs @@ -0,0 +1,3 @@ +usr/bin +usr/share/coco-java + --- coco-java-20110419.orig/debian/control +++ coco-java-20110419/debian/control @@ -0,0 +1,21 @@ +Source: coco-java +Section: devel +Priority: optional +Maintainer: Ubuntu Developers +XSBC-Original-Maintainer: Markus Loeberbauer +Build-Depends: debhelper (>= 8.9.14~), default-jdk +Standards-Version: 3.9.2 +Homepage: http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ + +Package: coco-java +Architecture: all +Depends: ${java:Depends}, ${misc:Depends} +Description: Coco/R Compiler Generator (Java Version) + Coco/R is a compiler generator, which takes an attributed grammar of a source + language and generates a scanner and a parser for this language. The scanner + works as a deterministic finite automaton. The parser uses recursive descent. + LL(1) conflicts can be resolved by a multi-symbol lookahead or by semantic + checks. Thus the class of accepted grammars is LL(k) for an arbitrary k. + . + To start Coco call cocoj, which is a shell script in /usr/bin. + --- coco-java-20110419.orig/debian/copyright +++ coco-java-20110419/debian/copyright @@ -0,0 +1,52 @@ +This work was packaged for Debian by: + + Markus Loeberbauer on Tue, 19 Apr 2011 16:21:52 +0200 + +It was downloaded from: + + http://www.ssw.uni-linz.ac.at/Research/Projects/Coco/ + +Upstream Authors: + + Hanspeter Moessenboeck + Markus Loeberbauer + +Copyright: + + Copyright (C) 1990, 2011 Hanspeter Moessenboeck + Copyright (C) 2003, 2011 Markus Loeberbauer + +License: + + Compiler Generator Coco/R, + Copyright (c) 1990, 2011 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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. + +The Debian packaging is: + + Copyright (C) 2011 Markus Loeberbauer + +and is licensed under the GPL version 2, +see "/usr/share/common-licenses/GPL-2". + --- coco-java-20110419.orig/debian/cocoj.1 +++ coco-java-20110419/debian/cocoj.1 @@ -0,0 +1,16 @@ +.TH cocoj 1 "Apr 19, 2011" "Coco/R Compiler Generator (Java Version)" + +.SH NAME +cocoj \- Coco/R Compiler Generator (Java Version) + +.SH HINT + +By default cocoj expects the Parser.frame and Scanner.frame file to be +in the same directory as the grammar (atg-file) to translate. As the +frame files are architecture independent, the default frame files can be +found in /usr/share/coco-java/. + +.SH SEE ALSO + +See package coco-doc for documentation. + --- coco-java-20110419.orig/debian/changelog +++ coco-java-20110419/debian/changelog @@ -0,0 +1,279 @@ +coco-java (20110419-3ubuntu1) quantal; urgency=low + + * Transition package to use default java implementation: + - d/control: BD on default-jdk only. + + -- James Page Wed, 01 Aug 2012 13:41:44 +0100 + +coco-java (20110419-3) unstable; urgency=low + + * debian package cleanup + + -- Markus Loeberbauer Sat, 21 Jan 2012 19:53:00 +0100 + +coco-java (20110419-2) unstable; urgency=low + + * fixed startup shell script (Closes: #647243) + + -- Markus Loeberbauer Mon, 07 Nov 2011 11:12:02 +0100 + +coco-java (20110419-1) unstable; urgency=low + + * New upstream release + * Frame files provided as command line argument take now precedence + over frame files in the source directory of the attributed grammar. + * The package can be set as a directive in the attributed + grammar: $package=packageName + if the package is set in the attributed grammar and on the command + line, the command line argument takes precedence. + * New option checkEOF: With the option checkEOF the user can specify + whether the generated parser should check if the entire input has been + consumed after parsing, i.e., if the token after the start symbol of + the grammar is an end-of-file token. The user can enable or disable + this check by the following directive in the attributed grammar: + $checkEOF=true // enable the end of file check (default) + $checkEOF=false // disable the end of file check + * Support for UTF-8 input: The token stores the character position + in Token.charPos. + * Support for copyright sections in the generated files. If a + file named Copyright.frame is provided, it will be included at + the top of the generated scanner and parser. + * Cleanup, removed the marker $$$ from the end of the frame files. + * More robust scanner generation. + * More robust UTF-8 handling in ParserGen.CopySourcePart and + Scanner.GetString. + * Simplified Coco.atg (using statements handled by ANY). + * Minor change: Code cleanup. + + -- Markus Loeberbauer Tue, 19 Apr 2011 16:21:52 +0200 + +coco-java (20090327-1) unstable; urgency=low + + * New upstream release + * Support for pragmas which are part of terminal classes (thanks + to Serge Voloshenyuk) + * Support for the escape sequences vertical tab (\v) and audible bell (\a) + * Minor change: Code cleanup + + -- Markus Loeberbauer Fri, 27 Mar 2009 13:18:05 +0100 + +coco-java (20081106-1) unstable; urgency=low + + * New upstream release. + * Minor change: code cleanup. + * Minor change: More robust Scanner, never assign Buffer.EOF to a char (which + results in an overflow, should do no harm). + + -- Markus Loeberbauer Mon, 10 Nov 2008 09:45:00 +0100 + +coco-java (20081001-3) unstable; urgency=low + + * Build with java 1.4 compatibility (Closes: 503771). + + -- Markus Loeberbauer Tue, 28 Oct 2008 11:15:00 +0100 + +coco-java (20081001-2) unstable; urgency=low + + * More robust clean target in make file. + + -- Markus Loeberbauer Sat, 04 Oct 2008 10:05:00 +0100 + +coco-java (20081001-1) unstable; urgency=low + + * New upstream release + * Bugfix: bug in the construction of the scanner automaton fixed. + * Minor change: More robust Peek method is Scanner. + * Minor change: Literal check is now handled by a hash-table-lookup instead + of an if-else-if cascade. + * Minor change: Allow underscores (_) in identifiers. + + -- Markus Loeberbauer Tue, 23 Sep 2008 20:10:00 +0100 + +coco-java (20070906-2) unstable; urgency=low + + * Minor Bugfix: Allow buffer position to be set to the end of the file, + this allows grammars without trailing new-line. + + -- Markus Loeberbauer Thu, 10 Sep 2007 14:15:00 +0100 + +coco-java (20070906-1) unstable; urgency=low + + * Enhanced support for input streams: Previously we did support files via + file names and file streams via input streams, but not non seek-able + streams (e.g. network). Now we support both stream types. Please note + since our memory buffer keeps the entire history of a stream, the maximum + supported stream size is limited by the available memory and the runtime + environment. + * The possibility to set the output path with command line option "-o". + * The main method returns 1 if the grammar contained an error. + + -- Markus Loeberbauer Thu, 06 Sep 2007 15:15:00 +0100 + +coco-java (20061206-1) unstable; urgency=low + + * The declaration of standard whitespaces (namely space) is again done in + the file Scanner.frame. + + -- Markus Loeberbauer Wed, 06 Dec 2006 15:00:00 +0100 + +coco-java (20060919-2) unstable; urgency=low + + * Added binary-arch target in debian/rules (Closes: 395586). + * It's now a non native package (Closes: 396539). + + -- Markus Loeberbauer Fri, 10 Nov 2006 14:21:58 +0100 + +coco-java (20060919-1) unstable; urgency=low + + * Misplaced resolvers cause warnings instead of errros now. + * The scanners generated by Coco/R can now also process Unicode + characters in UTF-8 format. This implies that Coco/R itself + supports UTF-8 now. + * Attributes may now also contain the characters '<' and '>' + (e.g. for operators or generic types). Such attributes must + be enclosed in <. and .> brackets. + * Error messages are written to an error stream instead of to the console. + The error stream can be changed by the user. + * The scanner now also recognizes the Unicode byte order mark for UTF-8. + + -- Markus Loeberbauer Tue, 19 Sep 2006 16:00:00 +0100 + +coco-java (20051117-1) unstable; urgency=low + + * The if else if cascade of an alternative does not get optimized to a + switch statement anymore if the alternative contains a LL(1) warning, + thus coco generates at least compileable code in such a situation. + + -- Markus Loeberbauer Thu, 17 Nov 2005 17:00:00 +0100 + +coco-java (20050926-1) unstable; urgency=low + + * Constant declarations are generated for pragma names in the parser now + (in case you want to access those names in semantic actions). + + -- Markus Loeberbauer Tue, 27 Sep 2005 19:18:00 +0100 + +coco-java (20050919-1) unstable; urgency=low + + * Bug fixed in Tab.cs. Coco reported a misplaced resolver if 2 alternatives + at the end of a production were deletable and a resolver was placed + in front of the first one. + + -- Markus Loeberbauer Mon, 19 Sep 2005 16:00:00 +0100 + +coco-java (20050504-1) unstable; urgency=low + + * New Upstream release + * Small bug in DFA fixed (EOF was not recognized correctly if ANY was used). + * Coco/R as well as the generated compilers are reentrant now. + That means that all fields and methods are non-static. + Please look at the user manual to see how to create and + initialize a scanner and a parser object in your compiler. + * In addition to bracket comments (/* ... */), ATG files can also contain + end of line comments now (// ... cr lf) + * Corrected some package troubles. (Closes: #306622) + + -- Markus Loeberbauer Tue, 04 May 2005 16:00:00 +0100 + +coco-java (20050316-3) unstable; urgency=low + + * debian/control: For Build-Depends, unzip, kaffe, jikes, jikes-kaffe + + -- Markus Loeberbauer Tue, 29 Mar 2005 10:00:00 +0100 + +coco-java (20050316-2) unstable; urgency=low + + * Moved from Sun java to kaffe and jikes to become main compliant. + + -- Markus Loeberbauer Tue, 29 Mar 2005 10:00:00 +0100 + +coco-java (20050316-1) unstable; urgency=low + + * Scanners can read arbitrariliy large files now (needed for + parsing log files with several hundred megabytes). + * Generated scanners are substantially faster than before (about 30%). + + -- Markus Loeberbauer Fri, 18 Mar 2005 13:00:00 +0100 + +coco-java (20050111-1) unstable; urgency=low + + * First upload to Debian unstable. + Sponsor: Rene Mayrhofer + * Renamed to coco-java. + * Lexical structures like '(' {char} ')' resulted in an endless loop in + the scanner if char was defined as ANY - ')' and if the terminating ')' + was missing in the input stream of the generated compiler. + + -- Markus Loeberbauer Tue, 11 Jan 2005 18:00:00 +0100 + +cocosourcesjava (2004.10.27-1) unstable; urgency=low + + * If an expression in curly braces or square brackets is deletable + (as in [[x]]) a new LL(1) warning is printed: contents of [...] + or {...} must not be deletable. + + -- Markus Loeberbauer Wed, 27 Oct 2004 17:35:00 +0100 + +cocosourcesjava (2004.10.11-1) unstable; urgency=low + + * Blanks are specified as white space in the scanner frame now, so one can + delete this if one doesn't want to ignore blanks. + (Caution! Use the latests Coco.jar only with the latest Scanner.frame!) + + -- Markus Loeberbauer Tue, 11 Oct 2004 10:00:00 +0100 + +cocosourcesjava (2004.06.28-3) unstable; urgency=low + + * Bug fix in DFA.java and ParserGen.java, Path seperator "\\" changed to + System.getProperty("file.seperator"). + + -- Markus Loeberbauer Tue, 24 Aug 2004 13:50:00 +0100 + +cocosourcesjava (2004.06.28-2) unstable; urgency=low + + * Bug fix in DFA.java, buggy code was generated for CONTEXT phrases. + * Bug fix in Coco.atg, invalid Token Factors and Terms caused Coco to crash. + + -- Markus Loeberbauer Tue, 27 Jul 2004 10:09:00 +0100 + +cocosourcesjava (2004.06.28-1) unstable; urgency=low + + * New upstream release + * Generation of case-insensitive compilers changed + - keyword IGNORECASE instead of IGNORE CASE. + - case is also ignored in tokens and character sets now. + - User manual changed + * The scanner uses '\u0100' instead of '\u0' as an end of file (eof) + character now. This allowes \0 to be used in tokens (useful for parsing + binary files). + * Bug fix in the detection of tokens that cannot be distinguished. + * IO routines changed from Java 1.0 to Java 1.1. + * Various cleanups. + + -- Markus Loeberbauer Tue, 06 Jun 2004 17:00:00 +0100 + +cocosourcesjava (2004.04.14-1) unstable; urgency=low + + * Method Tab.IgnoreCase added + * The frames directory is not specified by the environment variable CRFRAMES + any more but can be specified with the command line option -frames + * Bug fix in Coco.java (incorrect handling of command line arguments) + * Errors.errMsgFormat handled as in the C-Sharp version now (in Parser.java) + * Bug fix in Sets.PrintSet (in Tab.java) + * Fatal errors abort with System.exit(1) instead of System.exit(0) now + + -- Markus Loeberbauer Fri, 16 Apr 2004 12:35:00 +0100 + +cocosourcesjava (2004.04.06-2) unstable; urgency=low + + * changelog corrected + * directory names to lower case + + -- Markus Loeberbauer Tue, 13 Apr 2004 18:35:00 +0100 + +cocosourcesjava (2004.04.06-1) unstable; urgency=low + + * New upstream release + + -- Markus Loeberbauer Wed, 07 Apr 2004 18:35:00 +0100 + --- coco-java-20110419.orig/debian/compat +++ coco-java-20110419/debian/compat @@ -0,0 +1 @@ +7