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

(* global definitions: *)

	uses crt , dos , yacclib , lexlib ;
	Const 
		TMax = 500 ;	(* longueur maximale de la table *)

				(* codage des P-instructions *)

		ADD = 1 ;	SUB = 2 ;	MUL = 3 ;	NEG = 4 ;
		ET = 5 ;	OU = 6 ;	LNEG = 7 ;	EQU = 8 ;
		GEQ = 9 ;	LEQ = 10 ;	LES = 11 ; 	GRT = 12 ;
	 	NEQ = 13 ;	LDC = 14 ;	LDO = 15 ;	STO = 16 ;
		MOV = 17 ;	CHK = 18 ; 	PECRIRE = 19 ;	PLIRE = 20 ;
		UJP = 21 ;	FJP = 22 ;	INIT = 23 ;	RES = 24 ;	
		RET = 25 ;	ERREUR = 26 ;	PECRIREC = 27 ;
	Type	
		symbole = record
			nom : string[25] ; (* le segment des donnČes est limitČ *)
			dim : integer ;
			depl : integer
		end ;
		pinstruction = record
			operation : integer ;
			argument : longint
		end ;
		liste = ^cliste ;
		cliste = record
			adresse : longint ;
			suivant : liste
		end ;

	Var		(* la fonction rechercher est dans Gallex.l *)
		table : array[1..TMax] of symbole ;
		longueur : integer ;
		recherche : boolean ;
		pcode : file of pinstruction ;
		listetmp : liste ;

	procedure completertable( place, dimension : integer ) ;
	begin
		table[place].dim := dimension ;
		if place = 1 then table[place].depl := 0
		else table[place].depl := 
			table[place-1].depl + table[place-1].dim
	end ;

	procedure em ( voperation : integer ; vargument : longint ) ;
	Var v : pinstruction ;
	begin
		v.operation := voperation ;
		v.argument := vargument ;
		write(pcode, v)
	end ;

	procedure em1 ( voperation : integer ) ;
	begin
		em( voperation, 0 )
	end ;

	function position : longint ;
	begin
		position := filepos( pcode )
	end ;

	function liste0 : liste ;
	begin
		liste0 := nil
	end ;

	function liste1 ( p : longint ) : liste ;
	Var tmp : liste ;
	begin
		new( tmp ) ;
		tmp^.adresse := p ;
		tmp^.suivant := nil ;
		liste1 := tmp
	end ;

	function concatener ( l1, l2 : liste ) : liste ;
	Var tmp : liste ;
	begin
		if l1 = nil then concatener := l2
		else begin
			tmp := l1 ;
			while tmp^.suivant <> nil do tmp := tmp^.suivant ;
			tmp^.suivant := l2 ;
			concatener := l1
		end
	end ;

	procedure adresser ( ladresse, vadresse : longint ) ;
	Var v : pinstruction ;
	begin
		seek( pcode , ladresse ) ;
		read( pcode , v ) ;
		v.argument := vadresse ;
		seek( pcode , ladresse ) ;
		write( pcode , v )
	end ;

	procedure reprendre ( var l : liste ; vadresse : longint ) ;
	Var tmp : liste ; posinitiale : longint ;
	begin
		posinitiale := position ;
		while l <> nil do begin
			adresser( l^.adresse , vadresse ) ;
			tmp := l ;
			l := l^.suivant ;
			dispose( tmp )
		end ;
		seek( pcode , posinitiale ) 
	end ;


const programme = 257;
const retourne = 258;
const fin = 259;
const variables = 260;
const id = 261;
const entier = 262;
const tableau = 263;
const nb = 264;
const affect = 265;
const si = 266;
const alors = 267;
const sinon = 268;
const tantque = 269;
const faire = 270;
const ecrire = 271;
const ecrirec = 272;
const lire = 273;
const oprel = 274;
const opadd = 275;
const opmult = 276;
const non = 277;

type YYSType = record case Integer of
                 1 : ( yyinteger : integer );
                 2 : ( yyliste : liste );
                 3 : ( yylongint : longint );
               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
         begin
         			listetmp := yyv[yysp-1].yyliste ;
         			reprendre(listetmp, position ) ;
         			em1( ERREUR )
         		end ;
       end;
   2 : begin
         recherche := true ; 
       end;
   3 : begin
         recherche := true ;
         		(* on pourrait additionner les RES issus de Lid
         		(alternatives ci-dessous) et n'en faire qu'un seul ici :
         		em( RES, yyv[yysp-1].yyinteger ) *) 
       end;
   4 : begin
         begin
         			completertable( yyv[yysp-2].yyinteger, yyv[yysp-0].yyinteger ) ;
         			em( RES, yyv[yysp-0].yyinteger )
         			(* ou bien yyval.yyinteger := yyv[yysp-0].yyinteger *)
         		end ;
       end;
   5 : begin
         begin
         			completertable( yyv[yysp-2].yyinteger, yyv[yysp-0].yyinteger ) ;
         			em( RES, yyv[yysp-0].yyinteger )
         			(* ou bien yyval.yyinteger := yyv[yysp-3].yyinteger + yyv[yysp-0].yyinteger *)
         		end ;
       end;
   6 : begin
         yyval.yyinteger := 1 ; 
       end;
   7 : begin
         begin
         			if yyv[yysp-1].yyinteger < 1 then begin
         				write( 'Dimension de tableau incorrecte.') ;
         				writeln(' (ligne : ', yylineno, ')') ;
         				halt( 1 )
         			end ;
         			yyval.yyinteger := yyv[yysp-1].yyinteger
         		end ; 
       end;
   8 : begin
         ; 
       end;
   9 : begin
         begin
         			listetmp := yyv[yysp-2].yyliste ;
         			reprendre( listetmp, yyv[yysp-1].yylongint ) ;
         			yyval.yyliste := yyv[yysp-0].yyliste
         		end ; 
       end;
  10 : begin
         begin
         			em1( STO ) ;
         			yyval.yyliste := liste0
         		end ; 
       end;
  11 : begin
         yyval.yyliste := concatener( liste1( yyv[yysp-2].yylongint ), yyv[yysp-1].yyliste ) ; 
       end;
  12 : begin
         begin
         			listetmp := liste1( yyv[yysp-4].yylongint ) ;
         			reprendre( listetmp, yyv[yysp-2].yylongint + 1 ) ;
         			yyval.yyliste := concatener(
         					concatener( yyv[yysp-3].yyliste, liste1( yyv[yysp-2].yylongint ) ), yyv[yysp-1].yyliste 
         					)
         		end ; 
       end;
  13 : begin
         begin
         			listetmp := yyv[yysp-1].yyliste ;
         			reprendre( listetmp, position ) ;
         			em( UJP, yyv[yysp-4].yylongint ) ;
         			yyval.yyliste := liste1( yyv[yysp-2].yylongint )
         		end ; 
       end;
  14 : begin
         begin
         			em1( PECRIRE ) ;
         			yyval.yyliste := liste0
         		end ; 
       end;
  15 : begin
         begin
         			em1( RET ) ;
         			yyval.yyliste := liste0
         		end ; 
       end;
  16 : begin
         if table[yyv[yysp-0].yyinteger].dim = 1 then
         			em( LDC, table[yyv[yysp-0].yyinteger].depl )
         		else begin
         			write('Un tableau n''est pas affectable. ') ;
         			write( '(', table[yyv[yysp-0].yyinteger].nom, ', ligne : ') ;
         			writeln( yylineno, ')' ) ;
         			halt( 1 )
         		end ; 
       end;
  17 : begin
         begin
         			em( CHK, table[yyv[yysp-3].yyinteger].dim ) ;
         			em( LDC, table[yyv[yysp-3].yyinteger].depl ) ;
         			em1( ADD )
         		end ; 
       end;
  18 : begin
         ; 
       end;
  19 : begin
         em1( yyv[yysp-1].yyinteger ) ; 
       end;
  20 : begin
         ; 
       end;
  21 : begin
         em1( yyv[yysp-1].yyinteger ) ; 
       end;
  22 : begin
         em1( SUB ) ; 
       end;
  23 : begin
         ; 
       end;
  24 : begin
         em1( yyv[yysp-1].yyinteger ) ; 
       end;
  25 : begin
         begin
         			if table[yyv[yysp-0].yyinteger].dim = 1 then
         				em( LDO, table[yyv[yysp-0].yyinteger].depl )
         			else begin
         				write( 'Un tableau n''est pas une expression. ') ;
         				write( '(', table[yyv[yysp-0].yyinteger].nom, ', ligne : ' ) ;
         				writeln( yylineno, ')' ) ;
         				halt( 1 )
         			end
         		end ;
       end;
  26 : begin
         em1( PLIRE ) ;
       end;
  27 : begin
         begin
         			em( CHK, table[yyv[yysp-3].yyinteger].dim ) ;
         			em( LDC, table[yyv[yysp-3].yyinteger].depl ) ;
         			em1( ADD ) ;
         			em1( MOV )
         		end ; 
       end;
  28 : begin
         ; 
       end;
  29 : begin
         em1( NEG ) ; 
       end;
  30 : begin
         em1( LNEG ) ; 
       end;
  31 : begin
         em( LDC, yyv[yysp-0].yyinteger ) ; 
       end;
  32 : begin
         yyval.yylongint := position ; 
       end;
  33 : begin
         begin
         			yyval.yylongint := position ;
         			em1( FJP )
         		end ; 
       end;
  34 : begin
         begin
         			yyval.yylongint := position ;
         			em1( UJP )
         		end ; 
       end;
  35 : begin
         yyval.yylongint := position ; 
       end;
  36 : begin
         begin
         			yyval.yylongint := position ;
         			em1( FJP )
         		end ; 
       end;
  end;
end(*yyaction*);

(* parse table: *)

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

const

yynacts   = 208;
yyngotos  = 67;
yynstates = 77;
yynrules  = 36;

yya : array [1..yynacts] of YYARec = (
{ 0: }
  ( sym: 257; act: 2 ),
{ 1: }
  ( sym: 0; act: 0 ),
{ 2: }
  ( sym: 260; act: 4 ),
  ( sym: 258; act: -2 ),
  ( sym: 261; act: -2 ),
  ( sym: 266; act: -2 ),
  ( sym: 269; act: -2 ),
  ( sym: 271; act: -2 ),
{ 3: }
  ( sym: 258; act: 9 ),
  ( sym: 261; act: 10 ),
  ( sym: 266; act: 11 ),
  ( sym: 269; act: 12 ),
  ( sym: 271; act: 13 ),
{ 4: }
  ( sym: 261; act: 15 ),
{ 5: }
  ( sym: 59; act: 17 ),
  ( sym: 259; act: 18 ),
{ 6: }
{ 7: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 8: }
  ( sym: 265; act: 29 ),
{ 9: }
{ 10: }
  ( sym: 91; act: 30 ),
  ( sym: 265; act: -16 ),
{ 11: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 12: }
{ 13: }
  ( sym: 40; act: 32 ),
{ 14: }
  ( sym: 259; act: 33 ),
  ( sym: 261; act: 34 ),
{ 15: }
  ( sym: 58; act: 35 ),
{ 16: }
  ( sym: 258; act: 9 ),
  ( sym: 261; act: 10 ),
  ( sym: 266; act: 11 ),
  ( sym: 269; act: 12 ),
  ( sym: 271; act: 13 ),
{ 17: }
{ 18: }
{ 19: }
{ 20: }
  ( sym: 276; act: 37 ),
  ( sym: 41; act: -20 ),
  ( sym: 45; act: -20 ),
  ( sym: 59; act: -20 ),
  ( sym: 93; act: -20 ),
  ( sym: 259; act: -20 ),
  ( sym: 267; act: -20 ),
  ( sym: 268; act: -20 ),
  ( sym: 270; act: -20 ),
  ( sym: 274; act: -20 ),
  ( sym: 275; act: -20 ),
{ 21: }
  ( sym: 45; act: 38 ),
  ( sym: 274; act: 39 ),
  ( sym: 275; act: 40 ),
  ( sym: 41; act: -18 ),
  ( sym: 59; act: -18 ),
  ( sym: 259; act: -18 ),
  ( sym: 267; act: -18 ),
  ( sym: 268; act: -18 ),
  ( sym: 270; act: -18 ),
{ 22: }
  ( sym: 270; act: 42 ),
{ 23: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 24: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 25: }
  ( sym: 91; act: 45 ),
  ( sym: 41; act: -25 ),
  ( sym: 45; act: -25 ),
  ( sym: 59; act: -25 ),
  ( sym: 93; act: -25 ),
  ( sym: 259; act: -25 ),
  ( sym: 267; act: -25 ),
  ( sym: 268; act: -25 ),
  ( sym: 270; act: -25 ),
  ( sym: 274; act: -25 ),
  ( sym: 275; act: -25 ),
  ( sym: 276; act: -25 ),
{ 26: }
{ 27: }
{ 28: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 29: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 30: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 31: }
  ( sym: 267; act: 50 ),
{ 32: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 33: }
{ 34: }
  ( sym: 58; act: 52 ),
{ 35: }
  ( sym: 262; act: 54 ),
  ( sym: 263; act: 55 ),
{ 36: }
{ 37: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 38: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 39: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 40: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 41: }
  ( sym: 258; act: 9 ),
  ( sym: 261; act: 10 ),
  ( sym: 266; act: 11 ),
  ( sym: 269; act: 12 ),
  ( sym: 271; act: 13 ),
{ 42: }
{ 43: }
  ( sym: 41; act: 61 ),
{ 44: }
{ 45: }
  ( sym: 40; act: 23 ),
  ( sym: 45; act: 24 ),
  ( sym: 261; act: 25 ),
  ( sym: 264; act: 26 ),
  ( sym: 273; act: 27 ),
  ( sym: 277; act: 28 ),
{ 46: }
{ 47: }
{ 48: }
  ( sym: 45; act: 38 ),
  ( sym: 93; act: 63 ),
  ( sym: 275; act: 40 ),
{ 49: }
  ( sym: 258; act: 9 ),
  ( sym: 261; act: 10 ),
  ( sym: 266; act: 11 ),
  ( sym: 269; act: 12 ),
  ( sym: 271; act: 13 ),
{ 50: }
{ 51: }
  ( sym: 41; act: 65 ),
{ 52: }
  ( sym: 262; act: 54 ),
  ( sym: 263; act: 55 ),
{ 53: }
{ 54: }
{ 55: }
  ( sym: 91; act: 67 ),
{ 56: }
{ 57: }
  ( sym: 276; act: 37 ),
  ( sym: 41; act: -22 ),
  ( sym: 45; act: -22 ),
  ( sym: 59; act: -22 ),
  ( sym: 93; act: -22 ),
  ( sym: 259; act: -22 ),
  ( sym: 267; act: -22 ),
  ( sym: 268; act: -22 ),
  ( sym: 270; act: -22 ),
  ( sym: 274; act: -22 ),
  ( sym: 275; act: -22 ),
{ 58: }
  ( sym: 45; act: 38 ),
  ( sym: 275; act: 40 ),
  ( sym: 41; act: -19 ),
  ( sym: 59; act: -19 ),
  ( sym: 259; act: -19 ),
  ( sym: 267; act: -19 ),
  ( sym: 268; act: -19 ),
  ( sym: 270; act: -19 ),
{ 59: }
  ( sym: 276; act: 37 ),
  ( sym: 41; act: -21 ),
  ( sym: 45; act: -21 ),
  ( sym: 59; act: -21 ),
  ( sym: 93; act: -21 ),
  ( sym: 259; act: -21 ),
  ( sym: 267; act: -21 ),
  ( sym: 268; act: -21 ),
  ( sym: 270; act: -21 ),
  ( sym: 274; act: -21 ),
  ( sym: 275; act: -21 ),
{ 60: }
  ( sym: 59; act: 17 ),
  ( sym: 259; act: 68 ),
{ 61: }
{ 62: }
  ( sym: 45; act: 38 ),
  ( sym: 93; act: 69 ),
  ( sym: 275; act: 40 ),
{ 63: }
{ 64: }
  ( sym: 59; act: 17 ),
  ( sym: 259; act: 71 ),
  ( sym: 268; act: 72 ),
{ 65: }
{ 66: }
{ 67: }
  ( sym: 264; act: 73 ),
{ 68: }
{ 69: }
{ 70: }
  ( sym: 258; act: 9 ),
  ( sym: 261; act: 10 ),
  ( sym: 266; act: 11 ),
  ( sym: 269; act: 12 ),
  ( sym: 271; act: 13 ),
{ 71: }
{ 72: }
{ 73: }
  ( sym: 93; act: 75 ),
{ 74: }
  ( sym: 59; act: 17 ),
  ( sym: 259; act: 76 )
{ 75: }
{ 76: }
);

yyg : array [1..yyngotos] of YYARec = (
{ 0: }
  ( sym: -16; act: 1 ),
{ 1: }
{ 2: }
  ( sym: -17; act: 3 ),
{ 3: }
  ( sym: -15; act: 5 ),
  ( sym: -14; act: 6 ),
  ( sym: -12; act: 7 ),
  ( sym: -4; act: 8 ),
{ 4: }
  ( sym: -2; act: 14 ),
{ 5: }
  ( sym: -9; act: 16 ),
{ 6: }
{ 7: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 21 ),
  ( sym: -5; act: 22 ),
{ 8: }
{ 9: }
{ 10: }
{ 11: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 21 ),
  ( sym: -5; act: 31 ),
{ 12: }
{ 13: }
{ 14: }
{ 15: }
{ 16: }
  ( sym: -14; act: 36 ),
  ( sym: -12; act: 7 ),
  ( sym: -4; act: 8 ),
{ 17: }
{ 18: }
{ 19: }
{ 20: }
{ 21: }
{ 22: }
  ( sym: -13; act: 41 ),
{ 23: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 21 ),
  ( sym: -5; act: 43 ),
{ 24: }
  ( sym: -8; act: 44 ),
{ 25: }
{ 26: }
{ 27: }
{ 28: }
  ( sym: -8; act: 46 ),
{ 29: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 21 ),
  ( sym: -5; act: 47 ),
{ 30: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 48 ),
{ 31: }
  ( sym: -10; act: 49 ),
{ 32: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 21 ),
  ( sym: -5; act: 51 ),
{ 33: }
{ 34: }
{ 35: }
  ( sym: -3; act: 53 ),
{ 36: }
{ 37: }
  ( sym: -8; act: 56 ),
{ 38: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 57 ),
{ 39: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 58 ),
{ 40: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 59 ),
{ 41: }
  ( sym: -15; act: 60 ),
  ( sym: -14; act: 6 ),
  ( sym: -12; act: 7 ),
  ( sym: -4; act: 8 ),
{ 42: }
{ 43: }
{ 44: }
{ 45: }
  ( sym: -8; act: 19 ),
  ( sym: -7; act: 20 ),
  ( sym: -6; act: 62 ),
{ 46: }
{ 47: }
{ 48: }
{ 49: }
  ( sym: -15; act: 64 ),
  ( sym: -14; act: 6 ),
  ( sym: -12; act: 7 ),
  ( sym: -4; act: 8 ),
{ 50: }
{ 51: }
{ 52: }
  ( sym: -3; act: 66 ),
{ 53: }
{ 54: }
{ 55: }
{ 56: }
{ 57: }
{ 58: }
{ 59: }
{ 60: }
  ( sym: -9; act: 16 ),
{ 61: }
{ 62: }
{ 63: }
{ 64: }
  ( sym: -11; act: 70 ),
  ( sym: -9; act: 16 ),
{ 65: }
{ 66: }
{ 67: }
{ 68: }
{ 69: }
{ 70: }
  ( sym: -15; act: 74 ),
  ( sym: -14; act: 6 ),
  ( sym: -12; act: 7 ),
  ( sym: -4; act: 8 ),
{ 71: }
{ 72: }
{ 73: }
{ 74: }
  ( sym: -9; act: 16 )
{ 75: }
{ 76: }
);

yyd : array [0..yynstates-1] of Integer = (
{ 0: } 0,
{ 1: } 0,
{ 2: } 0,
{ 3: } 0,
{ 4: } 0,
{ 5: } 0,
{ 6: } -8,
{ 7: } 0,
{ 8: } 0,
{ 9: } -15,
{ 10: } 0,
{ 11: } 0,
{ 12: } -35,
{ 13: } 0,
{ 14: } 0,
{ 15: } 0,
{ 16: } 0,
{ 17: } -32,
{ 18: } -1,
{ 19: } -23,
{ 20: } 0,
{ 21: } 0,
{ 22: } 0,
{ 23: } 0,
{ 24: } 0,
{ 25: } 0,
{ 26: } -31,
{ 27: } -26,
{ 28: } 0,
{ 29: } 0,
{ 30: } 0,
{ 31: } 0,
{ 32: } 0,
{ 33: } -3,
{ 34: } 0,
{ 35: } 0,
{ 36: } -9,
{ 37: } 0,
{ 38: } 0,
{ 39: } 0,
{ 40: } 0,
{ 41: } 0,
{ 42: } -36,
{ 43: } 0,
{ 44: } -29,
{ 45: } 0,
{ 46: } -30,
{ 47: } -10,
{ 48: } 0,
{ 49: } 0,
{ 50: } -33,
{ 51: } 0,
{ 52: } 0,
{ 53: } -4,
{ 54: } -6,
{ 55: } 0,
{ 56: } -24,
{ 57: } 0,
{ 58: } 0,
{ 59: } 0,
{ 60: } 0,
{ 61: } -28,
{ 62: } 0,
{ 63: } -17,
{ 64: } 0,
{ 65: } -14,
{ 66: } -5,
{ 67: } 0,
{ 68: } -13,
{ 69: } -27,
{ 70: } 0,
{ 71: } -11,
{ 72: } -34,
{ 73: } 0,
{ 74: } 0,
{ 75: } -7,
{ 76: } -12
);

yyal : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 3,
{ 3: } 9,
{ 4: } 14,
{ 5: } 15,
{ 6: } 17,
{ 7: } 17,
{ 8: } 23,
{ 9: } 24,
{ 10: } 24,
{ 11: } 26,
{ 12: } 32,
{ 13: } 32,
{ 14: } 33,
{ 15: } 35,
{ 16: } 36,
{ 17: } 41,
{ 18: } 41,
{ 19: } 41,
{ 20: } 41,
{ 21: } 52,
{ 22: } 61,
{ 23: } 62,
{ 24: } 68,
{ 25: } 74,
{ 26: } 86,
{ 27: } 86,
{ 28: } 86,
{ 29: } 92,
{ 30: } 98,
{ 31: } 104,
{ 32: } 105,
{ 33: } 111,
{ 34: } 111,
{ 35: } 112,
{ 36: } 114,
{ 37: } 114,
{ 38: } 120,
{ 39: } 126,
{ 40: } 132,
{ 41: } 138,
{ 42: } 143,
{ 43: } 143,
{ 44: } 144,
{ 45: } 144,
{ 46: } 150,
{ 47: } 150,
{ 48: } 150,
{ 49: } 153,
{ 50: } 158,
{ 51: } 158,
{ 52: } 159,
{ 53: } 161,
{ 54: } 161,
{ 55: } 161,
{ 56: } 162,
{ 57: } 162,
{ 58: } 173,
{ 59: } 181,
{ 60: } 192,
{ 61: } 194,
{ 62: } 194,
{ 63: } 197,
{ 64: } 197,
{ 65: } 200,
{ 66: } 200,
{ 67: } 200,
{ 68: } 201,
{ 69: } 201,
{ 70: } 201,
{ 71: } 206,
{ 72: } 206,
{ 73: } 206,
{ 74: } 207,
{ 75: } 209,
{ 76: } 209
);

yyah : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 8,
{ 3: } 13,
{ 4: } 14,
{ 5: } 16,
{ 6: } 16,
{ 7: } 22,
{ 8: } 23,
{ 9: } 23,
{ 10: } 25,
{ 11: } 31,
{ 12: } 31,
{ 13: } 32,
{ 14: } 34,
{ 15: } 35,
{ 16: } 40,
{ 17: } 40,
{ 18: } 40,
{ 19: } 40,
{ 20: } 51,
{ 21: } 60,
{ 22: } 61,
{ 23: } 67,
{ 24: } 73,
{ 25: } 85,
{ 26: } 85,
{ 27: } 85,
{ 28: } 91,
{ 29: } 97,
{ 30: } 103,
{ 31: } 104,
{ 32: } 110,
{ 33: } 110,
{ 34: } 111,
{ 35: } 113,
{ 36: } 113,
{ 37: } 119,
{ 38: } 125,
{ 39: } 131,
{ 40: } 137,
{ 41: } 142,
{ 42: } 142,
{ 43: } 143,
{ 44: } 143,
{ 45: } 149,
{ 46: } 149,
{ 47: } 149,
{ 48: } 152,
{ 49: } 157,
{ 50: } 157,
{ 51: } 158,
{ 52: } 160,
{ 53: } 160,
{ 54: } 160,
{ 55: } 161,
{ 56: } 161,
{ 57: } 172,
{ 58: } 180,
{ 59: } 191,
{ 60: } 193,
{ 61: } 193,
{ 62: } 196,
{ 63: } 196,
{ 64: } 199,
{ 65: } 199,
{ 66: } 199,
{ 67: } 200,
{ 68: } 200,
{ 69: } 200,
{ 70: } 205,
{ 71: } 205,
{ 72: } 205,
{ 73: } 206,
{ 74: } 208,
{ 75: } 208,
{ 76: } 208
);

yygl : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 2,
{ 2: } 2,
{ 3: } 3,
{ 4: } 7,
{ 5: } 8,
{ 6: } 9,
{ 7: } 9,
{ 8: } 13,
{ 9: } 13,
{ 10: } 13,
{ 11: } 13,
{ 12: } 17,
{ 13: } 17,
{ 14: } 17,
{ 15: } 17,
{ 16: } 17,
{ 17: } 20,
{ 18: } 20,
{ 19: } 20,
{ 20: } 20,
{ 21: } 20,
{ 22: } 20,
{ 23: } 21,
{ 24: } 25,
{ 25: } 26,
{ 26: } 26,
{ 27: } 26,
{ 28: } 26,
{ 29: } 27,
{ 30: } 31,
{ 31: } 34,
{ 32: } 35,
{ 33: } 39,
{ 34: } 39,
{ 35: } 39,
{ 36: } 40,
{ 37: } 40,
{ 38: } 41,
{ 39: } 43,
{ 40: } 46,
{ 41: } 48,
{ 42: } 52,
{ 43: } 52,
{ 44: } 52,
{ 45: } 52,
{ 46: } 55,
{ 47: } 55,
{ 48: } 55,
{ 49: } 55,
{ 50: } 59,
{ 51: } 59,
{ 52: } 59,
{ 53: } 60,
{ 54: } 60,
{ 55: } 60,
{ 56: } 60,
{ 57: } 60,
{ 58: } 60,
{ 59: } 60,
{ 60: } 60,
{ 61: } 61,
{ 62: } 61,
{ 63: } 61,
{ 64: } 61,
{ 65: } 63,
{ 66: } 63,
{ 67: } 63,
{ 68: } 63,
{ 69: } 63,
{ 70: } 63,
{ 71: } 67,
{ 72: } 67,
{ 73: } 67,
{ 74: } 67,
{ 75: } 68,
{ 76: } 68
);

yygh : array [0..yynstates-1] of Integer = (
{ 0: } 1,
{ 1: } 1,
{ 2: } 2,
{ 3: } 6,
{ 4: } 7,
{ 5: } 8,
{ 6: } 8,
{ 7: } 12,
{ 8: } 12,
{ 9: } 12,
{ 10: } 12,
{ 11: } 16,
{ 12: } 16,
{ 13: } 16,
{ 14: } 16,
{ 15: } 16,
{ 16: } 19,
{ 17: } 19,
{ 18: } 19,
{ 19: } 19,
{ 20: } 19,
{ 21: } 19,
{ 22: } 20,
{ 23: } 24,
{ 24: } 25,
{ 25: } 25,
{ 26: } 25,
{ 27: } 25,
{ 28: } 26,
{ 29: } 30,
{ 30: } 33,
{ 31: } 34,
{ 32: } 38,
{ 33: } 38,
{ 34: } 38,
{ 35: } 39,
{ 36: } 39,
{ 37: } 40,
{ 38: } 42,
{ 39: } 45,
{ 40: } 47,
{ 41: } 51,
{ 42: } 51,
{ 43: } 51,
{ 44: } 51,
{ 45: } 54,
{ 46: } 54,
{ 47: } 54,
{ 48: } 54,
{ 49: } 58,
{ 50: } 58,
{ 51: } 58,
{ 52: } 59,
{ 53: } 59,
{ 54: } 59,
{ 55: } 59,
{ 56: } 59,
{ 57: } 59,
{ 58: } 59,
{ 59: } 59,
{ 60: } 60,
{ 61: } 60,
{ 62: } 60,
{ 63: } 60,
{ 64: } 62,
{ 65: } 62,
{ 66: } 62,
{ 67: } 62,
{ 68: } 62,
{ 69: } 62,
{ 70: } 66,
{ 71: } 66,
{ 72: } 66,
{ 73: } 66,
{ 74: } 67,
{ 75: } 67,
{ 76: } 67
);

yyr : array [1..yynrules] of YYRRec = (
{ 1: } ( len: 4; sym: -16 ),
{ 2: } ( len: 0; sym: -17 ),
{ 3: } ( len: 3; sym: -17 ),
{ 4: } ( len: 3; sym: -2 ),
{ 5: } ( len: 4; sym: -2 ),
{ 6: } ( len: 1; sym: -3 ),
{ 7: } ( len: 4; sym: -3 ),
{ 8: } ( len: 1; sym: -15 ),
{ 9: } ( len: 3; sym: -15 ),
{ 10: } ( len: 3; sym: -14 ),
{ 11: } ( len: 5; sym: -14 ),
{ 12: } ( len: 7; sym: -14 ),
{ 13: } ( len: 5; sym: -14 ),
{ 14: } ( len: 4; sym: -14 ),
{ 15: } ( len: 1; sym: -14 ),
{ 16: } ( len: 1; sym: -4 ),
{ 17: } ( len: 4; sym: -4 ),
{ 18: } ( len: 1; sym: -5 ),
{ 19: } ( len: 3; sym: -5 ),
{ 20: } ( len: 1; sym: -6 ),
{ 21: } ( len: 3; sym: -6 ),
{ 22: } ( len: 3; sym: -6 ),
{ 23: } ( len: 1; sym: -7 ),
{ 24: } ( len: 3; sym: -7 ),
{ 25: } ( len: 1; sym: -8 ),
{ 26: } ( len: 1; sym: -8 ),
{ 27: } ( len: 4; sym: -8 ),
{ 28: } ( len: 3; sym: -8 ),
{ 29: } ( len: 2; sym: -8 ),
{ 30: } ( len: 2; sym: -8 ),
{ 31: } ( len: 1; sym: -8 ),
{ 32: } ( len: 1; sym: -9 ),
{ 33: } ( len: 1; sym: -10 ),
{ 34: } ( len: 1; sym: -11 ),
{ 35: } ( len: 1; sym: -12 ),
{ 36: } ( len: 1; sym: -13 )
);


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('debordement de la pile de yyparse');
      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('Erreur de syntaxe');

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 Gallex}


Var
	fichier : PathStr ;
	repertoire : DirStr ;
	nom : NameStr ;
	extension : ExtStr ;
begin
	if paramcount = 0 then begin
		writeln( 'Commande : GAL NomDuFichier[.GAL]' ) ;
		halt( 1 )
	end
	else begin
		fichier := fexpand( paramstr( 1 ) ) ;
		fsplit( fichier, repertoire, nom, extension ) ;
		if nom + extension = '' then begin
			writeln( 'Commande : GAL NomDuFichier[.GAL]' ) ;
			halt( 1 )
		end ;
		if extension = '' then extension := '.GAL' ;
		{$I-}
		assign( yyinput, repertoire + nom + extension ) ;
		reset( yyinput ) ;
		{$I+}
		if IOResult <> 0 then begin
			write('Impossible d''ouvrir le fichier : ' ) ;
			writeln( repertoire + nom + extension ) ;
			halt( 1 )
		end
	end ;
	{$I-}
	assign( pcode , repertoire + nom + '.PCO' ) ;
	rewrite( pcode ) ;
	{$I+}
	if IOResult <> 0 then begin
		writeln( 'Impossible d''ouvrir un fichier .PCO' ) ;
		halt( 1 )
	end ; 

	(* fin de la mise en place des fichiers *)
	
	longueur := 0 ;		(* initialisation de la table *)
	recherche := false ;	(* on commence par ranger *)
	em1( INIT ) ; (* ou em( INIT, 1 ) si ecrirec est utilisČe *)
	if yyparse = 0 then begin 
		writeln ;
		write( 'Traduction terminee. (Pcode dans le fichier : ' ) ;
		writeln( repertoire, nom, '.PCO)')
	end
end.