Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
dipsywong98 committed Nov 6, 2017
1 parent badf6c7 commit 12ebd34
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 67 deletions.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions assignment2/matfunc.yy.lex → assign2/matfunc.lex
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ digits [0-9]
number [\-]?(0|([1-9]+{digits}*))
/************* Start: add your definitions here*/


/************* End: add your definitions here */
%%
\n return *yytext;
/* Start: add your rules here*/

REV yylval = "REV";printf("%s",yytext);return REV;
NEG yylval = "NEG";printf("%s",yytext);return NEG;
{number} yylval = (char*)malloc(sizeof(char)*MAXL);strcpy(yylval, yytext);printf("%s",yytext);return NUM;

REV yyval = "REV";return REV;
NEG yyval = "NEG";return NEG;
{number} yylval = (char*)malloc(sizeof(char)*MAXL);strcpy(yylval, yytext);return NUM;
. printf("%c",*yytext);

/* End: add your rules here*/
[+\-*\/,\[\]\n()] printf("%s",yytext);return *yytext;
{ws}
. printf("missed: '%s'", yytext);
/* End: add your rules here*/
%%

void RmWs(char* str){
Expand Down
12 changes: 6 additions & 6 deletions assignment2/matfunc.y → assign2/matfunc.y
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ line: '\n'

expr: s1 {$$=$1;}
;
s1: s1 '+' s2 {$$=Add($1,$3);printf("plus:%s + %s",$1,$3);}
s1: s1 '+' s2 {$$=Add($1,$3);}
| s1 '-' s2 {$$=Minus($1,$3);}
| s2 {$$=$1;}
;
Expand All @@ -68,7 +68,7 @@ s4: MATRIX {$$=$1}
MATRIX: '[' COLS ']'{$$=malloc(sizeof(char*)*MAXL);sprintf($$,"[%s]",$2);}
;
COLS: ROW {$$=$1;}
| ROW ',' {$$=malloc(sizeof(char*)*(strlen($1)+1));sprintf($$,"%s,",$1);}
| ROW ',' COLS {$$=malloc(sizeof(char*)*(strlen($1)+1));sprintf($$,"%s,%s",$1,$3);}
ROW: '[' VEC ']' {$$=malloc(sizeof(char*)*MAXL);sprintf($$,"[%s]",$2);}
;
VEC: NUM ',' VEC {$$=malloc(sizeof(char*)*MAXL);sprintf($$,"%s,%s",$1,$3);}
Expand Down Expand Up @@ -102,10 +102,10 @@ int main(int argc, char *argv[]){

int yyerror(const char* s)
{
// extern int yylineno;
// extern char *yytext;
// printf("\n^%d: %s at %s #%d\n", yylineno, s, yytext, (int)(*yytext));
// return 0;
/*extern int yylineno;
extern char *yytext;
printf("\n^%d: %s at %s #%d\n", yylineno, s, yytext, (int)(*yytext));
return 0;*/
}

char *FFormat(const char* str){
Expand Down
13 changes: 13 additions & 0 deletions assign2/results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[2]]
[[2]]
[[2,4]]
[[2,4],[12,14],[10,10]]
[[5,205,19],[-223,13,25]]
[[6,271,22],[201,25,45]]
[[6,5,4],[3,2,1]]
[[3,6],[9,12]]
[[2,4],[6,8]]
[[2,4,6],[4,6,8]]
[[5,207,19],[1931,13,43]]
[[0,0,0],[0,0,0]]
[[-2,-4,-6],[-2,-4,-6]]
3 changes: 2 additions & 1 deletion assignment2/run.sh → assign2/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

#cd ../../mnt/c/Users/dipsy/Desktop/course/COMP3031/assign2

bison -d matfunc.y
#flex -o matfunc.lex.yy.c matfunc.lex
flex matfunc.lex
gcc *.c -o test -lm
./test testcase.txt
1 change: 0 additions & 1 deletion assignment2/test.sh → assign2/test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

bison -d matfunc.y
#flex -o matfunc.lex.yy.c matfunc.lex
flex matfunc.lex
gcc *.c -o test -lm
./test
File renamed without changes.
52 changes: 0 additions & 52 deletions assignment2/matfunc.lex

This file was deleted.

Empty file removed assignment2/results.txt
Empty file.
Binary file removed assignment2/test
Binary file not shown.

0 comments on commit 12ebd34

Please sign in to comment.