added more grammar; added testing

This commit is contained in:
Ian Griffin 2023-05-29 16:38:56 +08:00
parent 8e1335eb4e
commit 3ff54b86e9
4 changed files with 20 additions and 11 deletions

View File

@ -3,7 +3,8 @@ LEX_BIN ?= flex
YACC_BIN ?= bison YACC_BIN ?= bison
GRAMMARS_DIR ?= ./grammars GRAMMARS_DIR ?= ./grammars
GRAMMAR_ID ?= quut GRAMMAR_ID ?= lysator
SAMPLES_DIR ?= ./samples
output ?= $(GRAMMAR_ID)-cocc output ?= $(GRAMMAR_ID)-cocc
all: $(output) all: $(output)
@ -19,3 +20,6 @@ $(output): lex.yy.c $(GRAMMAR_ID).tab.c $(GRAMMAR_ID).tab.h
clean: clean:
rm -f lex.yy.c *.tab.c *.tab.h *-cocc rm -f lex.yy.c *.tab.c *.tab.h *-cocc
test: $(SAMPLES_DIR) $(output)
for cfile in $(SAMPLES_DIR)/*; do printf "\n\n *** file: %s *** \n" $$cfile; ./$(output) < $$cfile; [ -eq $$? 0 ]; done

View File

@ -118,7 +118,7 @@ yywrap()
return(1); return(1);
} }
comment() void comment()
{ {
char c, c1; char c, c1;
@ -138,7 +138,7 @@ loop:
int column = 0; int column = 0;
//­p¼Æ¾¹ //<EFBFBD>p<EFBFBD>ƾ<EFBFBD>
void count() void count()
{ {
int i; int i;

View File

@ -12,6 +12,12 @@ IS (u|U|l|L)*
#include "lysator.tab.h" #include "lysator.tab.h"
void count(); void count();
void comment();
int yywrap();
int yylex();
void yyerror(char*);
int check_type();
%} %}
%% %%
@ -115,13 +121,13 @@ L?\"(\\.|[^\\"])*\" { count(); return(STRING_LITERAL); }
%% %%
yywrap() int yywrap()
{ {
return(1); return(1);
} }
comment() void comment()
{ {
char c, c1; char c, c1;

View File

@ -421,15 +421,14 @@ function_definition
extern char yytext[]; extern char yytext[];
extern int column; extern int column;
extern int yylex();
int main() { yyerror(char *s)
return yyparse();
}
yyerror(s)
char *s;
{ {
fflush(stdout); fflush(stdout);
printf("\n%*s\n%*s\n", column, "^", column, s); printf("\n%*s\n%*s\n", column, "^", column, s);
} }
int main() {
return yyparse();
}