Datei: NDODLL/NDOql/Parser.frame
Last Commit (28c8c45)
| 1 | /*---------------------------------------------------------------------- |
| 2 | Compiler Generator Coco/R, |
| 3 | Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz |
| 4 | extended by M. Loeberbauer & A. Woess, Univ. of Linz |
| 5 | with improvements by Pat Terry, Rhodes University |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify it |
| 8 | under the terms of the GNU General Public License as published by the |
| 9 | Free Software Foundation; either version 2, or (at your option) any |
| 10 | later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 | or FITNESS FOR A PARTICULAR PURPOSE.··See the GNU General Public License |
| 15 | for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License along |
| 18 | with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | |
| 21 | As an exception, it is allowed to write an extension of Coco/R that is |
| 22 | used as a plugin in non-free software. |
| 23 | |
| 24 | If not otherwise stated, any source code generated by Coco/R (other than |
| 25 | Coco/R itself) does not fall under the GNU General Public License. |
| 26 | ----------------------------------------------------------------------*/ |
| 27 | -->begin |
| 28 | // |
| 29 | // This is generated code. Do not change it directly, change the Parser.frame file and rebuild the grammar. |
| 30 | // |
| 31 | |
| 32 | using System; |
| 33 | #pragma warning disable 3008, 1591 |
| 34 | |
| 35 | -->namespace |
| 36 | |
| 37 | public class Parser { |
| 38 | -->constants |
| 39 | ····const bool T = true; |
| 40 | ····const bool x = false; |
| 41 | ····const int minErrDist = 2; |
| 42 | ···· |
| 43 | ····public Scanner scanner; |
| 44 | ····public Errors··errors; |
| 45 | |
| 46 | ····public Token t;····// last recognized token |
| 47 | ····public Token la;·· // lookahead token |
| 48 | ····int errDist = minErrDist; |
| 49 | |
| 50 | -->declarations |
| 51 | |
| 52 | ····public Parser(Scanner scanner) { |
| 53 | ········this.scanner = scanner; |
| 54 | ········errors = new Errors(); |
| 55 | ····} |
| 56 | |
| 57 | ····void SynErr (int n) { |
| 58 | ········if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n); |
| 59 | ········errDist = 0; |
| 60 | ····} |
| 61 | |
| 62 | ····public void SemErr (string msg) { |
| 63 | ········if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg); |
| 64 | ········errDist = 0; |
| 65 | ····} |
| 66 | ···· |
| 67 | ····void Get () { |
| 68 | ········for (;;) { |
| 69 | ············t = la; |
| 70 | ············la = scanner.Scan(); |
| 71 | ············if (la.kind <= maxT) { ++errDist; break; } |
| 72 | -->pragmas |
| 73 | ············la = t; |
| 74 | ········} |
| 75 | ····} |
| 76 | ···· |
| 77 | ····void Expect (int n) { |
| 78 | ········if (la.kind==n) Get(); else { SynErr(n); } |
| 79 | ····} |
| 80 | ···· |
| 81 | ····bool StartOf (int s) { |
| 82 | ········return set[s, la.kind]; |
| 83 | ····} |
| 84 | ···· |
| 85 | ····void ExpectWeak (int n, int follow) { |
| 86 | ········if (la.kind == n) Get(); |
| 87 | ········else { |
| 88 | ············SynErr(n); |
| 89 | ············while (!StartOf(follow)) Get(); |
| 90 | ········} |
| 91 | ····} |
| 92 | |
| 93 | |
| 94 | ····bool WeakSeparator(int n, int syFol, int repFol) { |
| 95 | ········int kind = la.kind; |
| 96 | ········if (kind == n) {Get(); return true;} |
| 97 | ········else if (StartOf(repFol)) {return false;} |
| 98 | ········else { |
| 99 | ············SynErr(n); |
| 100 | ············while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) { |
| 101 | ················Get(); |
| 102 | ················kind = la.kind; |
| 103 | ············} |
| 104 | ············return StartOf(syFol); |
| 105 | ········} |
| 106 | ····} |
| 107 | |
| 108 | ···· |
| 109 | -->productions |
| 110 | |
| 111 | ····public void Parse() { |
| 112 | ········la = new Token(); |
| 113 | ········la.val = "";········ |
| 114 | ········Get(); |
| 115 | -->parseRoot |
| 116 | ····} |
| 117 | ···· |
| 118 | ····static readonly bool[,] set = { |
| 119 | -->initialization |
| 120 | ····}; |
| 121 | } // end Parser |
| 122 | |
| 123 | |
| 124 | public class Errors { |
| 125 | ····public int count = 0;····································// number of errors detected |
| 126 | ····public System.IO.TextWriter errorStream = Console.Out;·· // error messages go to this stream |
| 127 | ····public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text |
| 128 | |
| 129 | ····public virtual void SynErr (int line, int col, int n) { |
| 130 | ········string s; |
| 131 | ········switch (n) { |
| 132 | -->errors |
| 133 | ············default: s = "error " + n; break; |
| 134 | ········} |
| 135 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 136 | ········count++; |
| 137 | ····} |
| 138 | |
| 139 | ····public virtual void SemErr (int line, int col, string s) { |
| 140 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 141 | ········count++; |
| 142 | ····} |
| 143 | ···· |
| 144 | ····public virtual void SemErr (string s) { |
| 145 | ········errorStream.WriteLine(s); |
| 146 | ········count++; |
| 147 | ····} |
| 148 | ···· |
| 149 | ····public virtual void Warning (int line, int col, string s) { |
| 150 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 151 | ····} |
| 152 | ···· |
| 153 | ····public virtual void Warning(string s) { |
| 154 | ········errorStream.WriteLine(s); |
| 155 | ····} |
| 156 | } // Errors |
| 157 | |
| 158 | |
| 159 | public class FatalError: Exception { |
| 160 | ····public FatalError(string m): base(m) {} |
| 161 | } |
| 162 |
New Commit (b47b95e)
| 1 | /*---------------------------------------------------------------------- |
| 2 | Compiler Generator Coco/R, |
| 3 | Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz |
| 4 | extended by M. Loeberbauer & A. Woess, Univ. of Linz |
| 5 | with improvements by Pat Terry, Rhodes University |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify it |
| 8 | under the terms of the GNU General Public License as published by the |
| 9 | Free Software Foundation; either version 2, or (at your option) any |
| 10 | later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 | or FITNESS FOR A PARTICULAR PURPOSE.··See the GNU General Public License |
| 15 | for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License along |
| 18 | with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | |
| 21 | As an exception, it is allowed to write an extension of Coco/R that is |
| 22 | used as a plugin in non-free software. |
| 23 | |
| 24 | If not otherwise stated, any source code generated by Coco/R (other than |
| 25 | Coco/R itself) does not fall under the GNU General Public License. |
| 26 | ----------------------------------------------------------------------*/ |
| 27 | -->begin |
| 28 | // |
| 29 | // This is generated code. Do not change it directly, change the Parser.frame file and rebuild the grammar. |
| 30 | // |
| 31 | |
| 32 | using System; |
| 33 | #pragma warning disable 3008, 1591 |
| 34 | |
| 35 | -->namespace |
| 36 | |
| 37 | public class Parser { |
| 38 | -->constants |
| 39 | ····const bool T = true; |
| 40 | ····const bool x = false; |
| 41 | ····const int minErrDist = 2; |
| 42 | ···· |
| 43 | ····public Scanner scanner; |
| 44 | ····public Errors··errors; |
| 45 | |
| 46 | ····public Token t;····// last recognized token |
| 47 | ····public Token la;·· // lookahead token |
| 48 | ····int errDist = minErrDist; |
| 49 | |
| 50 | -->declarations |
| 51 | |
| 52 | ····public Parser(Scanner scanner) { |
| 53 | ········this.scanner = scanner; |
| 54 | ········errors = new Errors(); |
| 55 | ····} |
| 56 | |
| 57 | ····void SynErr (int n) { |
| 58 | ········if (errDist >= minErrDist) errors.SynErr(la.line, la.col, n); |
| 59 | ········errDist = 0; |
| 60 | ····} |
| 61 | |
| 62 | ····public void SemErr (string msg) { |
| 63 | ········if (errDist >= minErrDist) errors.SemErr(t.line, t.col, msg); |
| 64 | ········errDist = 0; |
| 65 | ····} |
| 66 | ···· |
| 67 | ····void Get () { |
| 68 | ········for (;;) { |
| 69 | ············t = la; |
| 70 | ············la = scanner.Scan(); |
| 71 | ············if (la.kind <= maxT) { ++errDist; break; } |
| 72 | -->pragmas |
| 73 | ············la = t; |
| 74 | ········} |
| 75 | ····} |
| 76 | ···· |
| 77 | ····void Expect (int n) { |
| 78 | ········if (la.kind==n) Get(); else { SynErr(n); } |
| 79 | ····} |
| 80 | ···· |
| 81 | ····bool StartOf (int s) { |
| 82 | ········return set[s, la.kind]; |
| 83 | ····} |
| 84 | ···· |
| 85 | ····void ExpectWeak (int n, int follow) { |
| 86 | ········if (la.kind == n) Get(); |
| 87 | ········else { |
| 88 | ············SynErr(n); |
| 89 | ············while (!StartOf(follow)) Get(); |
| 90 | ········} |
| 91 | ····} |
| 92 | |
| 93 | |
| 94 | ····bool WeakSeparator(int n, int syFol, int repFol) { |
| 95 | ········int kind = la.kind; |
| 96 | ········if (kind == n) {Get(); return true;} |
| 97 | ········else if (StartOf(repFol)) {return false;} |
| 98 | ········else { |
| 99 | ············SynErr(n); |
| 100 | ············while (!(set[syFol, kind] || set[repFol, kind] || set[0, kind])) { |
| 101 | ················Get(); |
| 102 | ················kind = la.kind; |
| 103 | ············} |
| 104 | ············return StartOf(syFol); |
| 105 | ········} |
| 106 | ····} |
| 107 | |
| 108 | ····bool IsOidIdentifier(OqlExpression iexp) { |
| 109 | ········return ((string)iexp.Value).EndsWith("oid"); |
| 110 | ····} |
| 111 | |
| 112 | ···· |
| 113 | -->productions |
| 114 | |
| 115 | ····public void Parse() { |
| 116 | ········la = new Token(); |
| 117 | ········la.val = "";········ |
| 118 | ········Get(); |
| 119 | -->parseRoot |
| 120 | ····} |
| 121 | ···· |
| 122 | ····static readonly bool[,] set = { |
| 123 | -->initialization |
| 124 | ····}; |
| 125 | } // end Parser |
| 126 | |
| 127 | |
| 128 | public class Errors { |
| 129 | ····public int count = 0;····································// number of errors detected |
| 130 | ····public System.IO.TextWriter errorStream = Console.Out;·· // error messages go to this stream |
| 131 | ····public string errMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text |
| 132 | |
| 133 | ····public virtual void SynErr (int line, int col, int n) { |
| 134 | ········string s; |
| 135 | ········switch (n) { |
| 136 | -->errors |
| 137 | ············default: s = "error " + n; break; |
| 138 | ········} |
| 139 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 140 | ········count++; |
| 141 | ····} |
| 142 | |
| 143 | ····public virtual void SemErr (int line, int col, string s) { |
| 144 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 145 | ········count++; |
| 146 | ····} |
| 147 | ···· |
| 148 | ····public virtual void SemErr (string s) { |
| 149 | ········errorStream.WriteLine(s); |
| 150 | ········count++; |
| 151 | ····} |
| 152 | ···· |
| 153 | ····public virtual void Warning (int line, int col, string s) { |
| 154 | ········errorStream.WriteLine(errMsgFormat, line, col, s); |
| 155 | ····} |
| 156 | ···· |
| 157 | ····public virtual void Warning(string s) { |
| 158 | ········errorStream.WriteLine(s); |
| 159 | ····} |
| 160 | } // Errors |
| 161 | |
| 162 | |
| 163 | public class FatalError: Exception { |
| 164 | ····public FatalError(string m): base(m) {} |
| 165 | } |
| 166 |