fixed precedence tests
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
%{
|
||||
#include <stdio.h>
|
||||
#include "../src/symbol_table.c"
|
||||
#include <math.h>
|
||||
extern int yylex(void);
|
||||
void yyerror(const char *err);
|
||||
extern char* yytext;
|
||||
@ -21,16 +22,18 @@
|
||||
char * words;
|
||||
}
|
||||
|
||||
//need subtraction only here
|
||||
|
||||
%type <words> id_or_types
|
||||
%type <words> types
|
||||
%type expression
|
||||
%type constant
|
||||
%token <words> ID 101
|
||||
%token <words> T_INTEGER 201
|
||||
%token <words> T_ADDRESS 202
|
||||
%token <words> T_BOOLEAN 203
|
||||
%token <words> T_CHARACTER 204
|
||||
%token <words> T_STRING 205
|
||||
%token C_INTEGER 301
|
||||
%token <integ> C_INTEGER 301
|
||||
%token C_NULL 302
|
||||
%token C_CHARACTER 303
|
||||
%token C_STRING 304
|
||||
@ -72,17 +75,19 @@
|
||||
%token COMMENT 700
|
||||
|
||||
//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 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:
|
||||
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:
|
||||
@ -155,7 +160,7 @@ statement_list:
|
||||
compound_statement:
|
||||
WHILE L_PAREN expression R_PAREN sblock
|
||||
| IF L_PAREN expression R_PAREN THEN sblock ELSE sblock
|
||||
| sblock
|
||||
| sblock //{printf("seen a compound statement rule\n");}
|
||||
;
|
||||
|
||||
simple_statement:
|
||||
@ -173,21 +178,21 @@ rec_op :
|
||||
DOT
|
||||
|
||||
expression:
|
||||
constant
|
||||
| SUB_OR_NEG expression %prec UMINUS
|
||||
| NOT expression
|
||||
| expression ADD expression
|
||||
| expression SUB_OR_NEG expression
|
||||
| expression MUL expression
|
||||
| expression DIV expression
|
||||
| expression REM expression
|
||||
| expression AND expression
|
||||
| expression OR expression
|
||||
| expression LESS_THAN expression
|
||||
| expression EQUAL_TO expression
|
||||
| assignable
|
||||
| L_PAREN expression R_PAREN
|
||||
| memOp assignable
|
||||
constant {printf("constant expression\n");}
|
||||
| SUB_OR_NEG expression %prec UMINUS {printf("negative expression\n");}
|
||||
| NOT expression {printf("not expression\n");}
|
||||
| expression ADD expression {printf("add expression\n");}
|
||||
| expression SUB_OR_NEG expression {printf("subtract expression\n");}
|
||||
| expression MUL expression {printf("multiply expression\n");}
|
||||
| expression DIV expression {printf("division expression\n");}
|
||||
| expression REM expression {printf("remainder expression\n");}
|
||||
| expression AND expression {printf("and expression\n");}
|
||||
| expression OR expression {printf("or expression\n");}
|
||||
| expression LESS_THAN expression {printf("less than expression\n");}
|
||||
| expression EQUAL_TO expression {printf("equals check expression\n");}
|
||||
| assignable {printf("assignable expression\n");}
|
||||
| L_PAREN expression R_PAREN {printf("paren expression\n");}
|
||||
| memOp assignable
|
||||
;
|
||||
|
||||
ablock:
|
||||
@ -201,8 +206,8 @@ argument_list:
|
||||
|
||||
|
||||
memOp:
|
||||
RESERVE
|
||||
| RELEASE
|
||||
RESERVE {printf("reserve expression\n");}
|
||||
| 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( "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;}}
|
||||
\"{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;*/}}
|
||||
|
Reference in New Issue
Block a user