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
MANDIR = $(PREFIX)/man/man
lex.yy.c:
lex.yy.c: parse.l
lex parse.l
.include <bsd.prog.mk>

View file

View file

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

View file

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