Sunteți pe pagina 1din 5

Analizador Sintactico En C#

using
using
using
using
using

System;
System.Collections.Generic;
System.Text;
System.IO;
System.Windows.Forms;

namespace MiCompilador
{
class TAnalizadorSS
{
//Atributos
private TCompilador cmp;//referencia al objeto compilador
private const string VACIO = "vacio";
private const string ERROR_TIPO = "error";
private const string BOOLEAN = "boolean";
private List<string> ListCol = new List<string>();
private List<string> ListVal = new List<string>();
//Constructores
//General
public TAnalizadorSS(TCompilador cmp)
{
this.cmp = cmp;
}
//Metodos
/*-------------------------------------------------------------------------------------------------*/
//invoca reestablecer al buffer de entrada
public void inicializar()
{
cmp.be.reestablecer();
}
/*-------------------------------------------------------------------------------------------------*/
//inicia el analisis sintanctico
public void iniciar()
{
TAtributosSS _PROGSQL = new TAtributosSS();
inicializar();
PROGSQL(_PROGSQL);
}
/*--------------------------------------------------------------------------------------------------*/
public void emparejar(string t)
{
if (cmp.be.preAnalisis.Complex == t)
cmp.be.siguiente();
else
cmp.me.error(100, t, cmp.be.preAnalisis.Lexema);
}
/*--------------------------------------------------------------------------------------------------*/
private void tipoBasededatos(StreamReader reader)
{
string linea = "";

while (reader.Peek() > -1)


{
linea = reader.ReadLine().Trim();...

-------------------------------------------------------fin--------------------------------------------------ANALIZADOR SINTACTICO
#include "descrec2.h"
#include <stdlib.h>
#include <gtk/gtk.h>
#include <math.h>
/*
int DescRec::E(float *ApV,Scanner *scan){
g_print("-------------inicia----------------\n");
if(T(ApV,scan))
if(Ep(ApV,scan))
return 1;
return 0;
}
int DescRec::Ep(float *ApV,Scanner *scan){
int t;
float aux;
t=scan->yylex();
g_print("EP -sig %d\n",t);
if(t==SUMA || t==RESTA){
if(T(&aux,scan)){
if(t==SUMA)
*ApV=(*ApV+aux);
if(t==RESTA)
*ApV=(*ApV-aux);
return Ep(ApV,scan);
}
return 0;
}
scan->regresaToken();
return 1;
}
int DescRec::T(float *ApV,Scanner *scan){
if(F(ApV,scan))
if(Tp(ApV,scan))
return 1;
return 0;
}
int DescRec::Tp(float *ApV,Scanner *scan){
int t;
float aux;
t=scan->yylex();

g_print("TP -sig %d\n",t);


if(t==PROD || t==DIV){
if(F(&aux,scan)){
if(t==PROD)
*ApV=*ApV*aux;
if(t==DIV)
*ApV=*ApV/aux;
return Tp(ApV,scan);
}
return 0;
}
scan->regresaToken();
return 1;
}
int DescRec::F(float *ApV,Scanner *scan){
int t;
t=scan->yylex();
g_print("F -sig %d\n",t);
switch(t){
case PAR_I:if(E(ApV,scan)){
t=scan->yylex();
if(t==PAR_D)
return 1;
}
return 0;
case NUM:*ApV=atof(scan->yytext);
return 1;
}
return 0;
}*/

int DescRec::E(float *ApV,Scanner *scan){


if(T(ApV,scan))
if(Ep(ApV,scan)){
return 1;
}
return 0;
}
int DescRec::Ep(float *ApV,Scanner *scan){
int t;
float aux;
t=scan->yylex();
if(t==SUMA || t==RESTA){
if(T(&aux,scan)){
if(t==SUMA)
*ApV=(*ApV+aux);
if(t==RESTA)
*ApV=(*ApV-aux);
return Ep(ApV,scan);
}
return 0;
}

scan->regresaToken();
return 1;
}
int DescRec::T(float *ApV,Scanner *scan){
if(S(ApV,scan))
if(Tp(ApV,scan))
return 1;
return 0;
}
int DescRec::Tp(float *ApV,Scanner *scan){
int t;
float aux;
t=scan->yylex();
if(t==PROD || t==DIV){
if(F(&aux,scan)){
if(t==PROD)
*ApV=*ApV*aux;
if(t==DIV)
*ApV=*ApV/aux;
return Tp(ApV,scan);
}
return 0;
}
scan->regresaToken();
return 1;
}
int DescRec::S(float *ApV,Scanner *scan){
if(P(ApV,scan))
if(Sp(ApV,scan))
return 1;
return 0;
}
int DescRec::Sp(float *ApV,Scanner *scan){
int t;
float aux;
t=scan->yylex();
if(t==POT || t==RAIZ){
if(P(&aux,scan)){
if(t==POT)
*ApV=powf(*ApV,aux);
if(t==RAIZ)
*ApV=sqrtf(aux);
return Sp(ApV,scan);
}
return 0;
}
scan->regresaToken();
return 1;
}
int DescRec::P(float *ApV,Scanner *scan){
int t,l;
float aux;

t=scan->yylex();
if(t==SIN || t==COS || t==TAN || t==LOG || t==LN || t==EXP){
if(F(&aux,scan)){
if(t==SIN)
*ApV=sinf(aux);
if(t==COS)
*ApV=cosf(aux);
if(t==TAN)
*ApV=tanf(aux);
if(t==LOG)
*ApV=log10f(aux);
if(t==LN)
*ApV=logf(aux);
if(t==EXP)
*ApV=expf(aux);
return 1;
}
return 0;
}
scan->regresaToken();
return F(ApV,scan);
}
int DescRec::F(float *ApV,Scanner *scan){
int t;
t=scan->yylex();
switch(t){
case PAR_I:if(E(ApV,scan)){
t=scan->yylex();
if(t==PAR_D)
return 1;
}
return 0;
case NUM:*ApV=atof(scan->yytext);
return 1;
/*case VAR_X:*ApV=atof(scan->yytext);
return 1;
case VAR_Y:*ApV=atof(scan->yytext);
return 1;*/
}
return 0;
}

S-ar putea să vă placă și