|
@ -5,6 +5,7 @@ |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdarg.h> |
|
|
#include <stdarg.h> |
|
|
#include <sys/stat.h> |
|
|
#include <sys/stat.h> |
|
|
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
|
#include "inputBuffer.c" |
|
|
#include "inputBuffer.c" |
|
|
#include "class.c" |
|
|
#include "class.c" |
|
@ -309,7 +310,7 @@ postfix = s:atom ( "?" - { s = mkQuery(s) } |
|
|
| "+" - { s = mkPlus(s) } |
|
|
| "+" - { s = mkPlus(s) } |
|
|
)? { $$ = s } |
|
|
)? { $$ = s } |
|
|
|
|
|
|
|
|
atom = string | class | dot | rule |
|
|
|
|
|
|
|
|
atom = string | class | dot | rule | '(' - e:expression - ')' {$$=e} |
|
|
|
|
|
|
|
|
rule = i:id !'=' { $$ = mkId(intern(yytext)) } |
|
|
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) } |
|
|
string = '"' < [^\"]* > '"' - { $$ = mkString(yytext) } |
|
|
|
|
|
|
|
|
class = '['-<(!']'string)*> ']' - { $$=mkClass(classify(yytext)) } |
|
|
|
|
|
|
|
|
class = '['-<(!']'.)*> ']' - { $$=mkClass(classify(yytext)) } |
|
|
|
|
|
|
|
|
dot = '.' - { $$=mkDot() } |
|
|
dot = '.' - { $$=mkDot() } |
|
|
|
|
|
|
|
@ -367,7 +368,7 @@ int execute(Node *node, InputBuffer *in) |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
case Class: { |
|
|
case Class: { |
|
|
if (testBit(get(Node,Class,array),currentChar(in))) { |
|
|
|
|
|
|
|
|
if (testBit(get(node,Class,array),currentChar(in))) { |
|
|
advance(in, 1); |
|
|
advance(in, 1); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
@ -411,8 +412,24 @@ int execute(Node *node, InputBuffer *in) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int main(int argc, char **argv) |
|
|
int main(int argc, char **argv) |
|
|
{ |
|
|
|
|
|
|
|
|
{ |
|
|
switch (argc) { |
|
|
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: { |
|
|
case 2: { |
|
|
inputBuffer = mkInputBuffer(argv[1]); |
|
|
inputBuffer = mkInputBuffer(argv[1]); |
|
|
break; |
|
|
break; |
|
@ -444,7 +461,10 @@ int main(int argc, char **argv) |
|
|
} |
|
|
} |
|
|
fatal("unrecognised option: %s", argv[1]); |
|
|
fatal("unrecognised option: %s", argv[1]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
default: { |
|
|
default: { |
|
|
|
|
|
printf("%i\n",argc); |
|
|
|
|
|
printf("test akoezpa\n"); |
|
|
fatal("usage: %s parsing-expression | -f filename", argv[0]); |
|
|
fatal("usage: %s parsing-expression | -f filename", argv[0]); |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
@ -459,10 +479,12 @@ int main(int argc, char **argv) |
|
|
size_t line_max=0; |
|
|
size_t line_max=0; |
|
|
ssize_t line_len=0; |
|
|
ssize_t line_len=0; |
|
|
Node *startRule= intern("start")->rule; |
|
|
Node *startRule= intern("start")->rule; |
|
|
|
|
|
|
|
|
if (!startRule) { |
|
|
if (!startRule) { |
|
|
fatal("no start rule"); |
|
|
fatal("no start rule"); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
while ((line_len=getline(&line,&line_max,stdin))>=0) { |
|
|
while ((line_len=getline(&line,&line_max,stdin))>=0) { |
|
|
if (line_len>0 && line[line_len-1]=='\n') { |
|
|
if (line_len>0 && line[line_len-1]=='\n') { |
|
|
line[line_len-1]=0; |
|
|
line[line_len-1]=0; |
|
|