// idbg - IJVM debugger.
// Copyright 2000 Tom Rothamel <tom-idbg@onegeek.org>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  

/* -*-c++-*- */

%{
#include <stdio.h>
#include "idbg.h"
#include "commands.h"
%}

%option noyywrap

HEXDIGIT [0-9A-Fa-f]
DIGIT [0-9]

SCHAR [a-zA-Z_]
CHAR [0-9a-zA-Z_]

%x qstr

%%

quit { return QUIT; }
exit { return QUIT; }

reinit { return REINIT; }
restart { return REINIT; }

run { return RUN; }
go { return GO; }
step { return STEP; }
next { return NEXT; }
show { return SHOW; }
disasm { return DISASM; }
trace { return TRACE; }
stack { return STACK; }
vars { return VARS; }

set { return SET; }
stop { return STOP; }
page { return page; }
quick { return quick; }
log { return LOG; }

break { return BREAK; }
breakpoint { return BREAK; }
breaks { return BREAK; }
breakpoints { return BREAK; }

drop { return DROP; }

[pP][cC] { return PC; }

[ \t\n]+

0x{HEXDIGIT}+ {
	int i = 2;
	int t = 0;

	while(yytext[i]) {
		t *= 16;
		if (yytext[i] >= 'a') { t += 10 + yytext[i] - 'a'; }
		else if (yytext[i] >= 'A') { t += 10 + yytext[i] - 'A'; }
		else { t += yytext[i] - '0'; }
		i++;
	}

	yylval.i = t;
	return NUMBER;
}

-?{DIGIT}+ {
	yylval.i = atoi(yytext);
	return NUMBER;
}

{SCHAR}{CHAR}* {
	yylval.s = strdup(yytext);

	if (lookup_method_name(yytext)) return METHODNAME;
	return NAME;
}

\" { BEGIN(qstr); }

<qstr>\\. { yymore(); }
<qstr>[^\"\\]+ { yymore(); }
<qstr>\" {
        BEGIN(INITIAL);

	yylval.s = strdup(yytext);
	yylval.s[strlen(yylval.s) - 1] = 0;
	
	return NAME;
} 


. { return yytext[0]; }

%%

void scan_string(char *s) {
	BEGIN(INITIAL);
	yy_scan_string(s);
}
