Almost finishing the yacc thing

This commit is contained in:
(≧◡≦) 2022-07-02 18:53:22 +02:00
parent 1f91a4eb2c
commit 1bfee5c1a0
4 changed files with 33 additions and 19 deletions

View file

@ -8,7 +8,7 @@ PREFIX = /usr/local
BINDIR = $(PREFIX)/bin BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/man/man MANDIR = $(PREFIX)/man/man
lex.yy.c: lex.yy.c: parse.l
lex parse.l lex parse.l
.include <bsd.prog.mk> .include <bsd.prog.mk>

View file

View file

@ -1,18 +1,20 @@
%{ %{
#include <stdio.h> #include <stdio.h>
#define YYSTYPE char*
#include "parse.h" #include "parse.h"
extern YYSTYPE yylval;
%} %}
%% %%
= return EQUAL;
server return SERVERTOK; server return SERVERTOK;
ipv4 return IP4TOK; ipv4 return IP4TOK;
ipv6 return IP6TOK; ipv6 return IP6TOK;
[a-zA-Z][a-zA-Z0-9]* yylval=strdup(yytext); return WORD; silent return SILTOK;
[a-zA-Z0-9\/.-]+ yylval=strdup(yytext); return URL; [a-zA-Z][a-zA-Z0-9]* yylval.val = !strcmp(yytext,"true"); return WORD;
\n /* ignore EOL */; (http|https).*[a-zA-Z0-9\/.-]+ yylval.str = strdup(yytext); return URL;
\n return SEMICOLON;
[ \t]+ [ \t]+
\" return QUOTE; \" return QUOTE;
; return SEMICOLON; ; return SEMICOLON;
#.*
%% %%

View file

@ -4,7 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "config.h" #include "config.h"
#define YYSTYPE char*
struct config rc; struct config rc;
int yyparse(void); int yyparse(void);
void yyerror(const char *str) { void yyerror(const char *str) {
@ -17,11 +17,15 @@
return 1; return 1;
} }
%} %}
%union YYSTYPE {
int val;
char *str;
}
%token SERVERTOK HPTOK SPTOK USPTOK UHPTOK IP4TOK IP6TOK QUOTE URL SEMICOLON WORD %token SERVERTOK HPTOK SPTOK USPTOK UHPTOK IP4TOK IP6TOK SILTOK QUOTE
%token URL SEMICOLON WORD EQUAL
%% %%
@ -35,7 +39,7 @@ statements
| |
IP4TOK quotedword IP4TOK quotedword
{ {
if(!strcmp($2,"true")) if($2.val)
rc.ipv4_flag = true; rc.ipv4_flag = true;
else else
rc.ipv4_flag = false; rc.ipv4_flag = false;
@ -43,7 +47,7 @@ IP4TOK quotedword
| |
IP6TOK quotedword IP6TOK quotedword
{ {
if(!strcmp($2,"true")) if($2.val)
rc.ipv6_flag = true; rc.ipv6_flag = true;
else else
rc.ipv6_flag = false; rc.ipv6_flag = false;
@ -51,30 +55,38 @@ IP6TOK quotedword
| |
SERVERTOK quotedname SERVERTOK quotedname
{ {
rc.server = $2; rc.server = $2.str;
} }
| |
HPTOK quotedname HPTOK quotedname
{ {
rc.http_proxy_url = $2; rc.http_proxy_url = $2.str;
} }
| |
SPTOK quotedname SPTOK quotedname
{ {
rc.socks_proxy_url = $2; rc.socks_proxy_url = $2.str;
} }
|
SILTOK quotedword
{
if($2.val)
rc.silent_flag = true;
else
rc.silent_flag = false;
}
; ;
quotedname: quotedname:
QUOTE URL QUOTE EQUAL QUOTE URL QUOTE
{ {
$$=$2; $$=$3;
} }
quotedword: quotedword:
QUOTE WORD QUOTE EQUAL QUOTE WORD QUOTE
{ {
$$=$2; $$=$3;
} }
statements: statements: