diff --git a/parse.leg b/parse.leg index 28a2ee0..5d07d0d 100644 --- a/parse.leg +++ b/parse.leg @@ -5,6 +5,7 @@ #include #include #include +#include #include "inputBuffer.c" #include "class.c" @@ -309,7 +310,7 @@ postfix = s:atom ( "?" - { s = mkQuery(s) } | "+" - { s = mkPlus(s) } )? { $$ = s } -atom = string | class | dot | rule +atom = string | class | dot | rule | '(' - e:expression - ')' {$$=e} rule = i:id !'=' { $$ = mkId(intern(yytext)) } @@ -317,7 +318,7 @@ id = < [a-zA-z_][a-zA-z_0-9]* > - { $$ = mkId(intern(yytext)) } string = '"' < [^\"]* > '"' - { $$ = mkString(yytext) } -class = '['-<(!']'string)*> ']' - { $$=mkClass(classify(yytext)) } +class = '['-<(!']'.)*> ']' - { $$=mkClass(classify(yytext)) } dot = '.' - { $$=mkDot() } @@ -367,7 +368,7 @@ int execute(Node *node, InputBuffer *in) return 1; } case Class: { - if (testBit(get(Node,Class,array),currentChar(in))) { + if (testBit(get(node,Class,array),currentChar(in))) { advance(in, 1); return 1; } @@ -411,8 +412,24 @@ int execute(Node *node, InputBuffer *in) } int main(int argc, char **argv) -{ +{ switch (argc) { + + case 1:{ + printf("affiche toi ho !\n"); + int char_index=0; + char *text_file= malloc(50); + int ch; + while ( (ch = getchar()) != EOF ) { + printf("%c",ch); + text_file[char_index]=ch; + char_index++; + } + printf("%s",text_file); + inputBuffer = mkInputBuffer(text_file); + break; + + } case 2: { inputBuffer = mkInputBuffer(argv[1]); break; @@ -444,7 +461,10 @@ int main(int argc, char **argv) } fatal("unrecognised option: %s", argv[1]); } + default: { + printf("%i\n",argc); + printf("test akoezpa\n"); fatal("usage: %s parsing-expression | -f filename", argv[0]); exit(1); } @@ -459,10 +479,12 @@ int main(int argc, char **argv) size_t line_max=0; ssize_t line_len=0; Node *startRule= intern("start")->rule; + if (!startRule) { fatal("no start rule"); return 1; } + while ((line_len=getline(&line,&line_max,stdin))>=0) { if (line_len>0 && line[line_len-1]=='\n') { line[line_len-1]=0;