mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-17 21:16:15 +02:00
120 lines
1.8 KiB
Plaintext
120 lines
1.8 KiB
Plaintext
%{
|
|
/*
|
|
* lang.l - BOOM syntax
|
|
*
|
|
* Copyright 2012 by Werner Almesberger
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "util.h"
|
|
#include "param.h"
|
|
#include "chr.h"
|
|
#include "y.tab.h"
|
|
#include "lang.h"
|
|
|
|
|
|
extern int yyparse(void);
|
|
|
|
static int start_token;
|
|
static int expose_nl;
|
|
static int lineno;
|
|
|
|
|
|
void parse_hierarchy(void)
|
|
{
|
|
start_token = START_HIERARCHY;
|
|
expose_nl = 0;
|
|
lineno = 1;
|
|
yyparse();
|
|
}
|
|
|
|
|
|
void parse_characteristics(void)
|
|
{
|
|
start_token = START_CHAR;
|
|
expose_nl = 1;
|
|
lineno = 1;
|
|
yyparse();
|
|
}
|
|
|
|
%}
|
|
|
|
|
|
/*
|
|
* We use ID for a bit of a hack: let %... be recognized as '%' WORD but treat
|
|
* ...% still as a single WORD.
|
|
*/
|
|
|
|
ID [-_A-Za-z0-9()+./]
|
|
|
|
%%
|
|
|
|
%{
|
|
if (start_token) {
|
|
int tmp = start_token;
|
|
|
|
start_token = 0;
|
|
return tmp;
|
|
}
|
|
%}
|
|
|
|
{ID}({ID}|"%")* { yylval.s = unique(yytext);
|
|
return WORD; }
|
|
|
|
"<=" return TOK_LE;
|
|
">=" return TOK_GE;
|
|
|
|
"//"[^\n]* ;
|
|
"/*"([^*]|("*"+([^*/])))*"*"+"/" { const char *s = yytext;
|
|
while (*s)
|
|
lineno += *s++ == '\n'; }
|
|
|
|
[ \t] ;
|
|
\n { lineno++;
|
|
if (expose_nl)
|
|
return TOK_NL; }
|
|
^#[^n]*\n lineno++;
|
|
|
|
. return *yytext;
|
|
|
|
%%
|
|
|
|
|
|
void yywarnf(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
fprintf(stderr, "%d: warning: ", lineno);
|
|
vfprintf(stderr, fmt, ap) ;
|
|
fprintf(stderr, "\n");
|
|
va_end(ap);
|
|
}
|
|
|
|
|
|
void yyerrorf(const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
fprintf(stderr, "%d: ", lineno);
|
|
vfprintf(stderr, fmt, ap) ;
|
|
fprintf(stderr, "\n");
|
|
va_end(ap);
|
|
exit(1);
|
|
}
|
|
|
|
|
|
void yyerror(const char *s)
|
|
{
|
|
fprintf(stderr, "%d: %s\n", lineno, s);
|
|
exit(1);
|
|
}
|