2012-03-18 18:24:12 +02:00
|
|
|
%{
|
|
|
|
/*
|
|
|
|
* 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"
|
2012-04-25 23:14:39 +03:00
|
|
|
#include "chr.h"
|
2012-03-18 18:24:12 +02:00
|
|
|
#include "y.tab.h"
|
2012-04-26 09:02:48 +03:00
|
|
|
#include "lang.h"
|
2012-03-18 18:24:12 +02:00
|
|
|
|
|
|
|
|
2012-04-26 09:02:48 +03:00
|
|
|
extern int yyparse(void);
|
|
|
|
|
|
|
|
static int start_token;
|
2012-04-28 17:46:42 +03:00
|
|
|
static int expose_nl;
|
2012-04-28 17:51:47 +03:00
|
|
|
static int lineno;
|
2012-03-18 18:24:12 +02:00
|
|
|
|
2012-04-26 09:02:48 +03:00
|
|
|
|
|
|
|
void parse_hierarchy(void)
|
|
|
|
{
|
|
|
|
start_token = START_HIERARCHY;
|
2012-04-28 17:46:42 +03:00
|
|
|
expose_nl = 0;
|
2012-04-28 17:51:47 +03:00
|
|
|
lineno = 1;
|
2012-04-26 09:02:48 +03:00
|
|
|
yyparse();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void parse_characteristics(void)
|
|
|
|
{
|
|
|
|
start_token = START_CHAR;
|
2012-04-28 17:46:42 +03:00
|
|
|
expose_nl = 1;
|
2012-04-28 17:51:47 +03:00
|
|
|
lineno = 1;
|
2012-04-26 09:02:48 +03:00
|
|
|
yyparse();
|
|
|
|
}
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
%}
|
|
|
|
|
2012-04-28 17:57:47 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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()+./]
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
%%
|
|
|
|
|
2012-04-26 09:02:48 +03:00
|
|
|
%{
|
|
|
|
if (start_token) {
|
|
|
|
int tmp = start_token;
|
|
|
|
|
|
|
|
start_token = 0;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2012-04-28 17:57:47 +03:00
|
|
|
{ID}({ID}|"%")* { yylval.s = unique(yytext);
|
2012-03-18 18:24:12 +02:00
|
|
|
return WORD; }
|
|
|
|
|
|
|
|
"<=" return TOK_LE;
|
|
|
|
">=" return TOK_GE;
|
|
|
|
|
2012-04-26 01:37:53 +03:00
|
|
|
"//"[^\n]* ;
|
2012-04-28 17:51:47 +03:00
|
|
|
"/*"([^*]|("*"+([^*/])))*"*"+"/" { const char *s = yytext;
|
|
|
|
while (*s)
|
|
|
|
lineno += *s++ == '\n'; }
|
2012-04-26 01:37:53 +03:00
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
[ \t] ;
|
2012-04-28 17:46:42 +03:00
|
|
|
\n { lineno++;
|
|
|
|
if (expose_nl)
|
|
|
|
return TOK_NL; }
|
2012-03-18 18:24:12 +02:00
|
|
|
^#[^n]*\n lineno++;
|
|
|
|
|
|
|
|
. return *yytext;
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
2012-04-29 04:38:06 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
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);
|
|
|
|
}
|