Browse Source

--- Merging r29502 into '.':
U utils/tply/pyacc.y
--- Merging r29503 into '.':
U utils/tply/lexbase.pas
G utils/tply/pyacc.y
U utils/tply/pyacc.pas
U utils/tply/plex.pas
U utils/tply/yaccbase.pas
--- Merging r30289 into '.':
U utils/tply/README.txt

# revisions: 29502,29503,30289

git-svn-id: branches/fixes_3_0@30825 -

marco 10 years ago
parent
commit
9bb8c2f400
6 changed files with 162 additions and 132 deletions
  1. 16 5
      utils/tply/README.txt
  2. 2 1
      utils/tply/lexbase.pas
  3. 22 11
      utils/tply/plex.pas
  4. 96 86
      utils/tply/pyacc.pas
  5. 24 28
      utils/tply/pyacc.y
  6. 2 1
      utils/tply/yaccbase.pas

+ 16 - 5
utils/tply/README.txt

@@ -16,7 +16,7 @@ available from the TPLY homepage:
 
 
 For information about the Free Pascal Compiler, please refer to:
 For information about the Free Pascal Compiler, please refer to:
 
 
-	http://tfdec1.fys.kuleuven.ac.be/~michael/fpc/fpc.html
+	http://www.freepascal.org/
 
 
 The manual can be found in the files tply.tex (TeX version) and tply.doc
 The manual can be found in the files tply.tex (TeX version) and tply.doc
 (ASCII version) contained in the package. An extended version of the manual
 (ASCII version) contained in the package. An extended version of the manual
@@ -44,7 +44,7 @@ The original version of the TPLY package was written by Albert Graef
 4.0-6.0. Berend de Boer <[email protected]>, the current maintainer of the
 4.0-6.0. Berend de Boer <[email protected]>, the current maintainer of the
 Turbo/Borland Pascal version, adapted TPLY to take advantage of the large
 Turbo/Borland Pascal version, adapted TPLY to take advantage of the large
 memory models in Borland Pascal 7.0 and Delphi. Michael Van Canneyt
 memory models in Borland Pascal 7.0 and Delphi. Michael Van Canneyt
-<[email protected]>, who maintains the Linux version of
+<[email protected]>, who maintains the Linux version of
 the Free Pascal compiler, is the author of the Free Pascal port.
 the Free Pascal compiler, is the author of the Free Pascal port.
 
 
 
 
@@ -77,10 +77,9 @@ to store things :-) The 16-bit DPMI platforms have tables extended as large as
 possible without changing basic Lex or Yacc sources.
 possible without changing basic Lex or Yacc sources.
 
 
 This version was ported to Free Pascal by Michael Van Canneyt
 This version was ported to Free Pascal by Michael Van Canneyt
-<[email protected]> (April 1998).
+<[email protected]> (April 1998).
 
 
-*** Version 4.1		Michael Van Canneyt
-			<[email protected]>
+*** Version 4.1		Michael Van Canneyt <[email protected]>
 			Albert Graef <[email protected]>
 			Albert Graef <[email protected]>
 
 
 May 1998. Merges the Turbo and Free Pascal versions into a single package.
 May 1998. Merges the Turbo and Free Pascal versions into a single package.
@@ -142,6 +141,18 @@ from the lex.pas and yacc.pas programs), the Lex and Yacc code templates
 (*.cod files), and the LexLib and YaccLib library units (compiled from
 (*.cod files), and the LexLib and YaccLib library units (compiled from
 lexlib.pas and yacclib.pas).
 lexlib.pas and yacclib.pas).
 
 
+The plex and pyacc programs will look for the *.cod files in the following locations:
+For unix-like operating systems:
+1. Current directory.
+2. Directory given by FPCDIR
+3. Directory /usr/local/lib/fpc/lexyacc
+4. Directory /usr/lib/fpc/lexyacc
+
+For other operating systems (dos/windows-like) : 
+1. Current directory.
+2. Directory given by FPCDIR 
+3. Directory where the executable is located.
+
 For the Free Pascal/Linux version, a Makefile is provided. To install, issue
 For the Free Pascal/Linux version, a Makefile is provided. To install, issue
 the command `make' (maybe you have to edit the Makefile before this to reflect
 the command `make' (maybe you have to edit the Makefile before this to reflect
 your setup) and then `make install'. Note that in the Linux version the
 your setup) and then `make install'. Note that in the Linux version the

+ 2 - 1
utils/tply/lexbase.pas

@@ -65,7 +65,8 @@ lfilename     : String;
 pasfilename   : String;
 pasfilename   : String;
 lstfilename   : String;
 lstfilename   : String;
 codfilename   : String;
 codfilename   : String;
-codfilepath   : String; { Under linux, binary and conf file
+codfilepath1,
+codfilepath2  : String; { Under linux, binary and conf file
                           are not in the same path}
                           are not in the same path}
 
 
 (* Lex input, output, list and code template file: *)
 (* Lex input, output, list and code template file: *)

+ 22 - 11
utils/tply/plex.pas

@@ -62,7 +62,7 @@ $History: LEX.PAS $
 program Lex;
 program Lex;
 
 
 uses
 uses
-  LexBase, LexTable, LexPos, LexDFA, LexOpt, LexList, LexRules, LexMsgs;
+  LexBase, LexTable, LexPos, LexDFA, LexOpt, LexList, LexRules, LexMsgs, SysUtils;
 
 
 
 
 procedure get_line;
 procedure get_line;
@@ -597,15 +597,14 @@ var i : Integer;
 
 
 begin
 begin
 {$ifdef Unix}
 {$ifdef Unix}
- {$ifdef BSD}
-  codfilepath:='/usr/local/lib/fpc/lexyacc/';
- {$else}
-  codfilepath:='/usr/lib/fpc/lexyacc/';
- {$endif}
+  codfilepath1:='/usr/local/lib/fpc/lexyacc/';
+  codfilepath2:='/usr/lib/fpc/lexyacc/';
 {$else}
 {$else}
-  codfilepath:=path(paramstr(0));
+  codfilepath1:=path(paramstr(0));
+  codfilepath2:='';
 {$endif}
 {$endif}
 
 
+
   (* sign-on: *)
   (* sign-on: *)
 
 
   writeln(sign_on);
   writeln(sign_on);
@@ -662,17 +661,29 @@ begin
   rewrite(yyout); if ioresult<>0 then fatal(cannot_open_file+pasfilename);
   rewrite(yyout); if ioresult<>0 then fatal(cannot_open_file+pasfilename);
   rewrite(yylst); if ioresult<>0 then fatal(cannot_open_file+lstfilename);
   rewrite(yylst); if ioresult<>0 then fatal(cannot_open_file+lstfilename);
 
 
-  (* search code template in current directory, then on path where Lex
-     was executed from: *)
+  (* search code template *)
   codfilename := 'yylex.cod';
   codfilename := 'yylex.cod';
   assign(yycod, codfilename);
   assign(yycod, codfilename);
   reset(yycod);
   reset(yycod);
   if ioresult<>0 then
   if ioresult<>0 then
     begin
     begin
-      codfilename := codfilepath+'yylex.cod';
+      codfilename := IncludeTrailingPathDelimiter(GetEnvironmentVariable('FPCDIR'))+'lexyacc'+DirectorySeparator+'yylex.cod';
       assign(yycod, codfilename);
       assign(yycod, codfilename);
       reset(yycod);
       reset(yycod);
-      if ioresult<>0 then fatal(cannot_open_file+codfilename);
+      if ioresult<>0 then
+        begin
+          codfilename := codfilepath1+'yylex.cod';
+          assign(yycod, codfilename);
+          reset(yycod);
+          if (codfilepath2<>'') and (ioresult<>0) then 
+            begin
+              codfilename := codfilepath2+'yylex.cod';
+              assign(yycod, codfilename);
+              reset(yycod);
+              if ioresult<>0 then 
+                fatal(cannot_open_file+codfilename);
+            end;
+        end;
     end;
     end;
 
 
   (* parse source grammar: *)
   (* parse source grammar: *)

+ 96 - 86
utils/tply/pyacc.pas

@@ -36,7 +36,7 @@ Last changes:
     updates)
     updates)
 
 
 $History: YACC.PAS $
 $History: YACC.PAS $
- *
+ * 
  * *****************  Version 2  *****************
  * *****************  Version 2  *****************
  * User: Berend       Date: 96-10-10   Time: 21:16
  * User: Berend       Date: 96-10-10   Time: 21:16
  * Updated in $/Lex and Yacc/tply
  * Updated in $/Lex and Yacc/tply
@@ -110,7 +110,7 @@ uses
     YaccChk source not available anymore PM }
     YaccChk source not available anymore PM }
 {$ENDIF}
 {$ENDIF}
 {$ENDIF}
 {$ENDIF}
-  YaccLib, YaccBase, YaccMsgs, YaccSem, YaccTabl, YaccPars;
+  YaccLib, YaccBase, YaccMsgs, YaccSem, YaccTabl, YaccPars, SysUtils;
 
 
 const ID = 257;
 const ID = 257;
 const C_ID = 258;
 const C_ID = 258;
@@ -161,28 +161,28 @@ begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
    6 : begin
    6 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
    7 : begin
    7 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
    8 : begin
    8 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
    9 : begin
    9 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   10 : begin
   10 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   11 : begin
   11 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   12 : begin
   12 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   13 : begin
   13 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   14 : begin
   14 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
@@ -191,19 +191,19 @@ begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   16 : begin
   16 : begin
-         error(rcurl_expected);
+         error(rcurl_expected); 
        end;
        end;
   17 : begin
   17 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   18 : begin
   18 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   19 : begin
   19 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   20 : begin
   20 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   21 : begin
   21 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
@@ -212,7 +212,7 @@ begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   23 : begin
   23 : begin
-         error(rbrace_expected);
+         error(rbrace_expected); 
        end;
        end;
   24 : begin
   24 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
@@ -221,7 +221,7 @@ begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   26 : begin
   26 : begin
-         error(rangle_expected);
+         error(rangle_expected); 
        end;
        end;
   27 : begin
   27 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
@@ -229,12 +229,12 @@ begin
   28 : begin
   28 : begin
          sort_types;
          sort_types;
          definitions;
          definitions;
-         next_section;
+         next_section; 
        end;
        end;
   29 : begin
   29 : begin
          next_section;
          next_section;
          generate_parser;
          generate_parser;
-         next_section;
+         next_section; 
        end;
        end;
   30 : begin
   30 : begin
          yyval := yyv[yysp-5];
          yyval := yyv[yysp-5];
@@ -242,48 +242,48 @@ begin
   31 : begin
   31 : begin
        end;
        end;
   32 : begin
   32 : begin
-         copy_rest_of_file;
+         copy_rest_of_file; 
        end;
        end;
   33 : begin
   33 : begin
        end;
        end;
   34 : begin
   34 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   35 : begin
   35 : begin
-         error(error_in_def);
+         error(error_in_def); 
        end;
        end;
   36 : begin
   36 : begin
-         startnt := ntsym(yyv[yysp-0]);
+         startnt := ntsym(yyv[yysp-0]); 
        end;
        end;
   37 : begin
   37 : begin
-         error(ident_expected);
+         error(ident_expected); 
        end;
        end;
   38 : begin
   38 : begin
-         copy_code;
+         copy_code; 
        end;
        end;
   39 : begin
   39 : begin
          yyval := yyv[yysp-2];
          yyval := yyv[yysp-2];
        end;
        end;
   40 : begin
   40 : begin
-         act_prec := 0;
+         act_prec := 0; 
        end;
        end;
   41 : begin
   41 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
        end;
        end;
   42 : begin
   42 : begin
-         act_prec := new_prec_level(left);
+         act_prec := new_prec_level(left); 
        end;
        end;
   43 : begin
   43 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
        end;
        end;
   44 : begin
   44 : begin
-         act_prec := new_prec_level(right);
+         act_prec := new_prec_level(right); 
        end;
        end;
   45 : begin
   45 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
        end;
        end;
   46 : begin
   46 : begin
-         act_prec := new_prec_level(nonassoc);
+         act_prec := new_prec_level(nonassoc); 
        end;
        end;
   47 : begin
   47 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
@@ -295,169 +295,169 @@ begin
          yyval := yyv[yysp-1];
          yyval := yyv[yysp-1];
        end;
        end;
   50 : begin
   50 : begin
-         act_type := 0;
+         act_type := 0; 
        end;
        end;
   51 : begin
   51 : begin
-         act_type := yyv[yysp-1]; add_type(yyv[yysp-1]);
+         act_type := yyv[yysp-1]; add_type(yyv[yysp-1]); 
        end;
        end;
   52 : begin
   52 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   53 : begin
   53 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   54 : begin
   54 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   55 : begin
   55 : begin
-         error(ident_expected);
+         error(ident_expected); 
        end;
        end;
   56 : begin
   56 : begin
-         error(error_in_def);
+         error(error_in_def); 
        end;
        end;
   57 : begin
   57 : begin
-         error(ident_expected);
+         error(ident_expected); 
        end;
        end;
   58 : begin
   58 : begin
          if act_type<>0 then
          if act_type<>0 then
          sym_type^[yyv[yysp-0]] := act_type;
          sym_type^[yyv[yysp-0]] := act_type;
          if act_prec<>0 then
          if act_prec<>0 then
-         sym_prec^[yyv[yysp-0]] := act_prec;
+         sym_prec^[yyv[yysp-0]] := act_prec; 
        end;
        end;
   59 : begin
   59 : begin
          litsym(yyv[yysp-0], 0);
          litsym(yyv[yysp-0], 0);
          if act_type<>0 then
          if act_type<>0 then
          sym_type^[litsym(yyv[yysp-0], 0)] := act_type;
          sym_type^[litsym(yyv[yysp-0], 0)] := act_type;
          if act_prec<>0 then
          if act_prec<>0 then
-         sym_prec^[litsym(yyv[yysp-0], 0)] := act_prec;
+         sym_prec^[litsym(yyv[yysp-0], 0)] := act_prec; 
        end;
        end;
   60 : begin
   60 : begin
          litsym(yyv[yysp-0], 0);
          litsym(yyv[yysp-0], 0);
          if act_type<>0 then
          if act_type<>0 then
          sym_type^[litsym(yyv[yysp-0], 0)] := act_type;
          sym_type^[litsym(yyv[yysp-0], 0)] := act_type;
          if act_prec<>0 then
          if act_prec<>0 then
-         sym_prec^[litsym(yyv[yysp-0], 0)] := act_prec;
+         sym_prec^[litsym(yyv[yysp-0], 0)] := act_prec; 
        end;
        end;
   61 : begin
   61 : begin
          litsym(yyv[yysp-1], 0);
          litsym(yyv[yysp-1], 0);
          if act_type<>0 then
          if act_type<>0 then
          sym_type^[litsym(yyv[yysp-1], yyv[yysp-0])] := act_type;
          sym_type^[litsym(yyv[yysp-1], yyv[yysp-0])] := act_type;
          if act_prec<>0 then
          if act_prec<>0 then
-         sym_prec^[litsym(yyv[yysp-1], 0)]  := act_prec;
+         sym_prec^[litsym(yyv[yysp-1], 0)]  := act_prec; 
        end;
        end;
   62 : begin
   62 : begin
          litsym(yyv[yysp-1], 0);
          litsym(yyv[yysp-1], 0);
          if act_type<>0 then
          if act_type<>0 then
          sym_type^[litsym(yyv[yysp-1], yyv[yysp-0])] := act_type;
          sym_type^[litsym(yyv[yysp-1], yyv[yysp-0])] := act_type;
          if act_prec<>0 then
          if act_prec<>0 then
-         sym_prec^[litsym(yyv[yysp-1], 0)]  := act_prec;
+         sym_prec^[litsym(yyv[yysp-1], 0)]  := act_prec; 
        end;
        end;
   63 : begin
   63 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   64 : begin
   64 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   65 : begin
   65 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   66 : begin
   66 : begin
-         error(ident_expected);
+         error(ident_expected); 
        end;
        end;
   67 : begin
   67 : begin
-         error(error_in_def);
+         error(error_in_def); 
        end;
        end;
   68 : begin
   68 : begin
-         error(ident_expected);
+         error(ident_expected); 
        end;
        end;
   69 : begin
   69 : begin
          if act_type<>0 then
          if act_type<>0 then
-         sym_type^[ntsym(yyv[yysp-0])] := act_type;
+         sym_type^[ntsym(yyv[yysp-0])] := act_type; 
        end;
        end;
   70 : begin
   70 : begin
-         next_section;
+         next_section; 
        end;
        end;
   71 : begin
   71 : begin
          yyval := yyv[yysp-1];
          yyval := yyv[yysp-1];
        end;
        end;
   72 : begin
   72 : begin
-         copy_code;
+         copy_code; 
        end;
        end;
   73 : begin
   73 : begin
-         next_section;
+         next_section; 
        end;
        end;
   74 : begin
   74 : begin
          yyval := yyv[yysp-4];
          yyval := yyv[yysp-4];
        end;
        end;
   75 : begin
   75 : begin
-         yyerrok;
+         yyerrok; 
        end;
        end;
   76 : begin
   76 : begin
-         error(error_in_rule);
+         error(error_in_rule); 
        end;
        end;
   77 : begin
   77 : begin
-         error(error_in_rule);
+         error(error_in_rule); 
        end;
        end;
   78 : begin
   78 : begin
-         start_rule(ntsym(yyv[yysp-0]));
+         start_rule(ntsym(yyv[yysp-0])); 
        end;
        end;
   79 : begin
   79 : begin
-         start_body;
+         start_body; 
        end;
        end;
   80 : begin
   80 : begin
-         end_body;
+         end_body; 
        end;
        end;
   81 : begin
   81 : begin
          yyval := yyv[yysp-0];
          yyval := yyv[yysp-0];
        end;
        end;
   82 : begin
   82 : begin
-         start_body;
+         start_body; 
        end;
        end;
   83 : begin
   83 : begin
-         end_body;
+         end_body; 
        end;
        end;
   84 : begin
   84 : begin
        end;
        end;
   85 : begin
   85 : begin
-         add_symbol(yyv[yysp-0]); yyerrok;
+         add_symbol(yyv[yysp-0]); yyerrok; 
        end;
        end;
   86 : begin
   86 : begin
-         add_symbol(sym(yyv[yysp-0])); yyerrok;
+         add_symbol(sym(yyv[yysp-0])); yyerrok; 
        end;
        end;
   87 : begin
   87 : begin
-         add_symbol(sym(yyv[yysp-0])); yyerrok;
+         add_symbol(sym(yyv[yysp-0])); yyerrok; 
        end;
        end;
   88 : begin
   88 : begin
-         add_action; yyerrok;
+         add_action; yyerrok; 
        end;
        end;
   89 : begin
   89 : begin
-         error(error_in_rule);
+         error(error_in_rule); 
        end;
        end;
   90 : begin
   90 : begin
-         copy_action;
+         copy_action; 
        end;
        end;
   91 : begin
   91 : begin
          yyval := yyv[yysp-2];
          yyval := yyv[yysp-2];
        end;
        end;
   92 : begin
   92 : begin
-         copy_single_action;
+         copy_single_action; 
        end;
        end;
   93 : begin
   93 : begin
        end;
        end;
   94 : begin
   94 : begin
-         add_rule_prec(yyv[yysp-0]);
+         add_rule_prec(yyv[yysp-0]); 
        end;
        end;
   95 : begin
   95 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
        end;
        end;
   96 : begin
   96 : begin
-         add_rule_prec(litsym(yyv[yysp-0], 0));
+         add_rule_prec(litsym(yyv[yysp-0], 0)); 
        end;
        end;
   97 : begin
   97 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
        end;
        end;
   98 : begin
   98 : begin
-         add_rule_prec(litsym(yyv[yysp-0], 0));
+         add_rule_prec(litsym(yyv[yysp-0], 0)); 
        end;
        end;
   99 : begin
   99 : begin
          yyval := yyv[yysp-3];
          yyval := yyv[yysp-3];
@@ -468,7 +468,7 @@ begin
  101 : begin
  101 : begin
        end;
        end;
  102 : begin
  102 : begin
-         add_action;
+         add_action; 
        end;
        end;
   end;
   end;
 end(*yyaction*);
 end(*yyaction*);
@@ -2131,10 +2131,10 @@ function yylex : integer;
             ('0'<=line[cno]) and (line[cno]<='9') or
             ('0'<=line[cno]) and (line[cno]<='9') or
             (line[cno]='_') or
             (line[cno]='_') or
             (line[cno]='.') ) do
             (line[cno]='.') ) do
-        begin
-          idstr := idstr+line[cno];
-          inc(cno)
-        end;
+	begin
+	  idstr := idstr+line[cno];
+	  inc(cno)
+	end;
       yylval := get_key(idstr);
       yylval := get_key(idstr);
       scan;
       scan;
       if not end_of_input and (line[cno]=':') then
       if not end_of_input and (line[cno]=':') then
@@ -2352,9 +2352,9 @@ function yylex : integer;
     else
     else
       case line[cno] of
       case line[cno] of
         'A'..'Z', 'a'..'z', '_' : yylex := scan_ident;
         'A'..'Z', 'a'..'z', '_' : yylex := scan_ident;
-        '''', '"' : yylex := scan_literal;
-        '0'..'9' : yylex := scan_num;
-        '%', '\' : yylex := scan_keyword;
+	'''', '"' : yylex := scan_literal;
+	'0'..'9' : yylex := scan_num;
+	'%', '\' : yylex := scan_keyword;
         '=' :
         '=' :
           if (cno<length(line)) and (line[succ(cno)]='{') then
           if (cno<length(line)) and (line[succ(cno)]='{') then
             begin
             begin
@@ -2363,7 +2363,7 @@ function yylex : integer;
             end
             end
           else
           else
             yylex := scan_char;
             yylex := scan_char;
-        else yylex := scan_char;
+	else yylex := scan_char;
       end;
       end;
     if lno=lno0 then
     if lno=lno0 then
       tokleng := cno-cno0
       tokleng := cno-cno0
@@ -2375,13 +2375,11 @@ var i : Integer;
 
 
 begin
 begin
 {$ifdef Unix}
 {$ifdef Unix}
- {$ifdef BSD}
-  codfilepath:='/usr/local/lib/fpc/lexyacc/';
- {$else}
-  codfilepath:='/usr/lib/fpc/lexyacc/';
- {$endif}
+  codfilepath1:='/usr/local/lib/fpc/lexyacc/';
+  codfilepath2:='/usr/lib/fpc/lexyacc/';
 {$else}
 {$else}
-  codfilepath:=path(paramstr(0));
+  codfilepath1:=path(paramstr(0));
+  codfilepath2:='';
 {$endif}
 {$endif}
 
 
   (* sign-on: *)
   (* sign-on: *)
@@ -2440,17 +2438,29 @@ begin
   rewrite(yyout); if ioresult<>0 then fatal(cannot_open_file+pasfilename);
   rewrite(yyout); if ioresult<>0 then fatal(cannot_open_file+pasfilename);
   rewrite(yylst); if ioresult<>0 then fatal(cannot_open_file+lstfilename);
   rewrite(yylst); if ioresult<>0 then fatal(cannot_open_file+lstfilename);
 
 
-  (* search code template in current directory, then on path where Yacc
-     was executed from: *)
+  (* search code template *)
   codfilename := 'yyparse.cod';
   codfilename := 'yyparse.cod';
   assign(yycod, codfilename);
   assign(yycod, codfilename);
   reset(yycod);
   reset(yycod);
   if ioresult<>0 then
   if ioresult<>0 then
     begin
     begin
-      codfilename := codfilepath+'yyparse.cod';
+      codfilename := IncludeTrailingPathDelimiter(GetEnvironmentVariable('FPCDIR'))+'lexyacc'+DirectorySeparator+'yyparse.cod';
       assign(yycod, codfilename);
       assign(yycod, codfilename);
       reset(yycod);
       reset(yycod);
-      if ioresult<>0 then fatal(cannot_open_file+codfilename);
+      if ioresult<>0 then
+        begin
+          codfilename := codfilepath1+'yyparse.cod';
+          assign(yycod, codfilename);
+          reset(yycod);
+          if (codfilepath2<>'') and (ioresult<>0) then 
+            begin
+              codfilename := codfilepath2+'yyparse.cod';
+              assign(yycod, codfilename);
+              reset(yycod);
+              if ioresult<>0 then 
+                fatal(cannot_open_file+codfilename);
+            end;
+        end;
     end;
     end;
 
 
   (* parse source grammar: *)
   (* parse source grammar: *)
@@ -2513,4 +2523,4 @@ begin
 
 
   halt(errors);
   halt(errors);
 
 
-end(*Yacc*).
+end(*Yacc*).

+ 24 - 28
utils/tply/pyacc.y

@@ -55,7 +55,7 @@
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 
 
 
-$Revision: 1.3 $
+$Revision: 1.5 $
 $Modtime: 96-08-01 11:24 $
 $Modtime: 96-08-01 11:24 $
 
 
 
 
@@ -129,16 +129,6 @@ $History: YACC.PAS $
 
 
 *)
 *)
 
 
-{$IFDEF MsDos}
-{$M 16384,0,655360}
-{$ENDIF}
-{$IFDEF DPMI}
-{$M 32768}
-{$ENDIF}
-{$IFDEF Windows}
-{$M 32768,0}
-{$ENDIF}
-
 {$X+}
 {$X+}
 {$I-}
 {$I-}
 program Yacc;
 program Yacc;
@@ -146,15 +136,11 @@ program Yacc;
 uses
 uses
 {$IFDEF Debug}
 {$IFDEF Debug}
 {$IFDEF DPMI}
 {$IFDEF DPMI}
-  YaccChk,
-{$ENDIF}
+  { YaccChk, removed as obsolete,
+    YaccChk source not available anymore PM }
 {$ENDIF}
 {$ENDIF}
-{$IFDEF Windows}
-{$IFNDEF Console}
-  WinCrt,
 {$ENDIF}
 {$ENDIF}
-{$ENDIF}
-  YaccLib, YaccBase, YaccMsgs, YaccSem, YaccTabl, YaccPars;
+  YaccLib, YaccBase, YaccMsgs, YaccSem, YaccTabl, YaccPars, SysUtils;
 
 
 %}
 %}
 
 
@@ -725,13 +711,11 @@ var i : Integer;
 
 
 begin
 begin
 {$ifdef Unix}
 {$ifdef Unix}
- {$ifdef BSD}
-  codfilepath:='/usr/local/lib/fpc/lexyacc/';
- {$else}
-  codfilepath:='/usr/lib/fpc/lexyacc/';
- {$endif}
+  codfilepath1:='/usr/local/lib/fpc/lexyacc/';
+  codfilepath2:='/usr/lib/fpc/lexyacc/';
 {$else}
 {$else}
-  codfilepath:=path(paramstr(0));
+  codfilepath1:=path(paramstr(0));
+  codfilepath2:='';
 {$endif}
 {$endif}
 
 
   (* sign-on: *)
   (* sign-on: *)
@@ -790,17 +774,29 @@ begin
   rewrite(yyout); if ioresult<>0 then fatal(cannot_open_file+pasfilename);
   rewrite(yyout); if ioresult<>0 then fatal(cannot_open_file+pasfilename);
   rewrite(yylst); if ioresult<>0 then fatal(cannot_open_file+lstfilename);
   rewrite(yylst); if ioresult<>0 then fatal(cannot_open_file+lstfilename);
 
 
-  (* search code template in current directory, then on path where Yacc
-     was executed from: *)
+  (* search code template *)
   codfilename := 'yyparse.cod';
   codfilename := 'yyparse.cod';
   assign(yycod, codfilename);
   assign(yycod, codfilename);
   reset(yycod);
   reset(yycod);
   if ioresult<>0 then
   if ioresult<>0 then
     begin
     begin
-      codfilename := codfilepath+'yyparse.cod';
+      codfilename := IncludeTrailingPathDelimiter(GetEnvironmentVariable('FPCDIR'))+'lexyacc'+DirectorySeparator+'yyparse.cod';
       assign(yycod, codfilename);
       assign(yycod, codfilename);
       reset(yycod);
       reset(yycod);
-      if ioresult<>0 then fatal(cannot_open_file+codfilename);
+      if ioresult<>0 then
+        begin
+          codfilename := codfilepath1+'yyparse.cod';
+          assign(yycod, codfilename);
+          reset(yycod);
+          if (codfilepath2<>'') and (ioresult<>0) then 
+            begin
+              codfilename := codfilepath2+'yyparse.cod';
+              assign(yycod, codfilename);
+              reset(yycod);
+              if ioresult<>0 then 
+                fatal(cannot_open_file+codfilename);
+            end;
+        end;
     end;
     end;
 
 
   (* parse source grammar: *)
   (* parse source grammar: *)

+ 2 - 1
utils/tply/yaccbase.pas

@@ -66,7 +66,8 @@ yfilename     : String;
 pasfilename   : String;
 pasfilename   : String;
 lstfilename   : String;
 lstfilename   : String;
 codfilename   : String;
 codfilename   : String;
-codfilepath   : String; { Under Linux,
+codfilepath1,
+codfilepath2  : String; { Under Linux,
                           binary and conf file are never in 1 directory.}
                           binary and conf file are never in 1 directory.}
 
 
 (* Yacc input, output, list and code template file: *)
 (* Yacc input, output, list and code template file: *)