OCP is back

This commit is contained in:
Christophe Alexandre 2002-03-13 19:04:02 +00:00
parent 4f28ec1138
commit 42e4d454b1
2 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,140 @@
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "iocheader.h"
extern int yylineno;
extern char *yytext;
extern int yyerror(char *str);
extern int yylex();
char con_orient = ' ';
int onvavoir = 0;
int top_used = 0;
int bottom_used = 0;
int right_used = 0;
int left_used = 0;
int l, l2;
char buf[256];
con_list *pt_list = NULL;
%}
%union {
char *text;
}
%token IGNORE TOP BOTTOM LEFT RIGHT IOPIN SPACE PAROUV PARFER PTVIRG PTZR
%token <text> IOCID
%start file
%%
file :
| orientation PAROUV expr PARFER file;
orientation : TOP {
if (top_used == 0){
con_orient = 'T';
top_used = 1;
} else yyerror("on ioc file : TOP declared twice");
}
| BOTTOM {
if (bottom_used == 0){
con_orient = 'B';
bottom_used = 1;
} else yyerror("on ioc file : BOTTOM declared twice");
}
| RIGHT {
if (right_used == 0){
con_orient = 'R';
right_used = 1;
} else yyerror("on ioc file : RIGHT declared twice");
}
| LEFT {
if (left_used == 0){
con_orient = 'L';
left_used = 1;
} else yyerror("on ioc file : LEFT declared twice");
}
| IGNORE {con_orient = ' ';}
expr :
| iopin expr;
| iopin space expr;
iopin : PAROUV IOPIN iopin1 PARFER PTVIRG;
space : SPACE IOCID PTVIRG {
pt_list = add_space(pt_list, con_orient, $2);
}
iopin1 : IOCID PTZR {
l = 0;
while ($1[l] != '.') l++;
strncpy(buf,$1,l);
buf[l] = '\0';
pt_list = add_con(pt_list, con_orient, buf);
}
| IOCID PAROUV IOCID PARFER PTZR {
l = 0;
while ($1[l] != '(') l++;
strncpy(buf,$1,l);
buf[l] = ' ';
l += 1;
l2 = l;
while ($1[l] != ')') l++;
strncpy(&buf[l2],&$1[l2],l-l2);
buf[l] = '\0';
pt_list = add_con(pt_list, con_orient, buf);
}
%%
int yyerror (char *str)
{
fflush(stdout);
fprintf(stderr, "error parsing the ioc file: %d: %s before %s\n", yylineno, str, yytext);
exit(1);
}
con_list* add_con(con_list* ptlist, char orient, char* name)
{
con_list* ptcon;
ptcon = (con_list*) malloc(sizeof(con_list));
ptcon->ORIENT = orient;
ptcon->NAME = strdup(name);
ptcon->NEXT = ptlist;
return ptcon;
}
con_list* add_space(con_list* ptlist, char orient, char *value)
{
con_list* ptcon;
ptcon = (con_list*) malloc(sizeof(con_list));
ptcon->NAME = strdup("SPACE");
ptcon->ORIENT = orient;
ptcon->VALUE = atoi(value);
ptcon->NEXT = ptlist;
return ptcon;
}
con_list* iocparse(char *file)
{
extern FILE *yyin;
if ((yyin = fopen(file,"r")) != NULL) {
yyparse();
fclose(yyin);
}
else
{
printf("error : ioc file not present\n");
exit(1);
}
return pt_list;
}

View File

@ -0,0 +1,34 @@
%{
#include <stdio.h>
#include "iocgram.h"
#define YY_NO_UNPUT /* Avoids warning */
int yylineno = 1;
%}
%%
#.* {}
\n { ++yylineno; }
[Ii][Gg][Nn][Oo][Rr][Ee] {return IGNORE; }
[Tt][Oo][Pp] {return TOP; }
[Bb][Oo][Tt][Tt][Oo][Mm] {return BOTTOM; }
[Ll][Ee][Ff][Tt] {return LEFT; }
[Rr][Ii][Gg][Hh][Tt] {return RIGHT; }
[Ii][Oo][Pp][Ii][Nn] {return IOPIN; }
[Ss][Pp][Aa][Cc][Ee] {return SPACE; }
"(" {return PAROUV; }
")" {return PARFER; }
; {return PTVIRG; }
"\.0" {return PTZR; }
[a-zA-Z0-9_]+ {yylval.text = yytext;
return IOCID; }
[ \t]+ {}
. {return *yytext;}
%%
int yywrap()
{
return 1;
}