1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-04 23:43:43 +02:00

b2/: add syntax switch

This commit is contained in:
Werner Almesberger 2012-04-26 03:02:48 -03:00
parent 3fff9373e3
commit 1817efd6dc
4 changed files with 55 additions and 5 deletions

View File

@ -15,8 +15,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include "lang.h"
extern int yyparse(void);
static void usage(const char *name) static void usage(const char *name)
@ -47,6 +46,6 @@ int main(int argc, char **argv)
default: default:
usage(*argv); usage(*argv);
} }
(void) yyparse(); parse_hierarchy();
return 0; return 0;
} }

19
b2/lang.h Normal file
View File

@ -0,0 +1,19 @@
/*
* lang.h - Things lang.l and lang.y export
*
* 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.
*/
#ifndef LANG_H
#define LANG_H
void parse_hierarchy(void);
void parse_characteristics(void);
#endif /* !LANG_H */

View File

@ -17,14 +17,41 @@
#include "param.h" #include "param.h"
#include "chr.h" #include "chr.h"
#include "y.tab.h" #include "y.tab.h"
#include "lang.h"
extern int yyparse(void);
static int start_token;
static int lineno = 1; static int lineno = 1;
void parse_hierarchy(void)
{
start_token = START_HIERARCHY;
yyparse();
}
void parse_characteristics(void)
{
start_token = START_CHAR;
yyparse();
}
%} %}
%% %%
%{
if (start_token) {
int tmp = start_token;
start_token = 0;
return tmp;
}
%}
[-_A-Za-z0-9()+./]+ { yylval.s = unique(yytext); [-_A-Za-z0-9()+./]+ { yylval.s = unique(yytext);
return WORD; } return WORD; }

View File

@ -71,6 +71,7 @@ static const struct field *top_field(void)
}; };
%token START_HIERARCHY START_CHAR
%token TOK_LE TOK_GE %token TOK_LE TOK_GE
%token <s> WORD %token <s> WORD
@ -86,11 +87,15 @@ static const struct field *top_field(void)
%% %%
all: all:
rule START_HIERARCHY hierarchy
;
hierarchy:
nameset hierarchy
| rule
{ {
field_dump(stderr, $1); field_dump(stderr, $1);
} }
| nameset all
; ;
nameset: nameset: