%{
/* Lexer/Scanner 
	Id: $Id: vb.l,v 1.18 2004/04/13 04:48:36 tommieb Exp tommieb $
	Revision: $Revision: 1.18 $
	Date: $Date: 2004/04/13 04:48:36 $
	Author: $Author: tommieb $

    This program is free software; you can redistribute it and/or modify
    it under the terms of version 2 of the GNU General Public License as 
    published by the Free Software Foundation.

    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Send me an email if you find this useful. 
    vbp.l is heavily borrowed from this version.
    Tom P. Brennan. 2004.

*/
#include 
#include 
#include "y.tab.h"
	/* #define return(x)	printf("%s\n", x) */
%}

whitespace		[\t ]+
literal_string	\"[^\"\n]*[\"]
eol				(_|\n|\r|\f|\012|\015)?
num				[-+]?[0-9]+(&|#)?
comment_one		(\'.*\n)
comment_two		[Rr][Ee][Mm]\ .*\n
ident_char		[_a-zA-Z.][a-zA-Z0-9._]*[\%#!$&]?
hex_literal		(&[h|H])?([0-9]+|[a-fA-F]+)*([0-9]*[a-fA-F]*)&?
oct_literal		(&[o|O])+([0-7]+)*&?
double_literal	-?(([0-9]+)|([0-9]*\.[0-9]+)([eE][-+]?[0-9]+)?)(@|&|!|#)?
character_literal 	'[A-Za-z]?'
guid_literal	(['{']+[A-Za-z0-9-]*['}']+)
shortcut_key	(['^'|'+'])?(['{']+[A-Za-z]?([0-9]*)?['}']+)
end				[Ee][Nn][Dd]
if				[Ii][Ff]
sub				[Ss][Uu][Bb]
function		[Ff][Uu][Nn][Cc][Tt][Ii][Oo][Nn]
with			[Ww][Ii][Tt][Hh]
property		[Pp][Rr][Oo][Pp][Ee][Rr][Tt][Yy]
select			[Ss][Ee][Ll][Ee][Cc][Tt]
loop			[Ll][Oo][Oo][Pp]
while			[Ww][Hh][Ii][Ll][Ee]
do				[Dd][Oo]
until			[Uu][Nn][Tt][Ii][Ll]
class			[Cc][Ll][Aa][Ss][Ss]
%{
int lineno = 1, tokenpos = 0, more_lexing = 1;
%}

%array yytext
%%
{whitespace}			{	tokenpos++; }
{comment_one}			{	tokenpos += yyleng; 
							lineno++;
						}
{comment_two}			{	tokenpos += yyleng; 
							lineno++;
						}
{eol}					{	tokenpos = 0;
							lineno++;
						}
"="						{	tokenpos += yyleng; return (OP_EQUAL); }
":"						{	tokenpos += yyleng; return (OP_SEMICOLON); }
","						{	tokenpos += yyleng; return (OP_COMMA); }
"("						{	tokenpos += yyleng; return (OP_LBRACKET); }
")"						{	tokenpos += yyleng; return (OP_RBRACKET); }
"*"						{	tokenpos += yyleng; return (OP_STAR); }
"&"						{	tokenpos += yyleng; return (CAT_OP_ONE); }
";"						{	tokenpos += yyleng; return (CAT_OP_TWO); }
"><"					{	tokenpos += yyleng; return (CMP_OP_ONE); }
"<>"					{	tokenpos += yyleng; return (CMP_OP_TWO); }
"<"						{	tokenpos += yyleng; return (CMP_OP_THREE); }
">"						{	tokenpos += yyleng; return (CMP_OP_FOUR); }
">="					{	tokenpos += yyleng; return (CMP_OP_FIVE); }
"=>"					{	tokenpos += yyleng; return (CMP_OP_SIX); }
"<="					{	tokenpos += yyleng; return (CMP_OP_SEVEN); }
"=<"					{	tokenpos += yyleng; return (CMP_OP_EIGHT); }
"+"						{	tokenpos += yyleng; return (ADD_OP_ONE); }
"-"						{	tokenpos += yyleng; return (ADD_OP_TWO); }
"/"						{	tokenpos += yyleng; return (MULT_OP_ONE); }
"\\"					{	tokenpos += yyleng; return (MULT_OP_TWO); }
"^"						{	tokenpos += yyleng; return (MULT_OP_THREE); }
"**"					{	tokenpos += yyleng; return (EXP_OP); }
"+="					{	tokenpos += yyleng; return (ASSIGN_OP_ONE); }
"-="					{	tokenpos += yyleng; return (ASSIGN_OP_TWO); }
":="					{	tokenpos += yyleng; return (ASSIGN_OP_THREE); }
{end}{whitespace}{if}				{	tokenpos += yyleng; return (ENDIF); }
{end}{whitespace}{sub}				{	tokenpos += yyleng; return (ENDSUB); }
{end}{whitespace}{function}			{	tokenpos += yyleng; return (ENDFUNCTION); }
{end}{whitespace}{with}				{	tokenpos += yyleng; return (ENDWITH); }
{end}{whitespace}{property}			{	tokenpos += yyleng; return (ENDPROPERTY2); }
{end}{whitespace}{select}			{	tokenpos += yyleng; return (ENDSELECT); }
	/*{end}{whitespace}{class}			{	tokenpos += yyleng; return (ENDCLASS); }*/
{loop}{whitespace}{until}			{	tokenpos += yyleng; return (LOOPUNTIL); }
{loop}{whitespace}{while}			{	tokenpos += yyleng; return (LOOPWHILE); }
{do}{whitespace}{while}				{	tokenpos += yyleng; return (DOWHILE); }
{do}{whitespace}{until}				{	tokenpos += yyleng; return (DOUNTIL); }
	/*{end}{whitespace}{select}			{	tokenpos += yyleng; return (ENDSELECT); }*/
"Version"				{	tokenpos += yyleng; return (VERSION); }
"Begin"					{	tokenpos += yyleng; return (VB_BEGIN); }
"End"					{	tokenpos += yyleng; return (END); }
"BeginProperty"			{	tokenpos += yyleng; return (BEGINPROPERTY); }
"EndProperty"			{	tokenpos += yyleng; return (ENDPROPERTY); }
"Attribute"				{	tokenpos += yyleng; return (ATTRIBUTE); }
"Class"					{	tokenpos += yyleng; return (CLASS); }
"Case"					{	tokenpos += yyleng; return (CASE); }
"Declare"				{	tokenpos += yyleng; return (DECLARE); }
"GoSub"					{	tokenpos += yyleng; return (GOSUB); }
"Sub"					{	tokenpos += yyleng; return (SUB); }
"Function"				{	tokenpos += yyleng; return (FUNCTION); }
"Lib"					{	tokenpos += yyleng; return (LIB); }
"Alias"					{	tokenpos += yyleng; return (ALIAS); }
"Enum"					{	tokenpos += yyleng; return (ENUM); }
"Public"				{	tokenpos += yyleng; return (PUBLIC); }
"Private"				{	tokenpos += yyleng; return (PRIVATE); }
"Erase"					{	tokenpos += yyleng; return (ERASE); }
"Event"					{	tokenpos += yyleng; return (EVENT); }
"Execute"				{	tokenpos += yyleng; return (EXECUTE); }
"ExecuteGlobal"			{	tokenpos += yyleng; return (EXECUTEGLOBAL); }
"On"					{	tokenpos += yyleng; return (ON); }
"Error"					{	tokenpos += yyleng; return (ERROR); }
	/*"Local"					{	tokenpos += yyleng; return (LOCAL); }*/
"Resume"				{	tokenpos += yyleng; return (RESUME); }
"Next"					{	tokenpos += yyleng; return (NEXT); }
"GoTo"					{	tokenpos += yyleng; return (GOTO); }
"Open"					{	tokenpos += yyleng; return (OPEN); }
"For"					{	tokenpos += yyleng; return (FOR); }
"As"					{	tokenpos += yyleng; return (AS); }
"Append"				{	tokenpos += yyleng; return (APPEND); }
"Binary"				{	tokenpos += yyleng; return (BINARY); }
"Input"					{	tokenpos += yyleng; return (INPUT); }
"Access"				{	tokenpos += yyleng; return (ACCESS); }
"Read"					{	tokenpos += yyleng; return (READ); }
"Write"					{	tokenpos += yyleng; return (WRITE); }
"Read Write"			{	tokenpos += yyleng; return (READ_WRITE); }
"Shared"				{	tokenpos += yyleng; return (SHARED); }
"Lock Read"				{	tokenpos += yyleng; return (LOCK_READ); }
"Lock Write"			{	tokenpos += yyleng; return (LOCK_WRITE); }
"Lock Read Write"		{	tokenpos += yyleng; return (LOCK_READ_WRITE); }
"Len"					{	tokenpos += yyleng; return (LEN); }
"Get"					{	tokenpos += yyleng; return (GET); }
"Close"					{	tokenpos += yyleng; return (CLOSE); }
"Seek"					{	tokenpos += yyleng; return (SEEK); }
"Line"					{	tokenpos += yyleng; return (LINE); }
"Lock"					{	tokenpos += yyleng; return (LOCK); }
"To"					{	tokenpos += yyleng; return (TO); }
"UnLock"				{	tokenpos += yyleng; return (UNLOCK); }
"Put"					{	tokenpos += yyleng; return (PUT); }
"Optional"				{	tokenpos += yyleng; return (OPTIONAL); }
"Option"				{	tokenpos += yyleng; return (OPTION); }
"Explicit"				{	tokenpos += yyleng; return (EXPLICIT); }
"Compare"				{	tokenpos += yyleng; return (COMPARE); }
"Text"					{	tokenpos += yyleng; return (TEXT); }
"Database"				{	tokenpos += yyleng; return (DATABASE); }
"Module"				{	tokenpos += yyleng; return (MODULE); }
"Base"					{	tokenpos += yyleng; return (BASE); }
"Name"					{	tokenpos += yyleng; return (NAME); }
"Property"				{	tokenpos += yyleng; return (PROPERTY); }
"Let"					{	tokenpos += yyleng; return (LET); }
"Set"					{	tokenpos += yyleng; return (SET); }
"Randomize"				{	tokenpos += yyleng; return (RANDOMIZE); }
"ReDim"					{	tokenpos += yyleng; return (REDIM); }
"Global"				{	tokenpos += yyleng; return (GLOBAL); }
"Friend"				{	tokenpos += yyleng; return (FRIEND); }
"Static"				{	tokenpos += yyleng; return (STATIC); }
"Const"					{	tokenpos += yyleng; return (CONST); }
"Default"				{	tokenpos += yyleng; return (DEFAULT); }
"ByVal"					{	tokenpos += yyleng; return (BYVAL); }
"ByRef"					{	tokenpos += yyleng; return (BYREF); }
"Dim"					{	tokenpos += yyleng; return (DIM); }
"WithEvents"			{	tokenpos += yyleng; return (WITHEVENTS); }
"New"					{	tokenpos += yyleng; return (NEW); }
"Type"					{	tokenpos += yyleng; return (TYPE); }
"Select"				{	tokenpos += yyleng; return (SELECT); }
"Else"					{	tokenpos += yyleng; return (ELSE); }
"Is"					{	tokenpos += yyleng; return (IS); }
"If"					{	tokenpos += yyleng; return (IF); }
"Then"					{	tokenpos += yyleng; return (THEN); }
"ElseIf"				{	tokenpos += yyleng; return (ELSEIF); }
"TypeOf"				{	tokenpos += yyleng; return (TYPEOF); }
"#If"					{	tokenpos += yyleng; return (HASH_IF); }
"#End"					{	tokenpos += yyleng; return (HASH_END); }
"#ElseIf"				{	tokenpos += yyleng; return (HASH_ELSEIF); }
"#Else"					{	tokenpos += yyleng; return (HASH_ELSE); }
"In"					{	tokenpos += yyleng; return (IN); }
"Do"					{	tokenpos += yyleng; return (DO); }
"While"					{	tokenpos += yyleng; return (WHILE); }
	/*"Until"					{	tokenpos += yyleng; return (UNTIL); }*/
"Loop"					{	tokenpos += yyleng; return (LOOP); }
"Wend"					{	tokenpos += yyleng; return (WEND); }
"Call"					{	tokenpos += yyleng; return (CALL); }
"Null"					{	tokenpos += yyleng; return (VB_NULL); }
"Return"				{	tokenpos += yyleng; return (RETURN); }
"Stop"					{	tokenpos += yyleng; return (STOP); }
"Preserve"				{	tokenpos += yyleng; return (PRESERVE); }
"With"					{	tokenpos += yyleng; return (WITH); }
"Boolean"				{	tokenpos += yyleng; return (BOOLEAN); }
"Byte"					{	tokenpos += yyleng; return (BYTE); }
"Control"				{	tokenpos += yyleng; return (CONTROL); }
"Currency"				{	tokenpos += yyleng; return (CURRENCY); }
"Date"					{	tokenpos += yyleng; return (DATE); }
"Decimal"				{	tokenpos += yyleng; return (DECIMAL); }
"Double"				{	tokenpos += yyleng; return (DOUBLE); }
"Form"					{	tokenpos += yyleng; return (FORM); }
"Integer"				{	tokenpos += yyleng; return (INTEGER); }
"Long"					{	tokenpos += yyleng; return (LONG); }
"Object"				{	tokenpos += yyleng; return (OBJECT); }
"Single"				{	tokenpos += yyleng; return (SINGLE); }
"String"				{	tokenpos += yyleng; return (STRING); }
"Variant"				{	tokenpos += yyleng; return (VARIANT); }
"Or"					{	tokenpos += yyleng; return (OR); }
"Xor"					{	tokenpos += yyleng; return (XOR); }
"And"					{	tokenpos += yyleng; return (AND); }
"Mod"					{	tokenpos += yyleng; return (MOD); }
"AddressOf"				{	tokenpos += yyleng; return (ADDRESSOF); }
"Not"					{	tokenpos += yyleng; return (NOT); }
"Print"					{	tokenpos += yyleng; return (PRINT); }
"Exit"					{	tokenpos += yyleng; return (EXIT); }
"True"					{	tokenpos += yyleng; return (TRUE); }
"False"					{	tokenpos += yyleng; return (FALSE); }
"Random"				{	tokenpos += yyleng; return (RANDOM); }
"Output"				{	tokenpos += yyleng; return (OUTPUT); }
"Implements"			{	tokenpos += yyleng; return (IMPLEMENTS); }
"#"						{	tokenpos += yyleng; return (OP_HASH); }
"DefBool"				{	tokenpos += yyleng; return (DEFBOOL); }
"DefByte"				{	tokenpos += yyleng; return (DEFBYTE); }
"DefInt"				{	tokenpos += yyleng; return (DEFINT); }
"DefLng"				{	tokenpos += yyleng; return (DEFLNG); }
"DefCur"				{	tokenpos += yyleng; return (DEFCUR); }
"DefSng"				{	tokenpos += yyleng; return (DEFSNG); }
"DefDbl"				{	tokenpos += yyleng; return (DEFDBL); }
"DefDec"				{	tokenpos += yyleng; return (DEFDEC); }
"DefDate"				{	tokenpos += yyleng; return (DEFDATE); }
"DefStr"				{	tokenpos += yyleng; return (DEFSTR); }
"DefObj"				{	tokenpos += yyleng; return (DEFOBJ); }
"DefVar"				{	tokenpos += yyleng; return (DEFVAR); }
"Nothing"				{	tokenpos += yyleng; return (NOTHING); }
"Each"					{	tokenpos += yyleng; return (EACH); }
"ParamArray"			{	tokenpos += yyleng; return (PARAMARRAY); }
"Mid"$?					{	tokenpos += yyleng; return (MID); }
"VB.Form"				{	tokenpos += yyleng; return (VBFORM); }
"Shortcut"				{	tokenpos += yyleng; return (SHORTCUT); }
{double_literal} {
				tokenpos += yyleng;
				yylval.numeral = atof(yytext);
				return NUMERIC_CONSTANT; 
				/* printf("A Numeric Constant!\n"); */
			}
{ident_char}		{	
						yylval.string = (char *) strdup(yytext);
						tokenpos += yyleng;
						/* printf("An identifier!\n");  */
						return IDENTIFIER; 
					}					
{literal_string}	{	
						yylval.string = (char *) strdup(yytext+1);   
						if (yylval.string[yyleng - 2] != (char)34)   
							yyerror("Unterminated string!");	     
						else									     
							yylval.string[yyleng - 2] = '\0';	     
						tokenpos += yyleng; 					     
						/* printf("A string literal!\n"); */
						return LITERAL_STRING;  			
					}
{character_literal}	{
						yylval.string = (char *) strdup(yytext);
						if (yylval.string[yyleng - 2] != '\'' )
							yyerror("Unterminated character literal!");
						else
							yylval.string[yyleng - 2] = '\0';
						tokenpos += yyleng;
						/* printf("A Character Literal!\n"); */
						return LITERAL_CHAR_CONSTANT;
					}
{hex_literal}		{	
						yylval.string = (char *) strdup(yytext);
						tokenpos += yyleng;
						/* printf("A hexadecimal literal!\n"); */
						return LITERAL_HEX; 
					}
{shortcut_key}		{
						yylval.string = (char *) strdup(yytext);
						tokenpos += yyleng;
						/* printf("A hexadecimal literal!\n"); */
						return SHORTCUT_KEY; 
					}
{guid_literal} 			{
							yylval.string = (char *) strdup(yytext);
							tokenpos += yyleng;
							/*printf("Got a GUID!");*/
							return LITERAL_GUID;
						}
"$"					{	tokenpos += yyleng; return (DOLLAR); }
.					{	yyerror("Trying to lex M$'s syntax - give up!\n");
						exit(1); 
					}
%%
#ifdef TEST_LB_LEX
main()
{
	yylex();
}
#endif
yywrap()
{
	return more_lexing;
}

    Source: geocities.com/wabbitty2002