/*
// Copyright (C) 1996 DIMACS Center, Rutgers, The State University of New Jersey
// Author(s): Sue Mniszewski (Los Alamos Nat. Lab.), Jonathan Berry
// This software is copyrighted by the DIMACS Center at Rutgers, The State
// University of New Jersey.  IT IS PROVIDED AS IS, AND THE AUTHORS, DIMACS, AND
// RUTGERS, THE STATE UNIVERSITY OF NEW JERSEY  DISCLAIM
// ALL LIABILITY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
// DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
// IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
// NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
// MODIFICATIONS.
// The authors hereby grant permission to use, copy, modify, distribute,
// and license this software and its documentation for any purpose, provided
// that existing copyright notices are retained in all copies and that this
// notice is included verbatim in any distributions. No written agreement,
// license, or royalty fee is required for any of the authorized uses.
// Modifications to this software may be copyrighted by their authors
// and need not follow the licensing terms described here, provided that
// the new terms are clearly indicated on the first page of each file where
// they apply.
// Last File Update: 21-Jul-1997
// 
*/
%{
/*================================================================*/
/*
   LINK Graph Language Input System ver 1.0
   by Sue Mniszewski
   Lexical Analysis Spec ver 1.0
*/
/*================================================================*/
/* 
 * Work around to redefine names used in YACC code that are actually C++ 
 * classes and get included here, but not used 
 */
/* put #defines to longs for C++ classes used in yacc code here */
/* bring in definitions generated by YACC */
#include "y.tab.h"
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
extern char *newString(char *old);
extern "C" {
        /**** these may have to be defined depending on the version of flex */
	void *yy_flex_alloc ( int i )  
				{ return (void*) malloc(i); }
	void *yy_flex_realloc ( void *ptr, int size )
				{ return (void*) realloc(ptr, size); }
	/*void yy_flex_free ( void *ptr )
				{ free(ptr); }*/
	int yywrap ( void )	
				{ return 1; }
	void yy_strcpy ( char *s1, const char *s2 )
				{ strcpy(s1, s2); }
}
/* parse related stuff */
int line_count;			// initialized in parseGraph.cpp
 void count_chars(char *str) 
  {
    while(*str)
      {
        if (*str == '\n') line_count ++;
        str++;
      }
  }
void yyerror(char *str)
{
  fprintf(stderr," line %d : %s\n",line_count,str);
  fflush(stderr);
}
/* allow for bigger lexemes */
#undef  YYLMAX
#define YYLMAX 16*1024
#define EMIT(result) { count_chars(yytext); \
		       return(result); }
#define DISCARD      { count_chars(yytext); }
#define EMIT_INT(result) {yylval.NUM = atoi(yytext);\
			  EMIT(result);}
#define EMIT_FLT(result) {yylval.FLT = (float) atof(yytext);\
			  EMIT(result);}
#define EMIT_DBL(result) {yylval.DBL = atof(yytext);\
			  EMIT(result);}
#define EMIT_STR(result) {yylval.STR = newString(yytext);\
			  EMIT(result);}
static char *strptr;
#define EMIT_STRIPPED_STR(result) {strptr = yytext; strptr++;               \
				   while(isspace(*strptr)) strptr++;        \
				   yylval.STR = newString(strptr);          \
				   yylval.STR[strlen(yylval.STR)-1] = '\0'; \
			           EMIT(result);}
%}
/* increase transition table for identification of STRING */
%a 7000
%o 13000
SAFE_QUOTE	\\\"
XCOMMENT	"--"
/***********************these predefinitions don't work in flex***********
digit	 	[0-9]
unsigned_const	{digit}{digit}*
int_const	([+\-])?{unsigned_const}
fp1		([+\-])?{digit}+(\.{digit}+)(E[+\-]?{digit}+)?
fp2		([+\-])?{digit}+(\.{digit}+)?(E[+\-]?{digit}+)
fp_const1   	{fp1}[fF]
fp_const2   	{fp2}[fF]
db_const1   	{fp1}([lL])?
db_const2   	{fp2}([lL])?
**************************************************************************/
%%
([+\-])?[0-9][0-9]*             EMIT_INT(INT_CONST);
([+\-])?[0-9]+(\.[0-9]*)([Ee][+\-]?[0-9]+)?([lL])? EMIT_DBL(DBL_CONST);
([+\-])?[0-9]*(\.[0-9]+)([Ee][+\-]?[0-9]+)?([lL])? EMIT_DBL(DBL_CONST);
([+\-])?[0-9]+(\.[0-9]*)?([Ee][+\-]?[0-9]+)([lL])? EMIT_DBL(DBL_CONST);
([+\-])?[0-9]+(\.[0-9]*)([Ee][+\-]?[0-9]+)?[fF]  EMIT_FLT(FLT_CONST);
([+\-])?[0-9]*(\.[0-9]+)([Ee][+\-]?[0-9]+)?[fF]  EMIT_FLT(FLT_CONST);
([+\-])?[0-9]+(\.[0-9]*)?([Ee][+\-]?[0-9]+)[fF]  EMIT_FLT(FLT_CONST);
"{"				EMIT(LBRACE);
"}"				EMIT(RBRACE);
"["				EMIT(LBRACKET);
"]"				EMIT(RBRACKET);
"("				EMIT(LPAREN);
")"				EMIT(RPAREN);
"<"				EMIT(LDIRECT);
">"				EMIT(RDIRECT);
","				EMIT(COMMA);
Graph				EMIT(ABSTRACTGRAPH);
MHyperGraph			EMIT(MHYPERGRAPH);
HyperGraph			EMIT(HYPERGRAPH);
MUHyperGraph			EMIT(MUHYPERGRAPH);
UHyperGraph			EMIT(UHYPERGRAPH);
MDHyperGraph			EMIT(MDHYPERGRAPH);
DHyperGraph			EMIT(DHYPERGRAPH);
MBinGraph			EMIT(MBINGRAPH);
BinGraph			EMIT(BINGRAPH);
MUBinGraph			EMIT(MUBINGRAPH);
UBinGraph			EMIT(UBINGRAPH);
MDBinGraph			EMIT(MDBINGRAPH);
DBinGraph			EMIT(DBINGRAPH);
Vertices			EMIT(VERTICES);
Edges				EMIT(EDGES);
location			EMIT(LOCATION);
x_subgraph			EMIT(SUBGRAPH);
back				EMIT_STR(INT_ATTR);
color                  		EMIT_STR(STR_ATTR);
direction			EMIT_STR(INT_ATTR);
distance			EMIT_STR(DBL_ATTR);
finish_time			EMIT_STR(INT_ATTR);
graph_name			EMIT_STR(STR_ATTR);
label             		EMIT_STR(STR_ATTR);
low				EMIT_STR(INT_ATTR);
mark				EMIT_STR(INT_ATTR);
name             		EMIT_STR(STR_ATTR);
open				EMIT_STR(INT_ATTR);
pred				EMIT_STR(VPTR_ATTR);
forefather			EMIT_STR(VPTR_ATTR);
start_time			EMIT_STR(INT_ATTR);
size 	                 	EMIT_STR(INT_ATTR);
weight				EMIT_STR(DBL_ATTR);
width				EMIT_STR(INT_ATTR);
x				EMIT_STR(DBL_ATTR);
y				EMIT_STR(DBL_ATTR);
[a-zA-Z_][a-zA-Z0-9_]*		EMIT_STR(IDENT);
\"([^"\n]|\\\"|\n)*\"		EMIT_STRIPPED_STR(STR_CONST);
{XCOMMENT}.*$			DISCARD;
[ \t\n\14]			DISCARD;
.				EMIT_STR(ERROR_TOKEN);
