mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
removed test lex/yacc parser
This commit is contained in:
parent
6dd3b3d7ad
commit
89408942bb
6 changed files with 0 additions and 3762 deletions
|
@ -1,19 +0,0 @@
|
|||
%{
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "boolean.tab.h" // to get the token types that we return
|
||||
|
||||
%}
|
||||
|
||||
%option prefix="log_expression_"
|
||||
%option noyywrap
|
||||
|
||||
%%
|
||||
|
||||
[ \t\n] ; // ignore whitespace
|
||||
[&] ; //operators
|
||||
[a-b]+ { log_expression_lval.token = strdup(log_expression_text); return TOKEN; }
|
||||
[0-9]+ { log_expression_lval.constant = atoi(log_expression_text); return CONSTANT; }
|
||||
|
||||
%%
|
|
@ -1,241 +0,0 @@
|
|||
Grammatik
|
||||
|
||||
0 $accept: input $end
|
||||
|
||||
1 input: %empty
|
||||
2 | exp '\n'
|
||||
|
||||
3 exp: comp
|
||||
4 | exp '&' exp
|
||||
5 | exp '|' exp
|
||||
6 | exp '^' exp
|
||||
7 | '~' exp
|
||||
8 | '(' exp ')'
|
||||
|
||||
9 comp: CONSTANT
|
||||
10 | TOKEN
|
||||
|
||||
|
||||
Terminale und die Regeln, in denen sie verwendet werden
|
||||
|
||||
$end (0) 0
|
||||
'\n' (10) 2
|
||||
'&' (38) 4
|
||||
'(' (40) 8
|
||||
')' (41) 8
|
||||
'^' (94) 6
|
||||
'|' (124) 5
|
||||
'~' (126) 7
|
||||
error (256)
|
||||
TOKEN (258) 10
|
||||
CONSTANT (259) 9
|
||||
NEG (260)
|
||||
|
||||
|
||||
Nicht-Terminal und die Regeln, in denen sie verwendet werden
|
||||
|
||||
$accept (13)
|
||||
auf der linken Seite: 0
|
||||
input (14)
|
||||
auf der linken Seite: 1 2, auf der rechten Seite: 0
|
||||
exp (15)
|
||||
auf der linken Seite: 3 4 5 6 7 8, auf der rechten Seite: 2 4 5
|
||||
6 7 8
|
||||
comp (16)
|
||||
auf der linken Seite: 9 10, auf der rechten Seite: 3
|
||||
|
||||
|
||||
Zustand 0
|
||||
|
||||
0 $accept: . input $end
|
||||
|
||||
TOKEN schiebe und gehe zu Zustand 1 über
|
||||
CONSTANT schiebe und gehe zu Zustand 2 über
|
||||
'~' schiebe und gehe zu Zustand 3 über
|
||||
'(' schiebe und gehe zu Zustand 4 über
|
||||
|
||||
$default reduziere mit Regel 1 (input)
|
||||
|
||||
input gehe zu Zustand 5 über
|
||||
exp gehe zu Zustand 6 über
|
||||
comp gehe zu Zustand 7 über
|
||||
|
||||
|
||||
Zustand 1
|
||||
|
||||
10 comp: TOKEN .
|
||||
|
||||
$default reduziere mit Regel 10 (comp)
|
||||
|
||||
|
||||
Zustand 2
|
||||
|
||||
9 comp: CONSTANT .
|
||||
|
||||
$default reduziere mit Regel 9 (comp)
|
||||
|
||||
|
||||
Zustand 3
|
||||
|
||||
7 exp: '~' . exp
|
||||
|
||||
TOKEN schiebe und gehe zu Zustand 1 über
|
||||
CONSTANT schiebe und gehe zu Zustand 2 über
|
||||
'~' schiebe und gehe zu Zustand 3 über
|
||||
'(' schiebe und gehe zu Zustand 4 über
|
||||
|
||||
exp gehe zu Zustand 8 über
|
||||
comp gehe zu Zustand 7 über
|
||||
|
||||
|
||||
Zustand 4
|
||||
|
||||
8 exp: '(' . exp ')'
|
||||
|
||||
TOKEN schiebe und gehe zu Zustand 1 über
|
||||
CONSTANT schiebe und gehe zu Zustand 2 über
|
||||
'~' schiebe und gehe zu Zustand 3 über
|
||||
'(' schiebe und gehe zu Zustand 4 über
|
||||
|
||||
exp gehe zu Zustand 9 über
|
||||
comp gehe zu Zustand 7 über
|
||||
|
||||
|
||||
Zustand 5
|
||||
|
||||
0 $accept: input . $end
|
||||
|
||||
$end schiebe und gehe zu Zustand 10 über
|
||||
|
||||
|
||||
Zustand 6
|
||||
|
||||
2 input: exp . '\n'
|
||||
4 exp: exp . '&' exp
|
||||
5 | exp . '|' exp
|
||||
6 | exp . '^' exp
|
||||
|
||||
'&' schiebe und gehe zu Zustand 11 über
|
||||
'|' schiebe und gehe zu Zustand 12 über
|
||||
'^' schiebe und gehe zu Zustand 13 über
|
||||
'\n' schiebe und gehe zu Zustand 14 über
|
||||
|
||||
|
||||
Zustand 7
|
||||
|
||||
3 exp: comp .
|
||||
|
||||
$default reduziere mit Regel 3 (exp)
|
||||
|
||||
|
||||
Zustand 8
|
||||
|
||||
4 exp: exp . '&' exp
|
||||
5 | exp . '|' exp
|
||||
6 | exp . '^' exp
|
||||
7 | '~' exp .
|
||||
|
||||
$default reduziere mit Regel 7 (exp)
|
||||
|
||||
|
||||
Zustand 9
|
||||
|
||||
4 exp: exp . '&' exp
|
||||
5 | exp . '|' exp
|
||||
6 | exp . '^' exp
|
||||
8 | '(' exp . ')'
|
||||
|
||||
'&' schiebe und gehe zu Zustand 11 über
|
||||
'|' schiebe und gehe zu Zustand 12 über
|
||||
'^' schiebe und gehe zu Zustand 13 über
|
||||
')' schiebe und gehe zu Zustand 15 über
|
||||
|
||||
|
||||
Zustand 10
|
||||
|
||||
0 $accept: input $end .
|
||||
|
||||
$default annehmen
|
||||
|
||||
|
||||
Zustand 11
|
||||
|
||||
4 exp: exp '&' . exp
|
||||
|
||||
TOKEN schiebe und gehe zu Zustand 1 über
|
||||
CONSTANT schiebe und gehe zu Zustand 2 über
|
||||
'~' schiebe und gehe zu Zustand 3 über
|
||||
'(' schiebe und gehe zu Zustand 4 über
|
||||
|
||||
exp gehe zu Zustand 16 über
|
||||
comp gehe zu Zustand 7 über
|
||||
|
||||
|
||||
Zustand 12
|
||||
|
||||
5 exp: exp '|' . exp
|
||||
|
||||
TOKEN schiebe und gehe zu Zustand 1 über
|
||||
CONSTANT schiebe und gehe zu Zustand 2 über
|
||||
'~' schiebe und gehe zu Zustand 3 über
|
||||
'(' schiebe und gehe zu Zustand 4 über
|
||||
|
||||
exp gehe zu Zustand 17 über
|
||||
comp gehe zu Zustand 7 über
|
||||
|
||||
|
||||
Zustand 13
|
||||
|
||||
6 exp: exp '^' . exp
|
||||
|
||||
TOKEN schiebe und gehe zu Zustand 1 über
|
||||
CONSTANT schiebe und gehe zu Zustand 2 über
|
||||
'~' schiebe und gehe zu Zustand 3 über
|
||||
'(' schiebe und gehe zu Zustand 4 über
|
||||
|
||||
exp gehe zu Zustand 18 über
|
||||
comp gehe zu Zustand 7 über
|
||||
|
||||
|
||||
Zustand 14
|
||||
|
||||
2 input: exp '\n' .
|
||||
|
||||
$default reduziere mit Regel 2 (input)
|
||||
|
||||
|
||||
Zustand 15
|
||||
|
||||
8 exp: '(' exp ')' .
|
||||
|
||||
$default reduziere mit Regel 8 (exp)
|
||||
|
||||
|
||||
Zustand 16
|
||||
|
||||
4 exp: exp . '&' exp
|
||||
4 | exp '&' exp .
|
||||
5 | exp . '|' exp
|
||||
6 | exp . '^' exp
|
||||
|
||||
$default reduziere mit Regel 4 (exp)
|
||||
|
||||
|
||||
Zustand 17
|
||||
|
||||
4 exp: exp . '&' exp
|
||||
5 | exp . '|' exp
|
||||
5 | exp '|' exp .
|
||||
6 | exp . '^' exp
|
||||
|
||||
$default reduziere mit Regel 5 (exp)
|
||||
|
||||
|
||||
Zustand 18
|
||||
|
||||
4 exp: exp . '&' exp
|
||||
5 | exp . '|' exp
|
||||
6 | exp . '^' exp
|
||||
6 | exp '^' exp .
|
||||
|
||||
$default reduziere mit Regel 6 (exp)
|
File diff suppressed because it is too large
Load diff
|
@ -1,85 +0,0 @@
|
|||
/* A Bison parser, made by GNU Bison 3.0.4. */
|
||||
|
||||
/* Bison interface for Yacc-like parsers in C
|
||||
|
||||
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
|
||||
|
||||
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 3 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, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* As a special exception, you may create a larger work that contains
|
||||
part or all of the Bison parser skeleton and distribute that work
|
||||
under terms of your choice, so long as that work isn't itself a
|
||||
parser generator using the skeleton or a modified version thereof
|
||||
as a parser skeleton. Alternatively, if you modify or redistribute
|
||||
the parser skeleton itself, you may (at your option) remove this
|
||||
special exception, which will cause the skeleton and the resulting
|
||||
Bison output files to be licensed under the GNU General Public
|
||||
License without this special exception.
|
||||
|
||||
This special exception was added by the Free Software Foundation in
|
||||
version 2.2 of Bison. */
|
||||
|
||||
#ifndef YY_LOG_EXPRESSION_BOOLEAN_TAB_H_INCLUDED
|
||||
# define YY_LOG_EXPRESSION_BOOLEAN_TAB_H_INCLUDED
|
||||
/* Debug traces. */
|
||||
#ifndef LOG_EXPRESSION_DEBUG
|
||||
# if defined YYDEBUG
|
||||
#if YYDEBUG
|
||||
# define LOG_EXPRESSION_DEBUG 1
|
||||
# else
|
||||
# define LOG_EXPRESSION_DEBUG 0
|
||||
# endif
|
||||
# else /* ! defined YYDEBUG */
|
||||
# define LOG_EXPRESSION_DEBUG 0
|
||||
# endif /* ! defined YYDEBUG */
|
||||
#endif /* ! defined LOG_EXPRESSION_DEBUG */
|
||||
#if LOG_EXPRESSION_DEBUG
|
||||
extern int log_expression_debug;
|
||||
#endif
|
||||
|
||||
/* Token type. */
|
||||
#ifndef LOG_EXPRESSION_TOKENTYPE
|
||||
# define LOG_EXPRESSION_TOKENTYPE
|
||||
enum log_expression_tokentype
|
||||
{
|
||||
TOKEN = 258,
|
||||
CONSTANT = 259,
|
||||
NEG = 260
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Value type. */
|
||||
#if ! defined LOG_EXPRESSION_STYPE && ! defined LOG_EXPRESSION_STYPE_IS_DECLARED
|
||||
|
||||
union LOG_EXPRESSION_STYPE
|
||||
{
|
||||
#line 12 "boolean.y" /* yacc.c:1909 */
|
||||
|
||||
char *token;
|
||||
unsigned long constant;
|
||||
|
||||
#line 73 "boolean.tab.h" /* yacc.c:1909 */
|
||||
};
|
||||
|
||||
typedef union LOG_EXPRESSION_STYPE LOG_EXPRESSION_STYPE;
|
||||
# define LOG_EXPRESSION_STYPE_IS_TRIVIAL 1
|
||||
# define LOG_EXPRESSION_STYPE_IS_DECLARED 1
|
||||
#endif
|
||||
|
||||
|
||||
extern LOG_EXPRESSION_STYPE log_expression_lval;
|
||||
|
||||
int log_expression_parse (void);
|
||||
|
||||
#endif /* !YY_LOG_EXPRESSION_BOOLEAN_TAB_H_INCLUDED */
|
|
@ -1,74 +0,0 @@
|
|||
%{
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void log_expression_error(const char *s);
|
||||
int log_expression_lex();
|
||||
int log_expression_parse();
|
||||
long lookup_token(char *token);
|
||||
%}
|
||||
|
||||
%union {
|
||||
char *token;
|
||||
unsigned long constant;
|
||||
}
|
||||
|
||||
%token <token> TOKEN
|
||||
%token <constant> CONSTANT
|
||||
|
||||
%type <constant> exp comp
|
||||
|
||||
|
||||
%left '&' '|' '^'
|
||||
%precedence NEG
|
||||
|
||||
%define api.prefix {log_expression_}
|
||||
|
||||
%%
|
||||
|
||||
input:
|
||||
| exp '\n' { printf("\n\nresult = %#lx\n", $1); }
|
||||
;
|
||||
|
||||
exp :
|
||||
comp
|
||||
| exp '&' exp { $$ = $1 & $3; }
|
||||
| exp '|' exp { $$ = $1 | $3; }
|
||||
| exp '^' exp { $$ = $1 ^ $3; }
|
||||
| '~' exp %prec NEG { $$ = ~$2; printf("neg\n"); }
|
||||
| '(' exp ')' { $$ = $2; printf("subex"); }
|
||||
;
|
||||
|
||||
comp :
|
||||
CONSTANT { $$ = $1; printf("const %ld", $1); }
|
||||
| TOKEN { $$ = lookup_token($1); printf("token '%s'", $1); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
long lookup_token(char *token)
|
||||
{
|
||||
if (!strcmp(token, "a"))
|
||||
return 201;
|
||||
else if (!strcmp(token, "b"))
|
||||
return 202;
|
||||
if (!strcmp(token, "c"))
|
||||
return 203;
|
||||
if (!strcmp(token, "d"))
|
||||
return 204;
|
||||
else
|
||||
return 1111;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
do {
|
||||
log_expression_parse();
|
||||
} while (!feof(stdin));
|
||||
}
|
||||
|
||||
void log_expression_error(const char *s) {
|
||||
printf("EEK, parse error! Message: %s", s);
|
||||
exit(-1);
|
||||
}
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue