From 83a5c325a43c8cec2d0b59ba39a4b3267081a4fc Mon Sep 17 00:00:00 2001 From: Anicka Bernathova Date: Wed, 2 Jul 2008 14:51:05 +0200 Subject: [PATCH] Initial commit --- Makefile | 8 ++++++ cond.y | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ jazyk | 44 +++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 Makefile create mode 100644 cond.y create mode 100644 jazyk diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..32acee5 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +all: bison + gcc -Wall -O2 -o cond cond.tab.c + +bison: + bison cond.y + +clean: + rm -rf cond.tab.c cond diff --git a/cond.y b/cond.y new file mode 100644 index 0000000..a199ed9 --- /dev/null +++ b/cond.y @@ -0,0 +1,85 @@ +%{ + +#include + +int yylex (void); +void yyerror (char const *); + +%} + +%token CONST +%left EQ +%left '|' '&' '^' +%left '!' + +%% +input: /* empty */ + | input line +; + +line: '\n' + | boo '\n' { printf("%s\n",$1?"true":"false"); } + | boo EQ boo { $$ = $1 == $2 } + | boo '|' boo { $$ = $1 || $2 } + | boo '&' boo { $$ = $1 && $2 } + | boo '^' boo { $$ = ($1 || $2) && !($1 && $2) } + | '!' boo { $$ = ! $1 } +; + +boo: + +; +%% + +#include +#include + +#define BUFSIZE 4096 + +int +yylex(void) +{ + + int c, last; + char temp[BUFSIZE]; + char* p=temp; + + while ((c = getchar ()) == ' ' || c == '\t'); + + if (c == '"'){ + last = '"'; + while ((c = getchar()) != '"' || last == '\\'){ + *p = c; + last = c; + p++; + if (p-temp >= BUFSIZE-1) + break; + } + *p = '\0'; + + strcpy(&yylval,temp); + return CONST; + } + + if (c == '='){ + if ((c = getchar ()) == '=') + return EQ; + } + + if (c == EOF) + return 0; + + return c; +} + +void +yyerror (char const *s) +{ + fprintf (stderr, "%s\n", s); +} + +int +main(void) +{ + return yyparse (); +} diff --git a/jazyk b/jazyk new file mode 100644 index 0000000..c116b50 --- /dev/null +++ b/jazyk @@ -0,0 +1,44 @@ +Start -> Start Start +Start -> if Podminka { Prikaz } | if Podminka { Prikaz } Konec_podminky | Prikaz + +Konec_podminky -> else if Podminka { Prikaz } Konec_podminky +Konec_podminky -> else Podminka { Prikaz } + +Podminka -> Promenna Operator Retezec | (Promenna Operator Retezec) | Promenna Operator Retezec Bool_spojka Podminka| (Promenna Operator Retezec) Bool_spojka Podminka| ! Podminka + +Bool_spojka -> | | & | ^ + +Promenna -> $X +Retezec -> T | R +T -> "Y" | 'Z' | N +N -> //jakekoliv cislo +X -> [A-Za-Z0-9_-]+ +Y -> //cokoliv s escapovanymi uvozovkami +Z -> //cokoliv s escapovanymi apostrofy +A -> // cokoliv s escapovanymi lomitky +R -> /A/ + +Retezec -> Retezec.Retezec | Promenna.Retezec | Retezec.Promenna | Promenna | Promenna.Promenna + +Operator -> == | === | != | !== | <= | >= | < | > | ~~ | !~ | ~~~ | !~~ + +Prikaz -> PrikazPrikaz +Prikaz -> Prirazeni | Akce +Prirazeni -> Promenna = Retezec | Promenna = Akce +Akce -> Co -> Jak Retezec +Co -> copy | _ +Jak -> pipe | mail | _ + +-- +promenna: $[A-Za-Z0-9_-]+ +string: "[^\n]*" | '[^\n]*' | cislo +klicove slovo +whitespace +whitespace s novym radkem +operator +leva zavorka +prava zavorka +leva slozena zavorka +prava slozena zavorka +sipka +EOF -- 2.39.2