]> mj.ucw.cz Git - umpf.git/commitdiff
Initial commit
authorAnicka Bernathova <anicka@anicka.net>
Wed, 2 Jul 2008 12:51:05 +0000 (14:51 +0200)
committerAnicka Bernathova <anicka@anicka.net>
Wed, 2 Jul 2008 12:51:05 +0000 (14:51 +0200)
Makefile [new file with mode: 0644]
cond.y [new file with mode: 0644]
jazyk [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
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 (file)
index 0000000..a199ed9
--- /dev/null
+++ b/cond.y
@@ -0,0 +1,85 @@
+%{
+
+#include <stdio.h>
+
+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 <ctype.h>
+#include <string.h>
+
+#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 (file)
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