iverilog/vvp/lexor.lex

106 lines
2.7 KiB
Plaintext
Raw Normal View History

2001-03-11 01:29:38 +01:00
%{
2001-03-20 03:48:40 +01:00
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: lexor.lex,v 1.5 2001/03/20 02:48:40 steve Exp $"
#endif
2001-03-11 01:29:38 +01:00
# include "parse_misc.h"
# include "compile.h"
# include "parse.h"
# include <string.h>
%}
%%
/* A label is any non-blank text that appears left justified. */
^[.$_a-zA-Z][.$_a-zA-Z0-9]* {
yylval.text = strdup(yytext);
return T_LABEL; }
/* String tokens are parsed here. Return as the token value the
contents of the string without the enclosing quotes. */
\"[^\"]*\" {
yytext[strlen(yytext)-1] = 0;
yylval.text = strdup(yytext+1);
return T_STRING; }
2001-03-11 01:29:38 +01:00
/* These are some keywords that are recognized. */
".functor" { return K_FUNCTOR; }
2001-03-18 01:37:55 +01:00
".scope" { return K_SCOPE; }
2001-03-11 01:29:38 +01:00
".thread" { return K_THREAD; }
".var" { return K_VAR; }
/* instructions start with a % character. The compiler decides what
kind of instruction this really is. The few exceptions (that have
exceptional parameter requirements) are listed first. */
"%vpi_call" {
return K_vpi_call; }
2001-03-11 01:29:38 +01:00
"%"[.$_/a-zA-Z0-9]+ {
yylval.text = strdup(yytext);
return T_INSTR; }
[0-9][0-9]* {
2001-03-20 03:45:25 +01:00
yylval.numb = strtol(yytext, 0, 0);
2001-03-11 01:29:38 +01:00
return T_NUMBER; }
"0x"[0-9a-fA-F]+ {
2001-03-20 03:45:25 +01:00
yylval.numb = strtol(yytext, 0, 0);
2001-03-11 01:29:38 +01:00
return T_NUMBER; }
/* Symbols are pretty much what is left. They are used to refer to
labels so the rule must match a string that a label would match. */
[.$_a-zA-Z][.$_a-zA-Z0-9]* {
yylval.text = strdup(yytext);
return T_SYMBOL; }
/* Accept the common assembler style comments, treat them as white
space. Of course, also skip white space. The semi-colon is
special, though, in that it is also a statement terminator. */
";".* { return ';'; }
"#".* { ; }
[ \t\b] { ; }
\n { yyline += 1; }
. { return yytext[0]; }
%%
int yywrap()
{
return -1;
}
2001-03-20 03:48:40 +01:00
/*
* $Log: lexor.lex,v $
* Revision 1.5 2001/03/20 02:48:40 steve
* Copyright notices.
*
*/