home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.disi.unige.it
/
2015-02-11.ftp.disi.unige.it.tar
/
ftp.disi.unige.it
/
pub
/
.person
/
CataniaB
/
teach-act
/
esempi
/
Comp-Sep
/
parser.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-13
|
1KB
|
79 lines
#include <stdio.h>
#include <stdlib.h>
#include "getsym.h"
#include "parser.h" /* in questo caso quesa inclusione non e'
strettamente necessaria, perche'??? */
static symbol sym;
void parse(void)
{
sym = getsym();
parseE();
if (sym.kind == EQUAL)
{
printf("\n Successful parsing \n");
exit(EXIT_SUCCESS);
}
else
{
printf("\n Error: expecting equal symbol \n");
exit(EXIT_FAILURE);
}
}
void parseE(void)
{
parseT();
if (sym.kind == PLUS || sym.kind == MINUS)
{
sym = getsym();
parseE();
}
}
void parseT(void)
{
parseF();
if (sym.kind == TIMES || sym.kind == DIV)
{
sym = getsym();
parseT();
}
}
void parseF(void)
{
switch(sym.kind)
{
case LPAR:
sym = getsym();
parseE();
if (sym.kind != RPAR)
{
printf("\n Error: expecting right parenthesis \n");
exit(EXIT_FAILURE);
}
sym = getsym();
break;
case MINUS:
sym = getsym();
parseF();
break;
case NUMBER:
sym = getsym();
break;
default:
printf("\n Error: expecting left parenthesis or minus symbol or a number \n");
exit(EXIT_FAILURE);
break;
}
}