Advertisement
hectorrdz98

Final Project

Nov 15th, 2019
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. // prueba.gram
  2.  
  3. Lenguaje: C;
  4.  
  5. {
  6.     Programa -> Librerias Main; # Programa principal
  7.     Librerias -> \#include <Identificador.h> (,Librerias)?;
  8.     Main -> void main\(\){ Variables };
  9.     Variables -> TipoDato ListaDeIdentificadores\;;
  10.     ListaDeIdentificadores -> Identificador (,ListaDeIdentificadores)?;
  11.     Prueba -> \#|(Numero Programa)|(Identificador Numero?);
  12.     Anidado -> (\? (Numero Programa)?)?;
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. // Lenguaje.cs
  25.  
  26. using System;
  27. using System.Collections.Generic;
  28. using System.Linq;
  29. using System.Text;
  30. using System.Threading.Tasks;
  31.  
  32. namespace Generador
  33. {
  34.     class Lenguaje : Sintaxis
  35.     {
  36.         public Lenguaje() : base()
  37.         {
  38.        
  39.         }
  40.         public Lenguaje(string filePath) : base(filePath)
  41.         {
  42.        
  43.         }
  44.        
  45.         public void Programa()
  46.         {
  47.             Librerias();
  48.             Main();
  49.         }
  50.        
  51.         private void Librerias()
  52.         {
  53.             Match("#");
  54.             Match("include");
  55.             Match("<");
  56.             Match(c.Identificador);
  57.             Match(".");
  58.             Match("h");
  59.             Match(">");
  60.             if (getContenido() == ",")
  61.             {
  62.                 Match(",");
  63.                 Librerias();
  64.             }
  65.         }
  66.        
  67.         private void Main()
  68.         {
  69.             Match("void");
  70.             Match("main");
  71.             Match("(");
  72.             Match(")");
  73.             Match("{");
  74.             Variables();
  75.             Match("}");
  76.         }
  77.        
  78.         private void Variables()
  79.         {
  80.             Match(c.TipoDato);
  81.             ListaDeIdentificadores();
  82.             Match(";");
  83.         }
  84.        
  85.         private void ListaDeIdentificadores()
  86.         {
  87.             Match(c.Identificador);
  88.             if (getContenido() == ",")
  89.             {
  90.                 Match(",");
  91.                 ListaDeIdentificadores();
  92.             }
  93.         }
  94.        
  95.         private void Prueba()
  96.         {
  97.             if (getContenido() == "#")
  98.                 Match("#");
  99.             else
  100.                 if (getClasificacion() == c.Numero)
  101.                 {
  102.                     Match(c.Numero);
  103.                     Programa();
  104.                 }
  105.                 else
  106.                 {
  107.                     Match(c.Identificador);
  108.                     if (getClasificacion() == c.Numero)
  109.                         Match(c.Numero);
  110.                 }
  111.         }
  112.        
  113.         private void Anidado()
  114.         {
  115.             if (getContenido() == "?")
  116.             {
  117.                 Match("?");
  118.                 if (getClasificacion() == c.Numero)
  119.                 {
  120.                     Match(c.Numero);
  121.                     Programa();
  122.                 }
  123.             }
  124.         }
  125.        
  126.     }
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. // Program.cs
  138.  
  139. using System;
  140. using System.Collections.Generic;
  141. using System.Linq;
  142. using System.Text;
  143. using System.Threading.Tasks;
  144.  
  145. namespace Generador
  146. {
  147.     class Program
  148.     {
  149.         static void Main(string[] args)
  150.         {
  151.             try
  152.             {
  153.                 Lenguaje L = new Lenguaje("C:\\archivos\\prueba.cs\\");
  154.  
  155.                 L.Programa();
  156.  
  157.                 Console.ReadKey();
  158.                 Console.WriteLine();
  159.                 L.closeFiles();
  160.             }
  161.             catch (MyException) { }
  162.         }
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement