From e95c31f841b67fc69d93ec650fe285d34f996a1e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 21 Aug 2006 15:24:10 +0000 Subject: Alright, the grammer is almost there, just debugging, in what I call extreme- debugging mode. If you wanted something intelligable, don't use this one. --- build.conf | 2 +- src/build.l | 28 ++++++++++++++++++++++++++- src/build.y | 59 +++++++++++++++++++++++++++++++-------------------------- src/builder.cpp | 26 +++++++++++++++++++++++-- src/builder.h | 6 ++++++ 5 files changed, 90 insertions(+), 31 deletions(-) diff --git a/build.conf b/build.conf index 8bbe679..2115fb0 100644 --- a/build.conf +++ b/build.conf @@ -4,7 +4,7 @@ default action: check "build", check "cleanup" rule "exe", target file, set "CXXFLAGS" = "-lBob", - input [files("src/{target}"), files("src/shared")] + input [files("src/{target}" ), files("src/shared")] [directoryName("src/tests")] filter /src\/tests/(.*)/tests\/{re:1}/: rule "exe", diff --git a/src/build.l b/src/build.l index 9a15719..8189f9d 100644 --- a/src/build.l +++ b/src/build.l @@ -18,7 +18,7 @@ std::string strbuf; %} %% -[,:=[\]] return yytext[0]; +[,:=[\]()] return yytext[0]; "+=" return TOK_ADDSET; "default" return TOK_DEFAULT; @@ -32,6 +32,7 @@ std::string strbuf; "check" return TOK_CHECK; "clean" return TOK_CLEAN; "target" return TOK_TARGET; +"input" return TOK_INPUT; \n+ { yylloc->last_line += yyleng; @@ -59,6 +60,27 @@ std::string strbuf; "#".* /* single line comment */ +[a-zA-Z][a-zA-Z0-9]* { + { + yylval->tval = bld.getTargetType( yytext ); + if( yylval->tval >= 0 ) + { + return TARGETTYPE; + } + else if( bld.isFunction( yytext ) ) + { + yylval->strval = stringdup( yytext ); + return FUNCTION; + } + bld.error( yylloc, "Invalid token" ); + } +} + +[^ \t\r\n\'\":=,/][^ \t\r\n\'\"=,]+[^ \t\r\n\'\":=,] { + yylval->strval = stringdup( yytext ); + return STRING; +} + \" { BEGIN( strdq ); strbuf = ""; @@ -94,6 +116,10 @@ std::string strbuf; return STRING; } +. { + bld.error( yylloc, "Invalid character found!" ); +} + %% void Builder::scanBegin() diff --git a/src/build.y b/src/build.y index d852c4c..5580299 100644 --- a/src/build.y +++ b/src/build.y @@ -40,9 +40,9 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ); %token TOK_PERFORM "perform" %token TOK_PRODUCES "produces" -%token ',' ':' '=' +%token ',' ':' '=' '(' ')' -%destructor { delete[] $$; } STRING +%destructor { delete[] $$; } STRING FUNCTION %% @@ -54,57 +54,61 @@ input: ; // Rule interpretation -rule: TOK_RULE STRING ':' rulecmds +rule: TOK_RULE STRING {printf("Rule %s:\n", $2 ); } ':' rulecmds ; rulecmds: rulecmd | rulecmds ',' rulecmd ; -rulecmd: TOK_MATCHES REGEXP - | TOK_PRODUCES STRING - | TOK_REQUIRES list - | TOK_INPUT TOK_FILTER REGEXP - | TOK_INPUT TOK_FILTER func - | TOK_PERFORM func +rulecmd: TOK_MATCHES REGEXP { printf(" Matches: %s\n", $2 ); } + | TOK_PRODUCES STRING { printf(" Produces: %s\n", $2 ); } + | TOK_REQUIRES { printf(" Requires:\n"); } list {printf("\n");} + | TOK_INPUT TOK_FILTER REGEXP { printf(" Input Filter: %s\n", $3 ); } + | TOK_INPUT TOK_FILTER { printf(" Input Filter: "); } func {printf("\n");} + | TOK_PERFORM { printf(" Perform: "); } func {printf("\n");} ; // Action interpretation -action: TOK_DEFAULT TOK_ACTION ':' actioncmds - | STRING TOK_ACTION ':' actioncmds +action: TOK_DEFAULT TOK_ACTION ':' { printf("Default action:\n"); } actioncmds + | STRING TOK_ACTION ':' { printf("\"%s\" action:\n", $1 ); } actioncmds ; actioncmds: actioncmd | actioncmds ',' actioncmd ; -actioncmd: actioncmdtype list +actioncmd: { printf("\t"); } actioncmdtype list {printf("\n");} ; -actioncmdtype: TOK_CHECK - | TOK_CLEAN +actioncmdtype: TOK_CHECK { printf("check "); } + | TOK_CLEAN { printf("clean "); } ; // Target interpretation - -target: list ':' targetcmds +target: list ':' { printf(" are targets:\n"); } targetcmds ; targetcmds: targetcmd | targetcmds ',' targetcmd ; -targetcmd: TOK_RULE STRING - | TOK_TARGET TOK_PREFIX STRING - | TOK_TARGET TARGETTYPE - | TOK_INPUT list - | TOK_REQUIRES list +targetcmd: TOK_RULE STRING { printf(" Rule %s\n", $2 ); } + | TOK_TARGET TOK_PREFIX STRING { printf(" Target prefix: %s\n", $3 ); } + | TOK_TARGET TARGETTYPE { printf(" Target Type: %d\n", $2 ); } + | TOK_INPUT { printf(" Input: "); } list { printf("\n"); } + | TOK_REQUIRES { printf(" Requires: "); } list { printf("\n"); } + | TOK_SET { printf(" Set: "); } targetset + ; + +targetset: STRING '=' STRING { printf("%s = %s\n", $1, $3 ); } + | STRING TOK_ADDSET STRING { printf("%s += %s\n", $1, $3 ); } ; // list goo list: listitem listfilter - | '[' listitems ']' listfilter + | '[' { printf("["); } listitems ']' { printf("]"); } listfilter ; listfilter: @@ -113,21 +117,21 @@ listfilter: ; listitems: listitem - | listitems ',' listitem + | listitems ',' {printf(", "); } listitem ; -listitem: STRING +listitem: STRING {printf("%s", $1 ); } | func ; // Function -func: FUNCTION '(' funcparams ')' +func: FUNCTION { printf("%s(", $1 ); } '(' funcparams ')' { printf(")"); } ; funcparams: - | STRING - | funcparams ',' STRING + | STRING { printf("%s", $1 ); } + | funcparams ',' STRING { printf(", %s", $3 ); } ; %% @@ -136,3 +140,4 @@ void yyerror( YYLTYPE *locp, Builder &bld, char const *msg ) { bld.error( locp, msg ); } + diff --git a/src/builder.cpp b/src/builder.cpp index 1ecbf05..b6ae887 100644 --- a/src/builder.cpp +++ b/src/builder.cpp @@ -1,5 +1,7 @@ #include "builder.h" +subExceptionDef( BuildException ); + Builder::Builder() { } @@ -9,22 +11,42 @@ Builder::~Builder() } void yyparse( Builder &bld ); +extern int yydebug; void Builder::load( const std::string &sFile ) { file = sFile; scanBegin(); + yydebug = 1; yyparse( *this ); scanEnd(); } void Builder::error( YYLTYPE *locp, const char *msg ) { - printf("%s\n", msg ); + fflush( stdout ); + throw BuildException("%s: %d.%d-%d.%d: %s", + file.c_str(), + locp->first_line, locp->first_column, + locp->last_line, locp->last_column, + msg ); } void Builder::error( const std::string &msg ) { - printf("%s\n", msg.c_str() ); + fflush( stdout ); + throw BuildException("%s", msg.c_str() ); +} + +int Builder::getTargetType( const char *sType ) +{ + if( !strcmp( sType, "file" ) ) + return 0; + return -1; +} + +bool Builder::isFunction( const char *sFunc ) +{ + return true; } diff --git a/src/builder.h b/src/builder.h index 9c146ea..3293108 100644 --- a/src/builder.h +++ b/src/builder.h @@ -4,12 +4,15 @@ #include #include #include "build.tab.h" +#include "exceptions.h" class Builder; #define YY_DECL int yylex( YYSTYPE *yylval_param, YYLTYPE *yylloc_param, Builder &bld ) YY_DECL; +subExceptionDecl( BuildException ); + class Builder { public: @@ -21,6 +24,9 @@ public: void load( const std::string &sFile ); + int getTargetType( const char *sType ); + bool isFunction( const char *sFunc ); + private: std::string file; void scanBegin(); -- cgit v1.2.3