%{
  /*
   morphg.lex - morphological generator created automatically from a
   morphological analyser developed by Kevin Humphreys
   <kwh@dcs.shef.ac.uk> and John Carroll
   <John.Carroll@cogs.susx.ac.uk> and Guido Minnen
   <Guido.Minnen@cogs.susx.ac.uk>.

   Copyright (c) 1998-2001 University of Sussex
   All rights reserved.

   Redistribution and use of source and derived binary forms are
   permitted provided that: 
   - they are not to be used in commercial products
   - the above copyright notice and this paragraph are duplicated in
   all such forms
   - any documentation, advertising materials, and other materials
   related to such distribution and use acknowledge that the software
   was developed by John Carroll <john.carroll@cogs.susx.ac.uk> and
   Guido Minnen <Guido.Minnen@cogs.susx.ac.uk> and refer to the
   following related publication:

     Guido Minnen, John Carroll and Darren Pearce. 2000. Robust, Applied
     Morphological Generation. In Proceedings of the First International
     Natural Language Generation Conference (INLG), Mitzpe Ramon, Israel.
     201-208.

   The name of University of Sheffield may not 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 merchantibility and fitness for a particular purpose.

   If you make any changes, the authors would appreciate it
   if you sent them details of what you have done.

   Covers the English productive affixes:

   -s	  plural of nouns, 3rd sing pres of verbs
   -ed	  past tense
   -en    past participle
   -ing	  progressive of verbs

   Compilation: flex -i -8 -Cfe -omorphg.yy.c morphg.lex
                gcc -o morphg morphg.yy.c

   Usage:       morphg [options:actuf verbstem-file] < file.txt 
   N.B. A file with a list of verb stems that allow for 
	consonant doubling in British English (called 'verbstem.list')
        is expected to be present in the same directory as morphg

   Options: (Are the same as those of morpha; for morphg option 'a'
             is vacuous though.)
            c this option ensures that casing is left untouched
              wherever possible
            t this option ensures that tags are output; N.B. if
              the option 'u' is set and the input text is tagged 
	      the tag will always be output even if this option 
	      is not set
            u this option should be used when the input file is 
	      untagged
            f a file with British English verb stems that allow for 
	      consonant doubling (called 'verbstem.list') is expected 
	      to be present in the same directory as morphg; using 
	      this option it is possible to specify a different file,
	      i.e., 'verbstem-file'

   Guido Minnen <Guido.Minnen@cogs.susx.ac.uk>
   original version: 03/12/98 - normal form and  different treatment of 
	                        consonant doubling introduced in order to 
				support automatic reversal; usage of 
				external list of verb stems (derived 
		                from the BNC) that allow for consonant 
				doubling in British English introduced
	    revised: 19/05/99 - improvement of option handling
	    revised: 03/08/99 - introduction of option -f; adaption of 
	                        normal form to avoid the loss of case 
   				information
	    revised: 01/09/99 - changed from normal form to compiler 
	                        directives format
	    revised: 02/12/99 - incorporated data extracted from the 
	 			CELEX lexical databases 
	    revised: 07/06/00 - adaption of Makefile to enable various 
	                        Flex optimizations 

   John Carroll <John.Carroll@cogs.susx.ac.uk>
            revised: 25/01/01 - new version of inversion program,
                                associated changes to directives; new
                                C preprocessor flag 'interactive'

   Diana McCarthy <dianam@cogs.susx.ac.uk>
            revised: 23/02/02 - fixed bug reading in verbstem file.
 
   John Carroll <John.Carroll@cogs.susx.ac.uk>
            revised: 19/06/02 - inversion was incorrect for e.g. verbs
                                ending VVC -- fixed
 
   Exception lists are taken from WordNet 1.5, the CELEX lexical
   database (Copyright Centre for Lexical Information; Baayen,
   Piepenbrock and Van Rijn; 1993) and various other corpora and MRDs.

   Many thanks to Chris Brew, Bill Fisher, Gerald Gazdar, Dale
   Gerdemann, Adam Kilgarriff and Ehud Reiter for suggested improvements 
   
   WordNet> WordNet 1.5 Copyright 1995 by Princeton University.
   WordNet> All rights reseved.
   WordNet>
   WordNet> THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON
   WordNet> UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
   WordNet> IMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, PRINCETON
   WordNet> UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANT-
   WordNet> ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE
   WordNet> OF THE LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT
   WordNet> INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR
   WordNet> OTHER RIGHTS.
   WordNet>
   WordNet> The name of Princeton University or Princeton may not be used in
   WordNet> advertising or publicity pertaining to distribution of the software
   WordNet> and/or database.  Title to copyright in this software, database and
   WordNet> any associated documentation shall at all times remain with
   WordNet> Princeton Univerisy and LICENSEE agrees to preserve same.

  */
 
#include <string.h>

#ifdef interactive 
#define YY_INPUT(buf,result,max_size) \
              { \
              int c = getchar(); \
              result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \
              }
#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ); fflush(yyout)
#endif

#define TRUE  (1==1)
#define FALSE  (1==0)
#define forever (TRUE)
#define UnSetOption(o)	(options.o = 0)
#define SetOption(o)	(options.o = 1)
#define Option(o)	(options.o)
#define MAXSTR    200

#ifdef __cplusplus
void downcase( char *text, int len );
char *upcase( char *vanilla_text );
char up8(char c);
int scmp(const char *a, const char *b);
int vcmp(const void *a, const void *b);
int gstem(int del, char *add);
int gcondub_stem(int del, char *add);
int gsemi_reg_stem(int del, char *add);
void capitalise( char *text, int len );
int proper_name_stem();
int common_noun_stem();
int gnull_stem();
int nnull_stem();
char get_option(int argc, char *argv[], char *options, int *arg, , int *i);
int read_verbstem(char *fn);
BOOL read_verbstem_file(char *argv[],unsigned int maxbuff, int *arg, int *i,char letter);
void set_up_options(int argc, char *argv[]);
#endif

int lex_tag;

typedef struct
    {unsigned int
		print_affixes : 1,
		change_case   : 1,
                tag_output    : 1,
		fspec         : 1;
} options_st;
typedef int BOOL;

options_st options;
int state;

%}

%option noyywrap

%x verb noun any scan

A ['+a-z0-9]
V [aeiou]
VY [aeiouy]
C [bcdfghjklmnpqrstvwxyz]
CXY [bcdfghjklmnpqrstvwxz]
CXY2 "bb"|"cc"|"dd"|"ff"|"gg"|"hh"|"jj"|"kk"|"ll"|"mm"|"nn"|"pp"|"qq"|"rr"|"ss"|"tt"|"vv"|"ww"|"xx"|"zz"
S2 "ss"|"zz"
S [sxz]|([cs]"h")
PRE "be"|"ex"|"in"|"mis"|"pre"|"pro"|"re"
EDING "en"|"ed"|"ing"
ESEDING "en"|"es"|"ed"|"ing"

AFFS "+en"|"+ed"|"+"
SAFFS "+s"
ALLAFFS "+en"|"+ed"|"+s"|"+"

G [^[:space:]_<>]
G- [^[:space:]_<>-]
SKIP [[:space:]]

