
(* Yacc parser template (TP Yacc V3.0), V1.2 6-17-91 AG *)

(* global definitions: *)

 USES   YaccLib, LexLib;

 TYPE stringN=string[8];

 VAR   info:array[1..20] of record nom,comp:stringN;verbe:integer; end;
       v:array[1..20] of string[30];
       compteur:byte;

 Function convert(s:string):byte;
 var i:byte;
 Begin
 i:=1; while v[i]<>s do inc(i);
 convert:=i;
 End;

 Procedure  DonneInfo(s:stringN);
 var j:byte;
 Begin
 writeln;writeln('Info du KGB : ');
  for j:=1 to compteur do if (info[j].nom=s) or (info[j].comp=s) then
      writeln(info[j].nom,' ',v[info[j].verbe],' ',info[j].comp);
 End;

 Procedure StockInfo(s1:stringN;i:byte;s3:stringN);
 Begin
 inc(compteur);
 info[compteur].nom:=s1;
 info[compteur].verbe:=i;
 info[compteur].comp:=s3;
 End;
const IdNom = 257;
const IdVerbe = 258;
const IdQui = 259;

type YYSType = record case Integer of
                 1 : ( yyInteger : Integer );
                 2 : ( yyStringN : StringN );
               end(*YYSType*);

var yylval : YYSType;

function yylex : Integer; forward;

function yyparse : Integer;

var yystate, yysp, yyn : Integer;
    yys : array [1..yymaxdepth] of Integer;
    yyv : array [1..yymaxdepth] of YYSType;
    yyval : YYSType;

procedure yyaction ( yyruleno : Integer );
  (* local definitions: *)
begin
  (* actions: *)
  case yyruleno of
   1 : begin
       end;
   2 : begin
         
       end;
   3 : begin
         
       end;
   4 : begin
         yyerrok; 
       end;
   5 : begin
         yyval := yyv[yysp-0];
       end;
   6 : begin
         yyval := yyv[yysp-0];
       end;
   7 : begin
         StockInfo(yyv[yysp-2].yyStringN,yyv[yysp-1].yyInteger,yyv[yysp-0].yyStringN);
       end;
   8 : begin
         DonneInfo(yyv[yysp-1].yyStringN);
       end;
   9 : begin
         yyval := yyv[yysp-0];
       end;
  10 : begin
         yyval.yyInteger:=convert(yytext);
       end;
  11 : begin
         yyval := yyv[yysp-0];
       end;
  12 : begin
         yyval.yyStringN:=yytext;
       end;
  end;
end(*yyaction*);

(* parse table: *)

type YYARec = record
                sym, act : Integer;
              end;
     YYRRec = record
                len, sym : Integer;
              end;

const

yynacts   = 14;
yyngotos  = 10;
yynstates = 18;
yynrules  = 12;

yya : array [1..yynacts] of YYARec = (
{ 0: }
  ( sym: 256; act: 2 ),
  ( sym: 0; act: -1 ),
  ( sym: 10; act: -1 ),
  ( sym: 257; act: -1 ),
  ( sym: 259; act: -1 ),
{ 1: }
  ( sym: 0; act: 0 ),
  ( sym: 10; act: 8 ),
  ( sym: 257; act: 9 ),
  ( sym: 259; act: 10 ),
{ 2: }
  ( sym: 10; act: 11 ),
{ 3: }
{ 4: }
{ 5: }
  ( sym: 258; act: 13 ),
{ 6: }
{ 7: }
{ 8: }
{ 9: }
{ 10: }
  ( sym: 257; act: 9 ),
{ 11: }
{ 12: }
  ( sym: 257; act: 9 ),
{ 13: }
{ 14: }
  ( sym: 63; act: 17 )
{ 15: }
{ 16: }
{ 17: }
);

yyg : array [1..yyngotos] of YYARec = (
{ 0: }
  ( sym: -7; act: 1 ),
{ 1: }
  ( sym: -9; act: 3 ),
  ( sym: -8; act: 4 ),
  ( sym: -5; act: 5 ),
  ( sym: -3; act: 6 ),
  ( sym: -2; act: 7 ),
{ 2: }
{ 3: }
{ 4: }
{ 5: }
  ( sym: -6; act: 12 ),
{ 6: }
{ 7: }
{ 8: }
{ 9: }
{ 10: }
  ( sym: -3; act: 14 ),
{ 11: }
{ 12: }
  ( sym: -4; act: 15 ),
  ( sym: -3; act: 16 )
{ 13: }
{ 14: }
{ 15: }
{ 16: }
{ 17: }
);

yyd : array [0..yynstates-1] of Integer = (
{ 0: } 0,
{ 1: } 0,
{ 2: } 0,
{ 3: } -6,
{ 4: } -5,
{ 5: } 0,
{ 6: } -9,
{ 7: } -3,
{ 8: } -2,
{ 9: } -12,
{ 10: } 0,
{ 11: } -4,
{ 12: } 0,
{ 13: } -10,
{ 14: } 0,
{ 15: } -7,
{ 16: } -11,
{ 17: } -8
);

yyal : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 6,
{ 2: } 10,
{ 3: } 11,
{ 4: } 11,
{ 5: } 11,
{ 6: } 12,
{ 7: } 12,
{ 8: } 12,
{ 9: } 12,
{ 10: } 12,
{ 11: } 13,
{ 12: } 13,
{ 13: } 14,
{ 14: } 14,
{ 15: } 15,
{ 16: } 15,
{ 17: } 15
);

yyah : array [0..yynstates-1] of Integer = (
{ 0: } 5,
{ 1: } 9,
{ 2: } 10,
{ 3: } 10,
{ 4: } 10,
{ 5: } 11,
{ 6: } 11,
{ 7: } 11,
{ 8: } 11,
{ 9: } 11,
{ 10: } 12,
{ 11: } 12,
{ 12: } 13,
{ 13: } 13,
{ 14: } 14,
{ 15: } 14,
{ 16: } 14,
{ 17: } 14
);

yygl : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 7,
{ 3: } 7,
{ 4: } 7,
{ 5: } 7,
{ 6: } 8,
{ 7: } 8,
{ 8: } 8,
{ 9: } 8,
{ 10: } 8,
{ 11: } 9,
{ 12: } 9,
{ 13: } 11,
{ 14: } 11,
{ 15: } 11,
{ 16: } 11,
{ 17: } 11
);

yygh : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 6,
{ 2: } 6,
{ 3: } 6,
{ 4: } 6,
{ 5: } 7,
{ 6: } 7,
{ 7: } 7,
{ 8: } 7,
{ 9: } 7,
{ 10: } 8,
{ 11: } 8,
{ 12: } 10,
{ 13: } 10,
{ 14: } 10,
{ 15: } 10,
{ 16: } 10,
{ 17: } 10
);

yyr : array [1..yynrules] of YYRRec = (
{ 1: } ( len: 0; sym: -7 ),
{ 2: } ( len: 2; sym: -7 ),
{ 3: } ( len: 2; sym: -7 ),
{ 4: } ( len: 2; sym: -7 ),
{ 5: } ( len: 1; sym: -2 ),
{ 6: } ( len: 1; sym: -2 ),
{ 7: } ( len: 3; sym: -8 ),
{ 8: } ( len: 3; sym: -9 ),
{ 9: } ( len: 1; sym: -5 ),
{ 10: } ( len: 1; sym: -6 ),
{ 11: } ( len: 1; sym: -4 ),
{ 12: } ( len: 1; sym: -3 )
);


const _error = 256; (* error token *)

function yyact(state, sym : Integer; var act : Integer) : Boolean;
  (* search action table *)
  var k : Integer;
  begin
    k := yyal[state];
    while (k<=yyah[state]) and (yya[k].sym<>sym) do inc(k);
    if k>yyah[state] then
      yyact := false
    else
      begin
        act := yya[k].act;
        yyact := true;
      end;
  end(*yyact*);

function yygoto(state, sym : Integer; var nstate : Integer) : Boolean;
  (* search goto table *)
  var k : Integer;
  begin
    k := yygl[state];
    while (k<=yygh[state]) and (yyg[k].sym<>sym) do inc(k);
    if k>yygh[state] then
      yygoto := false
    else
      begin
        nstate := yyg[k].act;
        yygoto := true;
      end;
  end(*yygoto*);

label parse, next, error, errlab, shift, reduce, accept, abort;

begin(*yyparse*)

  (* initialize: *)

  yystate := 0; yychar := -1; yynerrs := 0; yyerrflag := 0; yysp := 0;

{$ifdef yydebug}
  yydebug := true;
{$else}
  yydebug := false;
{$endif}

parse:

  (* push state and value: *)

  inc(yysp);
  if yysp>yymaxdepth then
    begin
      yyerror('yyparse stack overflow');
      goto abort;
    end;
  yys[yysp] := yystate; yyv[yysp] := yyval;

next:

  if (yyd[yystate]=0) and (yychar=-1) then
    (* get next symbol *)
    begin
      yychar := yylex; if yychar<0 then yychar := 0;
    end;

  if yydebug then writeln('state ', yystate, ', char ', yychar);

  (* determine parse action: *)

  yyn := yyd[yystate];
  if yyn<>0 then goto reduce; (* simple state *)

  (* no default action; search parse table *)

  if not yyact(yystate, yychar, yyn) then goto error
  else if yyn>0 then                      goto shift
  else if yyn<0 then                      goto reduce
  else                                    goto accept;

error:

  (* error; start error recovery: *)

  if yyerrflag=0 then yyerror('syntax error');

errlab:

  if yyerrflag=0 then inc(yynerrs);     (* new error *)

  if yyerrflag<=2 then                  (* incomplete recovery; try again *)
    begin
      yyerrflag := 3;
      (* uncover a state with shift action on error token *)
      while (yysp>0) and not ( yyact(yys[yysp], _error, yyn) and
                               (yyn>0) ) do
        begin
          if yydebug then
            if yysp>1 then
              writeln('error recovery pops state ', yys[yysp], ', uncovers ',
                      yys[yysp-1])
            else
              writeln('error recovery fails ... abort');
          dec(yysp);
        end;
      if yysp=0 then goto abort; (* parser has fallen from stack; abort *)
      yystate := yyn;            (* simulate shift on error *)
      goto parse;
    end
  else                                  (* no shift yet; discard symbol *)
    begin
      if yydebug then writeln('error recovery discards char ', yychar);
      if yychar=0 then goto abort; (* end of input; abort *)
      yychar := -1; goto next;     (* clear lookahead char and try again *)
    end;

shift:

  (* go to new state, clear lookahead character: *)

  yystate := yyn; yychar := -1; yyval := yylval;
  if yyerrflag>0 then dec(yyerrflag);

  goto parse;

reduce:

  (* execute action, pop rule from stack, and go to next state: *)

  if yydebug then writeln('reduce ', -yyn);

  yyflag := yyfnone; yyaction(-yyn);
  dec(yysp, yyr[-yyn].len);
  if yygoto(yys[yysp], yyr[-yyn].sym, yyn) then yystate := yyn;

  (* handle action calls to yyaccept, yyabort and yyerror: *)

  case yyflag of
    yyfaccept : goto accept;
    yyfabort  : goto abort;
    yyferror  : goto errlab;
  end;

  goto parse;

accept:

  yyparse := 0; exit;

abort:

  yyparse := 1; exit;

end(*yyparse*);


{$I tp5lex}

begin
compteur:=0;
v[1]:='est marie a';
v[2]:='est mariee a';
v[3]:='est le frere de';
v[4]:='est la soeur de';
v[5]:='est le pere de';
v[6]:='est la mere de';

writeln('Tapez exit pour sortir');
  if yyparse=0 then { done };
end.