| 1: | /* Created by SharpDevelop. | |
| 2: | * User: Eduardo Rocha Monteiro ([email protected]) | |
| 3: | * Date: 25/2/2005 | |
| 4: | * Time: 13:24 | |
| 5: | */ | |
| 6: | ||
| 7: | using System; | |
| 8: | using System.Collections; | |
| 9: | using System.IO; | |
| 10: | ||
| 11: | namespace Compilador.AnalisadorSintaticoN | |
| 12: | { | |
| 13: | /// <summary> | |
| 14: | /// Description of GrafoSintatico. | |
| 15: | /// </summary> | |
| 16: | public class GrafoSintatico | |
| 17: | { | |
| 18: | private int _index; | |
| 19: | private char _tipo; | |
| 20: | private string _classeLexica; | |
| 21: | private int _acaoSemantica; | |
| 22: | private int _alternativa; | |
| 23: | private int _sucessor; | |
| 24: | private static int _count; | |
| 25: | private GrafoSintatico _first; | |
| 26: | private GrafoSintatico _next; | |
| 27: | ||
| 28: | public GrafoSintatico() | |
| 29: | { | |
| 30: | ||
| 31: | } | |
| 32: | ||
| 33: | public GrafoSintatico Posiciona(string classeLex) | |
| 34: | { | |
| 35: | GrafoSintatico g = this._first; | |
| 36: | while (g!=null) | |
| 37: | { | |
| 38: | if (g.Tipo=='c' && g.ClasseLexica==classeLex) | |
| 39: | return g; | |
| 40: | g=g._next; | |
| 41: | } | |
| 42: | return null; | |
| 43: | } | |
| 44: | ||
| 45: | ||
| 46: | ||
| 47: | public GrafoSintatico Posiciona(int index) | |
| 48: | { | |
| 49: | GrafoSintatico g = this._first; | |
| 50: | while (g!=null) | |
| 51: | { | |
| 52: | if (g.Index == index) | |
| 53: | { | |
| 54: | return g; | |
| 55: | } | |
| 56: | g=g._next; | |
| 57: | } | |
| 58: | return null; | |
| 59: | } | |
| 60: | ||
| 61: | ||
| 62: | public GrafoSintatico(string grafoTxt) | |
| 63: | { | |
| 64: | _count = 0; | |
| 65: | _first = Load(grafoTxt); | |
| 66: | } | |
| 67: | ||
| 68: | public GrafoSintatico Load(string grafoSintaticoTxt) | |
| 69: | { | |
| 70: | bool firstTime=true; | |
| 71: | GrafoSintatico g = new GrafoSintatico(); | |
| 72: | StreamReader sr = new StreamReader(grafoSintaticoTxt); | |
| 73: | string grafoSintaticoStr; | |
| 74: | g._first=g; | |
| 75: | while ((grafoSintaticoStr = sr.ReadLine()) != null) | |
| 76: | { | |
| 77: | if(firstTime) | |
| 78: | { | |
| 79: | g._first.Add(LoadLine(grafoSintaticoStr)); | |
| 80: | firstTime=false; | |
| 81: | } | |
| 82: | else | |
| 83: | { | |
| 84: | _count++; | |
| 85: | g.Add(LoadLine(grafoSintaticoStr)); | |
| 86: | g=g._next; | |
| 87: | } | |
| 88: | } | |
| 89: | return g._first; | |
| 90: | } | |
| 91: | ||
| 92: | ||
| 93: | public void Add(GrafoSintatico grafoSintatico) | |
| 94: | { | |
| 95: | _next = grafoSintatico; | |
| 96: | _next._first= _first; | |
| 97: | } | |
| 98: | ||
| 99: | public void Testa() | |
| 100: | { | |
| 101: | Console.WriteLine("testando.."); | |
| 102: | GrafoSintatico g = this; | |
| 103: | while (g!=null) | |
| 104: | { | |
| 105: | Console.WriteLine(g.Tipo); | |
| 106: | g=g.Next; | |
| 107: | } | |
| 108: | } | |
| 109: | ||
| 110: | public GrafoSintatico LoadLine(string line) | |
| 111: | { | |
| 112: | GrafoSintatico grafoSintatico = new GrafoSintatico(); | |
| 113: | string aux=""; | |
| 114: | int i = 0; | |
| 115: | while(line.Substring(i,1)!=" ") | |
| 116: | { | |
| 117: | aux+=line.Substring(i,1); | |
| 118: | i++; | |
| 119: | } | |
| 120: | grafoSintatico._index = Convert.ToInt32(aux); | |
| 121: | i++; | |
| 122: | aux=""; | |
| 123: | while(line.Substring(i,1)!=" ") | |
| 124: | { | |
| 125: | aux+=line.Substring(i,1); | |
| 126: | i++; | |
| 127: | } | |
| 128: | grafoSintatico._tipo = aux[0]; | |
| 129: | i++; | |
| 130: | aux=""; | |
| 131: | while(line.Substring(i,1)!=" ") | |
| 132: | { | |
| 133: | aux+=line.Substring(i,1); | |
| 134: | i++; | |
| 135: | } | |
| 136: | grafoSintatico._classeLexica=aux; | |
| 137: | i++; | |
| 138: | aux=""; | |
| 139: | while(line.Substring(i,1)!=" ") | |
| 140: | { | |
| 141: | aux+=line.Substring(i,1); | |
| 142: | i++; | |
| 143: | } | |
| 144: | grafoSintatico._acaoSemantica = Convert.ToInt32(aux); | |
| 145: | i++; | |
| 146: | aux=""; | |
| 147: | while(line.Substring(i,1)!=" ") | |
| 148: | { | |
| 149: | aux+=line.Substring(i,1); | |
| 150: | i++; | |
| 151: | } | |
| 152: | grafoSintatico._alternativa = Convert.ToInt32(aux); | |
| 153: | i++; | |
| 154: | aux=""; | |
| 155: | while(i < line.Length) | |
| 156: | { | |
| 157: | ||
| 158: | aux+=line.Substring(i,1); | |
| 159: | i++; | |
| 160: | } | |
| 161: | grafoSintatico._sucessor = Convert.ToInt32(aux); | |
| 162: | return grafoSintatico; | |
| 163: | } | |
| 164: | ||
| 165: | public int Index | |
| 166: | { | |
| 167: | get | |
| 168: | { | |
| 169: | return _index; | |
| 170: | } | |
| 171: | } | |
| 172: | ||
| 173: | public int Tipo | |
| 174: | { | |
| 175: | get | |
| 176: | { | |
| 177: | return _tipo; | |
| 178: | } | |
| 179: | } | |
| 180: | ||
| 181: | public string ClasseLexica | |
| 182: | { | |
| 183: | get | |
| 184: | { | |
| 185: | return _classeLexica; | |
| 186: | } | |
| 187: | } | |
| 188: | ||
| 189: | public int Count | |
| 190: | { | |
| 191: | get | |
| 192: | { | |
| 193: | return _count; | |
| 194: | } | |
| 195: | } | |
| 196: | ||
| 197: | public int AcaoSemantica | |
| 198: | { | |
| 199: | get | |
| 200: | { | |
| 201: | return _acaoSemantica; | |
| 202: | } | |
| 203: | } | |
| 204: | ||
| 205: | public int Sucessor | |
| 206: | { | |
| 207: | get | |
| 208: | { | |
| 209: | return _sucessor; | |
| 210: | } | |
| 211: | } | |
| 212: | ||
| 213: | public int Alternativa | |
| 214: | { | |
| 215: | get | |
| 216: | { | |
| 217: | return _alternativa; | |
| 218: | } | |
| 219: | } | |
| 220: | ||
| 221: | public GrafoSintatico Next | |
| 222: | { | |
| 223: | get | |
| 224: | { | |
| 225: | return _next; | |
| 226: | } | |
| 227: | } | |
| 228: | ||
| 229: | } | |
| 230: | } |
This page was automatically generated by SharpDevelop.