chiark / gitweb /
starting on flex/bison parser for hostside
authorian <ian>
Sat, 9 Sep 2006 17:43:19 +0000 (17:43 +0000)
committerian <ian>
Sat, 9 Sep 2006 17:43:19 +0000 (17:43 +0000)
cprogs.make
hostside/.cvsignore
hostside/Makefile
hostside/record-l.l [new file with mode: 0644]
hostside/record-y.y [new file with mode: 0644]
hostside/record.c

index e6fd70cd360aad6f777278cd628809ad5b1ec8cd..19d8d04ea88da7d7b8053a623573cd565872a79a 100644 (file)
@@ -8,6 +8,12 @@ CFLAGS=        $(CPPFLAGS) -D_GNU_SOURCE \
 CPPFLAGS=
 LINK=          $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS)
 
+LEX=flex
+BISON=bison
+
 %.o:   %.c $(AUTOINCS)
        $(CC) $(CFLAGS) -MM $< >$*.d
        $(CC) $(CFLAGS) -o $@ -c $<
+
+%.c:   %.y
+       $(BISON) -o $@ $<
index 7ef68e190057f1ca14e5e8f477e4f7031bb84731..62750d50a700e6d95bba998eecdaf70d8a54cf5e 100644 (file)
@@ -11,3 +11,5 @@ gui-plan-bot
 selectors.h
 errorcodes.h
 retransmit-table.h
+record-l.c
+record-y.[ch]
index b66c194ad8c739e39e960521c12e201e272387fa..a718672ccae36716ef4a23eb8a4d587d14918e0d 100644 (file)
@@ -1,6 +1,7 @@
 #
 
-AUTOINCS=      auproto-pic.h layoutinfo.h selectors.h retransmit-table.h
+AUTOINCS=      auproto-pic.h layoutinfo.h selectors.h retransmit-table.h \
+               errorcodes.h
 TARGETS=       hostside-old gui-plan-bot realtime
 
 include ../common.make
@@ -54,6 +55,7 @@ safety:               safety.o utils.o trackloc.o ../layout/ours.layout-data.o
 hostside:      hostside.o serialio.o client.o obc.o commands.o utils.o \
                 nmra.o encode.o retransmit.o output.o auproto-pic.o \
                 parseutils.o \
+                record-l.o record-y.o record.o \
                 -loop
                $(LINK)
 
diff --git a/hostside/record-l.l b/hostside/record-l.l
new file mode 100644 (file)
index 0000000..4a61e8d
--- /dev/null
@@ -0,0 +1,41 @@
+/* -*- fundamental -*- */
+
+%{
+#include "y.tab.h"
+%}
+
+%option warn
+%option batch
+%option noyywrap
+
+%option bison-locations
+%option bison-bridge
+
+%{
+#define STR  yylval->str= xstrdup(yytext); return
+%}
+
+%%
+
+max-trains     { yylval->str= 0; return MAXTRAINS; }
+
+train          { STR TRAIN; }
+seg            { STR SEG; }
+is             { STR IS; }
+at             { STR AT; }
+has            { STR HAS; }
+step           { STR STEP; }           
+end            { STR END; }            
+
+[A-Za-z0-9_]+  { STR IDENT; }
+
+[0-9]{0,5}     { yylval->num= strtoul(yytext,0,10); return NUM; }
+[0-9]{6}       { badrecord("number too long"); }
+
+[-+:=~$/]      { yylval->str= 0; return yytext[0]; }
+
+\#.*\n|\       { yylval->str= 0; return NL; }
+
+[ \t]          { }
+
+.              { badrecord("lexically invalid input"); }
diff --git a/hostside/record-y.y b/hostside/record-y.y
new file mode 100644 (file)
index 0000000..3f8f769
--- /dev/null
@@ -0,0 +1,56 @@
+/* -*- fundamental -*- */
+
+%{
+#include "realtime.h"
+%}
+
+%union {
+  char *name;
+  Train *train;
+  Segment *seg;
+  int num;
+}
+
+%token <name>  TRAIN  SEG IS AT HAS STEP END  IDENT
+%token <name>  MAXTRAINS NL
+%token <num>   NUM
+
+%type <name>   ident
+%type <train>  train
+%type <segment>        seg
+%type <num>    sign
+
+%defines
+
+%%
+
+file:          end
+       |       line NL file
+
+line:          /* empty */
+       |       MAXTRAINS NUM
+                { record_max_trains($2); }
+       |       TRAIN train AT sign SEG ':' NUM '+' '-' NUM
+                { record_train_at($2,$4,$5,$7,$10); }
+       |       TRAIN train IS NUM NUM '+' NUM '+' NUM
+                { record_train_is($2,$4,$5,$7,$9); }
+       |       TRAIN train STEP NUM '=' NUM NUM '/' NUM
+                { record_train_step($2,$4,$6,$7,$9); }
+       |       SEG seg HAS sign train
+                { record_seg_has($2,$4,$5); }
+       |       SEG seg HAS '$'
+                { record_seg_has($2,0,0); }
+       |       SEG seg AT NUM
+                { record_seg_at($2,$4); }
+
+sign:          /* empty */ { return 1; }
+       |       '-' { return -1; }
+
+ident:         IDENT | TRAIN | SEG | IS | AT | STEP | END
+
+seg:           ident { $$= pname2seg($1); }
+train:         ident { $$= pname2train($1); }
+
+end:           END NL
+
+%%
index b025692c66a91b828ae86c9394089807733b45a6..429cee20069e02a64cdc644fb53feef1e44ccf28 100644 (file)
@@ -3,9 +3,11 @@
  *
  * File format:
  *
+ *  max-trains num
  *  train <trainpn> at [-]<foredetectpn>:<maxinto>+-<uncertainty>
- *  seg <segpn> has [-]<ownerpn>|$ <movposcomb>
- *  train <trainpn> is #<addr> <head>+<detectable>+<tail>
+ *  train <trainpn> is <addr> <head>+<detectable>+<tail>
  *  train <trainpn> step <step>=<speed> <upwait>/<downwait>
+ *  seg <segpn> has [-]<ownerpn>|$
+ *  seg <segpn> at <movposcomb>
  */