Téléchargement
Exemple de fonction main() pour votre Analyseur Syntaxique :
Version très "rustique" pour linux à modifier selon vos besoins...
Le programme obtenu prend en entrée un fichier test.in (qui contient le source à faire analyser par votre analyseur), et envoie le résultat sur la sortie standard ( l'écran ).
/*
(c) PK
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "mppksag.h"
static int file_length;
static char *filein = "test.in" ;
static char *fileout = "test.out";
extern void mppk_start();
int main (int argc, char ** argv)
{
FILE *fp;
struct stat statbuf;
char *file_string;
fp = fopen(filein,"r");
if (!fp)
{
fprintf(stderr,"cannot open %s\n",filein);
exit(1);
}
if (stat(filein, &statbuf) == 0) file_length = statbuf.st_size;
else file_length = 1000000; /* arbitrary file length */
file_string = (char *) malloc((unsigned)file_length+1);
fread(file_string, sizeof(char), file_length, fp);
file_string[file_length] = '\0';
fclose(fp);
printf("%s\n",mppksag(file_string, mppk_start));
}