diff --git a/README.md b/README.md index bee88f5..8d96bcf 100644 --- a/README.md +++ b/README.md @@ -264,3 +264,12 @@ cope here. `m4` is the first piece of software we need in the autotools suite. It allows macros to be defined and files to be generated from those macros. + +#### Part 20: flex 2.5.11 +`flex` is a tool for generating lexers or scanners: programs that recognize lexical patters. + +Unfortunately `flex` also depends on itself for compiling its own scanner, so +first flex 2.5.11 is compiled, with its scanner definition manually modified so that +it can be processed by lex for the Heirloom project (the required modifications +are mostly syntactical, plus a few workarounds to avoid some flex advanced features). +Then we recompile `flex` using its own lexer. diff --git a/rootfs.sh b/rootfs.sh index d0b5a5c..5ebda98 100755 --- a/rootfs.sh +++ b/rootfs.sh @@ -129,6 +129,9 @@ get_file https://ftp.gnu.org/pub/gnu/bash/bash-2.05b.tar.gz # m4 1.4 get_file https://ftp.gnu.org/gnu/m4/m4-1.4.tar.gz +# flex 2.5.11 +get_file http://download.nust.na/pub2/openpkg1/sources/DST/flex/flex-2.5.11.tar.gz + # General cleanup find tmp -name .git -exec rm -rf \; diff --git a/sysa/flex-2.5.11/files/scan.lex.l b/sysa/flex-2.5.11/files/scan.lex.l new file mode 100644 index 0000000..e0273d7 --- /dev/null +++ b/sysa/flex-2.5.11/files/scan.lex.l @@ -0,0 +1,712 @@ +/* scan.l - scanner for flex input -*-C-*- */ + +%{ +/* Copyright (c) 1990 The Regents of the University of California. */ +/* All rights reserved. */ + +/* This code is derived from software contributed to Berkeley by */ +/* Vern Paxson. */ + +/* The United States Government has rights in this work pursuant */ +/* to contract no. DE-AC03-76SF00098 between the United States */ +/* Department of Energy and the University of California. */ + +/* This file is part of flex. */ + +/* Redistribution and use in source and binary forms, with or without */ +/* modification, are permitted provided that the following conditions */ +/* are met: */ + +/* 1. Redistributions of source code must retain the above copyright */ +/* notice, this list of conditions and the following disclaimer. */ +/* 2. Redistributions in binary form must reproduce the above copyright */ +/* notice, this list of conditions and the following disclaimer in the */ +/* documentation and/or other materials provided with the distribution. */ + +/* Neither the name of the University nor the names of its contributors */ +/* may be used to endorse or promote products derived from this software */ +/* without specific prior written permission. */ + +/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ +/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ +/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ +/* PURPOSE. */ + +#define yyin_defined +#include "flexdef.h" +#include "parse.h" + +#define ACTION_ECHO add_action( yytext ) +#define ACTION_IFDEF(def, should_define) \ + { \ + if ( should_define ) \ + action_define( def, 1 ); \ + } + +#define MARK_END_OF_PROLOG mark_prolog(); + +#define YY_DECL \ + int flexscan() + +#define RETURNCHAR \ + yylval = (unsigned char) yytext[0]; \ + return CHAR; + +#define RETURNNAME \ + strcpy( nmstr, yytext ); \ + return NAME; + +#define PUT_BACK_STRING(str, start) \ + for ( i = strlen( str ) - 1; i >= start; --i ) \ + unput((str)[i]) + +#define CHECK_REJECT(str) \ + if ( all_upper( str ) ) \ + reject = true; + +#define CHECK_YYMORE(str) \ + if ( all_lower( str ) ) \ + yymore_used = true; + +#define YY_USER_INIT \ + if ( getenv("POSIXLY_CORRECT") ) \ + posix_compat = true; + +#ifndef yy_set_bol +#define yy_set_bol(x) (x ? NLSTATE : 0) +#endif + +#define YY_NULL 0 +#define yyterminate() return YY_NULL + +%} + +%e 5000 +%p 10000 +%a 100000 +%n 5000 + +%x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE +%x FIRSTCCL CCL ACTION RECOVER COMMENT ACTION_STRING +%x OPTION LINEDIR + +WS [ \t]+ +OPTWS [ \t]* +NOT_WS [^ \t\r\n] + +NL \r?\n + +NAME ([a-zA-Z_][a-zA-Z0-9_-]*) +NOT_NAME [^a-zA-Z_*\n]+ + +SCNAME {NAME} + +ESCSEQ (\\([^\n]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})) + +FIRST_CCL_CHAR ([^\\\n]|{ESCSEQ}) +CCL_CHAR ([^\\\n\]]|{ESCSEQ}) +CCL_EXPR ("[:"[a-zA-Z]+":]") + +LEXOPT [aceknopr] + +%% + static int bracelevel, didadef, indented_code; + static int doing_rule_action = false; + static int option_sense; + + int doing_codeblock = false; + int i; + Char nmdef[MAXLINE]; + + +^{WS} { indented_code = true; BEGIN(CODEBLOCK); } +^"/*" { ACTION_ECHO; BEGIN( COMMENT ); } +^#{OPTWS}line{WS} { BEGIN( LINEDIR ); } +^"%s"{NAME}? { return SCDECL; } +^"%x"{NAME}? { return XSCDECL; } +^"%{".*{NL} { + ++linenum; + line_directive_out( (FILE *) 0, 1 ); + indented_code = false; + BEGIN(CODEBLOCK); + } + +{WS} { /* discard */ } + +^"%%".* { + sectnum = 2; + bracelevel = 0; + mark_defs1(); + line_directive_out( (FILE *) 0, 1 ); + BEGIN(SECT2PROLOG); + return SECTEND; + } + +^"%pointer".*{NL} { yytext_is_array = false; ++linenum; } +^"%array".*{NL} { yytext_is_array = true; ++linenum; } + +^"%option" { BEGIN(OPTION); return OPTION_OP; } + +^"%"{LEXOPT}{OPTWS}[0-9]*{OPTWS}{NL} { ++linenum; /* ignore */ } +^"%"{LEXOPT}{WS}.*{NL} { ++linenum; /* ignore */ } + +^"%"[^sxaceknopr{}].* { synerr( _( "unrecognized '%' directive" ) ); } + +^{NAME} { + strcpy( nmstr, yytext ); + didadef = false; + BEGIN(PICKUPDEF); + } + +{SCNAME} { RETURNNAME; } +^{OPTWS}{NL} { ++linenum; /* allows blank lines in section 1 */ } +{OPTWS}{NL} { ACTION_ECHO; ++linenum; /* maybe end of comment line */ } + + +"*/" { ACTION_ECHO; BEGIN(INITIAL); } +"*" { ACTION_ECHO; } +[^*\n]+ { ACTION_ECHO; } +[^*\n]*{NL} { ++linenum; ACTION_ECHO; } + +\n { BEGIN(INITIAL); } +[0-9]+ { linenum = myctoi( yytext ); } + +\"[^"\n]*\" { + flex_free( (void *) infilename ); + infilename = copy_string( yytext + 1 ); + infilename[strlen( infilename ) - 1] = '\0'; + } + +^"%}".*{NL} { ++linenum; BEGIN(INITIAL); } + +{NAME}|{NOT_NAME}|. { ACTION_ECHO; } + +{NL} { + ++linenum; + ACTION_ECHO; + if ( indented_code ) + BEGIN(INITIAL); + } + + +{WS} { /* separates name and definition */ } + +{NOT_WS}[^\r\n]* { + strcpy( (char *) nmdef, yytext ); + + /* Skip trailing whitespace. */ + for ( i = strlen( (char *) nmdef ) - 1; + i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t'); + --i ) + ; + + nmdef[i + 1] = '\0'; + + ndinstal( nmstr, nmdef ); + didadef = true; + } + +{NL} { + if ( ! didadef ) + synerr( _( "incomplete name definition" ) ); + BEGIN(INITIAL); + ++linenum; + } + + +