/************************************************
 * This is a flex file generated by pretzel     *
 *                                              *
 ************************************************/

%{                                                     

 /* some needed headers: */                            
#include<iostream.h>                                   
#include"attr.h"                                     

 /* we'll define yywrap() which is needed for the scanner
  * here, so we won't have to bother about it if we're 
  * doing the standard case. You can define your own version
  * by #undef'ing PSCAN_YYWRAP and supplying your own definition
  * in the definitions section.                        
  */                                                   
#define PSCAN_YYWRAP                                   

 /* input will come from this istream */               
static istream * yyin_stream;                          

 /* redefine YYINPUT to read from input streams */     
#undef YY_INPUT                                        
#define YY_INPUT(buf, result, max_size) {         \
  if (yyin_stream->eof()) result=YY_NULL;         \
  else {                                          \
    yyin_stream->read(buf, max_size);             \
    result=yyin_stream->gcount();                 \
  }                                               \
}                                                      

%}                                                     


/* this is an example formatted token file for a pascal to test the
 * prettyprinting scanner generator. It was oiginally aimed to produce
 * TeX code to be formatted with the cwebmac package.
 */

%{
#define PSCAN_NAME pascan
#define PSCAN_INIT_NAME pascan_init
%}



/************************************************
 * some pretzel definitions start here:         *
 ***********************************************/

%{                                                     

 /* the default name of the include file with the token
  * code definitions is stored in PTOKDEFS_NAME and    
  * defaults to `ptokdefs'.                            
  */                                                   
#ifndef PTOKDEFS_NAME                                  
#define PTOKDEFS_NAME "ptokdefs.h"                   
#endif                                                 

 /* now we have to include the token definitions */    
#include PTOKDEFS_NAME                                 

 /* allow user to choose generated scanner class name*/
#ifndef PSCAN_NAME                                     
#define PSCAN_NAME Ppscan                              
#include "Ppscan.h"                                  
#endif                                                 

 /* redefine the interface of the scanner */           
#undef YY_DECL                                         
#define YY_DECL int yylex (Attribute**rvalue)          

 /* here's the standard version of yywrap() */         
#ifdef PSCAN_YYWRAP                                    
extern "C" int yywrap() {                            
    return(1);                                         
}                                                      
#endif                                                 

%}                                                     


%%


"<>"		{ *rvalue=join(
			create("$\\neq$"));
			
		 return(MATH);}


"<="		{ *rvalue=join(
			create("$\\leq$"));
			
		 return(MATH);}


">="		{ *rvalue=join(
			create("$\\geq$"));
			
		 return(MATH);}


":="		{ *rvalue=join(
			create("\\hbox{${}\\mathrel{:=}{}$}"));
			
		 return(MATH);}


'([^']|'')*'		{ *rvalue=join(
			join(
				join(
				create("\\.{"),
				create(yytext)
			),
				create("}")
			));
			
		 return(SIMP);}


"("		{*rvalue=create(yytext);return (OPEN);}


")"		{int i; *rvalue=join(
			 in_table(yytext) ? create("it") :
						create("bf") );
			
		 return(a[i]);  return(CLOSE);}


"["		{*rvalue=create(yytext);return (OPEN);}


"]"		{*rvalue=create(yytext);return (CLOSE);}


"*"		{ *rvalue=join(
			create("$\\ast$"));
			
		 return(MATH);}


","		{ *rvalue=join(
			join(
				create(yytext),
				create(opt9)
			));
			
		 return(MATH);}


".."		{*rvalue=create(yytext);return (MATH);}


"."		{*rvalue=create(yytext);return (SIMP);}


":"		{*rvalue=create(yytext);return (COLON);}


";"		{*rvalue=create(yytext);return (SEMI);}


"="		{*rvalue=create(yytext);return (MATH);}


"+"		{*rvalue=create(yytext);return (MATH);}


"-"		{*rvalue=create(yytext);return (MATH);}


"<"		{ *rvalue=join(
			create("$<$"));
			
		 return(MATH);}


">"		{ *rvalue=join(
			create("$>$"));
			
		 return(MATH);}


"/"		{*rvalue=create(yytext);return (MATH);}


"_"[a-zA-Z0-9]*		{ *rvalue=join(
			join(
				create("\\"),
				create(yytext)
			));
			
		 return(ID_TYPE);}


[0-9]+		{*rvalue=create(yytext);return (SIMP);}


[0-9]*"."[0-9]+		{*rvalue=create(yytext);return (SIMP);}


and		{ *rvalue=join(
			create("\\AND "));
			
		 return(MATH);}


array		{ *rvalue=join(
			create("\\&{array}"));
			
		 return(ALPHA);}


begin		{ *rvalue=join(
			join(
				join(
				create(force),
				create("\n")
			),
				create("\\&{begin}")
			));
			
		 return(BEG);}


boolean		{ *rvalue=join(
			create("\\&{boolean}"));
			
		 return(SIMP);}


case		{ *rvalue=join(
			join(
				join(
				create(force),
				create("\\&{case}")
			),
				create(cancel)
			));
			
		 return(CASE);}


const		{ *rvalue=join(
			join(
				join(
				create(force),
				create(backup)
			),
				create("\\&{const}")
			));
			
		 return(INTRO);}


div		{ *rvalue=join(
			create(" \\&{div} "));
			
		 return(MATH);}


do		{ *rvalue=join(
			create("\\&{do}"));
			
		 return(OMEGA);}


downto		{ *rvalue=join(
			create("\\&{downto}"));
			
		 return(MATH);}


else		{ *rvalue=join(
			create("\\&{else}"));
			
		 return(ELSE);}


end		{ *rvalue=join(
			create("\\&{end}"));
			
		 return(END);}


for		{ *rvalue=join(
			create("\\&{for}"));
			
		 return(ALPHA);}


function		{ *rvalue=join(
			join(
				join(
				create(big_force),
				create(backup)
			),
				create("\\&{function} ")
			));
			
		 return(PROC);}


if		{ *rvalue=join(
			create("\\&{if}"));
			
		 return(ALPHA);}


integer		{ *rvalue=join(
			create("\\&{integer}"));
			
		 return(SIMP);}


mod		{ *rvalue=join(
			create("\\&{mod}"));
			
		 return(MATH);}


not		{ *rvalue=join(
			create("\\neg "));
			
		 return(MATH);}


of		{ *rvalue=join(
			join(
				create("\\&{of} "),
				create(cancel)
			));
			
		 return(OMEGA);}


or		{ *rvalue=join(
			create("\\V "));
			
		 return(MATH);}


procedure		{ *rvalue=join(
			join(
				join(
				create(big_force),
				create(backup)
			),
				create("\\&{procedure} ")
			));
			
		 return(PROC);}


program		{ *rvalue=join(
			join(
				join(
				create(big_force),
				create(backup)
			),
				create("\\&{program} ")
			));
			
		 return(PROC);}


readln		{ *rvalue=join(
			create("\\&{readln}"));
			
		 return(SIMP);}


real		{ *rvalue=join(
			create("\\&{real}"));
			
		 return(SIMP);}


record		{ *rvalue=join(
			create("\\&{record}"));
			
		 return(RECORD);}


repeat		{ *rvalue=join(
			join(
				create(force),
				create("\\&{repeat}")
			));
			
		 return(BEG);}


then		{ *rvalue=join(
			create("\\&{then}"));
			
		 return(OMEGA);}


to		{ *rvalue=join(
			create(" \\&{to} "));
			
		 return(MATH);}


type		{ *rvalue=join(
			join(
				join(
				create(force),
				create(backup)
			),
				create("\\&{type}")
			));
			
		 return(INTRO);}


until		{ *rvalue=join(
			join(
				create(force),
				create("\\&{until}")
			));
			
		 return(UNTIL);}


var		{ *rvalue=join(
			join(
				join(
				create(force),
				create(backup)
			),
				create("\\&{var} ")
			));
			
		 return(INTRO);}


while		{ *rvalue=join(
			join(
				create(force),
				create("\\&{while}")
			));
			
		 return(ALPHA);}


with		{ *rvalue=join(
			join(
				create(force),
				create("\\&{with}")
			));
			
		 return(ALPHA);}


write		{ *rvalue=join(
			create("\\&{write}"));
			
		 return(SIMP);}


writeln		{ *rvalue=join(
			create("\\&{writeln}"));
			
		 return(SIMP);}


"{"[^}]*"}"		{ *rvalue=join(
			join(
				join(
				create("\\hbox{$\\{$\\.{"),
				create(yytext)
			),
				create("}$\\}$}")
			));
			
		 return(COMMENT);}


[a-zA-Z][a-zA-Z0-9]*		{*rvalue=create(yytext);return (ID_TYPE);}


[\t\ \n]		/* empty */


.		/* empty */


%%
/************************************************
 * additional pretzel C code follows here:      *
 ***********************************************/
PSCAN_NAME::PSCAN_NAME (istream* is ) : Pscan(is)
{                                              
    yyin_stream = is;                          
}                                              
PSCAN_NAME::scan(Attribute* *rvalue)           
{                                              
    return(yylex(rvalue));                     
}                                              
PSCAN_NAME::~PSCAN_NAME ()                     
{                                              
    yyrestart(NULL);                           
}                                              
/************************************************
 * additional user defined C code follows here: *
 ***********************************************/

