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

%{                                                     

 /* some needed headers: */                            
#include<iostream>                                   
#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();                 \
  }                                               \
}                                                      

%}                                                     



%{

char *typeset_pred(char *pred);

%}

/************************************************
 * 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=create(yytext);return (OPEN);}


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


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


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


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


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


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


","		{ *rvalue=join(
			create(", "));
			
		 return(COMMA);}


"##"		{ *rvalue=join(
			create("$[]$"));
			
		 return(BLOCK);}


"-->"		{ *rvalue=join(
			create("$\\longrightarrow$"));
			
		 return(ARROW);}


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


":="		{ *rvalue=join(
			create("$\\leftarrow$"));
			
		 return(BECOMES);}


"skip"		{ *rvalue=join(
			create("\\underline{\\bf skip}"));
			
		 return(SKIP);}


"abort"		{ *rvalue=join(
			create("\\underline{\\bf abort}"));
			
		 return(ABORT);}


"array"		{ *rvalue=join(
			create("{\\bf array}"));
			
		 return(ARRAY);}


"of"		{ *rvalue=join(
			create("{\\bf of}"));
			
		 return(OF);}


"do"		{ *rvalue=join(
			create("\\underline{\\bf do}"));
			
		 return(DO);}


"od"		{ *rvalue=join(
			create("\\underline{\\bf od}"));
			
		 return(OD);}


"if"		{ *rvalue=join(
			create("\\underline{\\bf if}"));
			
		 return(IF);}


"fi"		{ *rvalue=join(
			create("\\underline{\\bf fi}"));
			
		 return(FI);}


"|["		{ *rvalue=join(
			create("$|[$"));
			
		 return(OPENBLOCK);}


"]|"		{ *rvalue=join(
			create("$]|$"));
			
		 return(CLOSEBLOCK);}


"!"		{ *rvalue=join(
			create("$\\neg$"));
			
		 return(UNARY_OP);}


"~"		{ *rvalue=join(
			create("$\\neg$"));
			
		 return(UNARY_OP);}


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


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


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


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


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


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


"*"		{ *rvalue=join(
			create("$\\times$"));
			
		 return(BINARY_OP);}


"/"		{ *rvalue=join(
			create("\\underline{\\bf div}"));
			
		 return(BINARY_OP);}


"div"		{ *rvalue=join(
			create("\\underline{\\bf div}"));
			
		 return(BINARY_OP);}


"%"		{ *rvalue=join(
			create("\\underline{\\bf mod}"));
			
		 return(BINARY_OP);}


"mod"		{ *rvalue=join(
			create("\\underline{\\bf mod}"));
			
		 return(BINARY_OP);}


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


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


"!="		{ *rvalue=join(
			create("$\\neq$"));
			
		 return(BINARY_OP);}


"/="		{ *rvalue=join(
			create("$\\neq$"));
			
		 return(BINARY_OP);}


"max"		{ *rvalue=join(
			create("\\underline{\\bf max}"));
			
		 return(BINARY_OP);}


"min"		{ *rvalue=join(
			create("\\underline{\\bf min}"));
			
		 return(BINARY_OP);}


"var"		{ *rvalue=join(
			create("\\underline{\\bf var}"));
			
		 return(ACCESS);}


"con"		{ *rvalue=join(
			create("\\underline{\\bf con}"));
			
		 return(ACCESS);}


"swap"		{ *rvalue=join(
			create("\\underline{\\bf swap}"));
			
		 return(SWAP);}


"int"		{ *rvalue=join(
			create("{\\bf integer}"));
			
		 return(TYPE);}


"integer"		{ *rvalue=join(
			create("{\\bf integer}"));
			
		 return(TYPE);}


"bool"		{ *rvalue=join(
			create("{\\bf boolean}"));
			
		 return(TYPE);}


"boolean"		{ *rvalue=join(
			create("{\\bf boolean}"));
			
		 return(TYPE);}


[a-zA-Z]+		{ *rvalue=join(
			join(
				join(
				create("$\\mathit{"),
				create(yytext)
			),
				create("}$")
			));
			
		 return(ID);}


[0-9][0-9]*		{ *rvalue=join(
			join(
				join(
				create("$"),
				create(yytext)
			),
				create("$")
			));
			
		 return(NUMBER);}


"{>".*"<}"		{ *rvalue=join(
			join(
				join(
				create("$\\{"),
				create(typeset_pred(yytext))
			),
				create(" \\}$")
			));
			
		 return(PREDICATE);}


^"@use\ ".*		{ *rvalue=join(
			join(
				join(
				create("\n"),
				create(yytext)
			),
				create("\n")
			));
			
		 return(CHUNK);}


[\t\ \n]		/* 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: *
 ***********************************************/

