%{
static char *scan_l =
	"$Header: /private/postgres/src/parser/RCS/scan.lex,v 1.24 1992/07/28 19:11:28 mao Exp $";
/**********************************************************************
  scan.l
  lexical scanner for POSTGRES 
 **********************************************************************/

#include <ctype.h>
#include <math.h>

#include "parser/parse.h"
#include "nodes/pg_lisp.h"
#include "parser/atoms.h"


#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
	do \
	  { \
	    unsigned char c; \
	    c = input_io(); \
	    if( c ) \
	      { \
	        result = 1; \
	        buf[0] = c; \
	      } \
	    else \
	      result = YY_NULL; \
	  } \
	while(0)

extern LispValue yylval;
%}

digit		[0-9]
letter		[_A-Za-z]
letter_or_digit	[_A-Za-z0-9]

identifier	{letter}{letter_or_digit}*

self		[,()\[\].;$\:\+\-\*\/\<\>\=\|]
op_and_self	[\~\!\@\#\%\^\&\|\`\?\$\:\+\-\*\/\<\>\=]
op_only		[\~\!\@\#\%\^\&\`\?]

operator	({op_and_self}{op_and_self}+)|{op_only}+
string		\"
specialstr	\`
character	"'"

integer		{digit}+
real		{digit}+\.{digit}+([Ee][-+]?{digit}+)?

param		\${integer}

comment		"/*"

space		[ \t\n\f]
other		.

%%
{comment}	{ scancmnt();		}
"::"		{ return TYPECAST;	}
{specialstr}	{
			char buf[8192];
			scancon(buf,sizeof(buf), '`');
			yylval = lispString(buf);
			return (SCONST);
		}
{self}		{
		  return (yytext[0]);
		}
{operator}	{
			yylval = lispString((char *)yytext);
			return (Op);
		}
{param}	        {       yylval = lispInteger(atoi((char *)(&yytext[1])));		
	                return (PARAM);
                }
{integer}	{
			yylval = lispInteger(atoi((char *)yytext));		
			return (ICONST);
		}
{real}		{
			yylval = lispFloat(atof((char *)yytext));
			return (FCONST);
		}
{string}	{
			char buf[8192];
			scancon(buf,sizeof(buf), '"' );
			yylval = lispString(buf);
			return (SCONST);
		}

{character}	{
			char buf[2];
			scancon(buf, 1, '\'' );
			yylval = lispString(buf);
			return (CCONST);
		}
{identifier}	{
			ScanKeyword	*keyword;

			keyword = ScanKeywordLookup((char *)yytext);
			if (keyword != NULL) {
				yylval = lispAtom(keyword->name);
				return (keyword->value);
			} else {
				yylval = (LispValue) lispName((char *)yytext);
				return (IDENT);
			}
		}
{space}		{ /* void */		}
<<EOF>>		{
		  YY_NEW_FILE;
		  return 0;
		}
{other}		{ return (yytext[0]);	}

%%
int
lex_input( void )
{
    return input();
}

void
lex_unput( char c )
{
    unput( c );
}
