fixed precedence tests
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
%{
|
%{
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "../src/symbol_table.c"
|
#include "../src/symbol_table.c"
|
||||||
|
#include <math.h>
|
||||||
extern int yylex(void);
|
extern int yylex(void);
|
||||||
void yyerror(const char *err);
|
void yyerror(const char *err);
|
||||||
extern char* yytext;
|
extern char* yytext;
|
||||||
@ -21,16 +22,18 @@
|
|||||||
char * words;
|
char * words;
|
||||||
}
|
}
|
||||||
|
|
||||||
//need subtraction only here
|
|
||||||
%type <words> id_or_types
|
%type <words> id_or_types
|
||||||
%type <words> types
|
%type <words> types
|
||||||
|
%type expression
|
||||||
|
%type constant
|
||||||
%token <words> ID 101
|
%token <words> ID 101
|
||||||
%token <words> T_INTEGER 201
|
%token <words> T_INTEGER 201
|
||||||
%token <words> T_ADDRESS 202
|
%token <words> T_ADDRESS 202
|
||||||
%token <words> T_BOOLEAN 203
|
%token <words> T_BOOLEAN 203
|
||||||
%token <words> T_CHARACTER 204
|
%token <words> T_CHARACTER 204
|
||||||
%token <words> T_STRING 205
|
%token <words> T_STRING 205
|
||||||
%token C_INTEGER 301
|
%token <integ> C_INTEGER 301
|
||||||
%token C_NULL 302
|
%token C_NULL 302
|
||||||
%token C_CHARACTER 303
|
%token C_CHARACTER 303
|
||||||
%token C_STRING 304
|
%token C_STRING 304
|
||||||
@ -72,17 +75,19 @@
|
|||||||
%token COMMENT 700
|
%token COMMENT 700
|
||||||
|
|
||||||
//precedence order
|
//precedence order
|
||||||
%precedence RESERVE RELEASE
|
|
||||||
%precedence DOT
|
|
||||||
%precedence UMINUS
|
|
||||||
%precedence NOT
|
|
||||||
%left MUL DIV REM
|
|
||||||
%left ADD SUB_OR_NEG
|
|
||||||
%left LESS_THAN
|
|
||||||
%left EQUAL_TO
|
|
||||||
%left AND
|
|
||||||
%left OR
|
|
||||||
%left ASSIGN
|
%left ASSIGN
|
||||||
|
%left OR
|
||||||
|
%left AND
|
||||||
|
%left EQUAL_TO
|
||||||
|
%left LESS_THAN
|
||||||
|
%left ADD SUB_OR_NEG
|
||||||
|
%left MUL DIV REM
|
||||||
|
%precedence NOT
|
||||||
|
%precedence UMINUS
|
||||||
|
%precedence DOT
|
||||||
|
%precedence RESERVE RELEASE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
@ -125,7 +130,7 @@ idlist:
|
|||||||
|
|
||||||
sblock:
|
sblock:
|
||||||
L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
|
L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
|
||||||
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock statement_list {cur = getParent(cur);} R_BRACE
|
| L_BRACE {cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock {printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE
|
||||||
;
|
;
|
||||||
|
|
||||||
dblock:
|
dblock:
|
||||||
@ -155,7 +160,7 @@ statement_list:
|
|||||||
compound_statement:
|
compound_statement:
|
||||||
WHILE L_PAREN expression R_PAREN sblock
|
WHILE L_PAREN expression R_PAREN sblock
|
||||||
| IF L_PAREN expression R_PAREN THEN sblock ELSE sblock
|
| IF L_PAREN expression R_PAREN THEN sblock ELSE sblock
|
||||||
| sblock
|
| sblock //{printf("seen a compound statement rule\n");}
|
||||||
;
|
;
|
||||||
|
|
||||||
simple_statement:
|
simple_statement:
|
||||||
@ -173,20 +178,20 @@ rec_op :
|
|||||||
DOT
|
DOT
|
||||||
|
|
||||||
expression:
|
expression:
|
||||||
constant
|
constant {printf("constant expression\n");}
|
||||||
| SUB_OR_NEG expression %prec UMINUS
|
| SUB_OR_NEG expression %prec UMINUS {printf("negative expression\n");}
|
||||||
| NOT expression
|
| NOT expression {printf("not expression\n");}
|
||||||
| expression ADD expression
|
| expression ADD expression {printf("add expression\n");}
|
||||||
| expression SUB_OR_NEG expression
|
| expression SUB_OR_NEG expression {printf("subtract expression\n");}
|
||||||
| expression MUL expression
|
| expression MUL expression {printf("multiply expression\n");}
|
||||||
| expression DIV expression
|
| expression DIV expression {printf("division expression\n");}
|
||||||
| expression REM expression
|
| expression REM expression {printf("remainder expression\n");}
|
||||||
| expression AND expression
|
| expression AND expression {printf("and expression\n");}
|
||||||
| expression OR expression
|
| expression OR expression {printf("or expression\n");}
|
||||||
| expression LESS_THAN expression
|
| expression LESS_THAN expression {printf("less than expression\n");}
|
||||||
| expression EQUAL_TO expression
|
| expression EQUAL_TO expression {printf("equals check expression\n");}
|
||||||
| assignable
|
| assignable {printf("assignable expression\n");}
|
||||||
| L_PAREN expression R_PAREN
|
| L_PAREN expression R_PAREN {printf("paren expression\n");}
|
||||||
| memOp assignable
|
| memOp assignable
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -201,8 +206,8 @@ argument_list:
|
|||||||
|
|
||||||
|
|
||||||
memOp:
|
memOp:
|
||||||
RESERVE
|
RESERVE {printf("reserve expression\n");}
|
||||||
| RELEASE
|
| RELEASE {printf("release expression\n");}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|||||||
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}}
|
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {if(tok_flag != NULL){print_tok(COMMA);}incr(line_number,column_number,COMMA);return COMMA;}}
|
||||||
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}}
|
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {if(tok_flag != NULL){print_tok(ARROW);}incr(line_number,column_number,ARROW);return ARROW;}}
|
||||||
|
|
||||||
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);return C_INTEGER;}}
|
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {if(tok_flag != NULL){print_tok(C_INTEGER);}incr(line_number,column_number,C_INTEGER);yylval.integ = atoi(yytext);return C_INTEGER;}}
|
||||||
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);return C_CHARACTER;}}
|
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {if(tok_flag != NULL){print_tok(C_CHARACTER);}incr(line_number,column_number,C_CHARACTER);return C_CHARACTER;}}
|
||||||
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);return C_STRING;}}
|
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {if(tok_flag != NULL){print_tok(C_STRING);}incr(line_number,column_number,C_STRING);return C_STRING;}}
|
||||||
{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}}
|
{COMMENT} {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {if(tok_flag != NULL){print_tok(COMMENT);}incr(line_number,column_number,COMMENT);/*return COMMENT;*/}}
|
||||||
|
15
tests/sprint2/test/sp2_integer_binary_op.alpha
Normal file
15
tests/sprint2/test/sp2_integer_binary_op.alpha
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
entry(arg) := {
|
||||||
|
[integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1]
|
||||||
|
x := 3 + 2 * 8;
|
||||||
|
x := 3 - 2 / 8;
|
||||||
|
x := 3 * 2 % 8;
|
||||||
|
x := 3 * 2 % 8;
|
||||||
|
x := 3 % 2 * 8;
|
||||||
|
x := 3 + 2 - 8;
|
||||||
|
arr2 := 1 * reserve x;
|
||||||
|
arr2 := release x;
|
||||||
|
b2 := 3 < 2;
|
||||||
|
b1 := 1 = 2;
|
||||||
|
b2 := !(3 < 2);
|
||||||
|
b1 := 6<7 & 7=7;
|
||||||
|
}
|
Reference in New Issue
Block a user