Skip to content

Commit

Permalink
Erro raro na checagem de consisterncia dos parametros de funcao
Browse files Browse the repository at this point in the history
  • Loading branch information
fkeglevich committed Jun 20, 2017
1 parent 379847f commit 584ff49
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 44 deletions.
42 changes: 9 additions & 33 deletions saida.txt
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
a : short 0 ;
a1 : long 1 ;
i : long 0 ;
v : long [ 10 ] 0 0 0 0 true 0 0 0 0 0 ;
mat : long [ 10 ] ;
f : float 10.55 ;
c : byte 'x' ;
d : byte 65 ;
falsiane : bool TRUE ;
long main ( ) {
a = true ;
v # 3.4 = 2 ;
v # 2 = v[10 - 1 ];
for ( i = 1 to 10 ) print i " " ;
read hihiUpsy ;
print " Digite um numero: \n" ;
read i ;
while ( i < 10 ) {
a = incn(a , 1 );
i = i + 1 ;
};
print "Incrementado algumas vezes fica " a "\n" ;
when ( a == 5 ) then print "Parou no meio\n" ;
when ( a == 11 ) then ;
when ( a == 11 ) then ;
;
;
;
{
;
};
{
v : long [ 4 ] 0 0 0 0 ;
a2 : short 0 ;
long incn2 ( long x , float n ) return main();
long incn3 ( ) return main();
long incn ( long x , long n ) {
a2 = incn3();
return a2 + n ;
};
long main ( ) {
a2 = 2 ;
};
long incn ( long x , long n ) return x + n ;
short voidfunc ( ) ;
11 changes: 7 additions & 4 deletions sample.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// UFRGS - Compiladores - Marcelo Johann - 2017/1

a: short 0;
long incn (long x, long n)
return a2+n;


a2: short 0;
a1: long 1;
i: long 0;
v: long[10] 0 0 0 0 true 0 0 0 0 0;
Expand All @@ -12,7 +16,7 @@ falsiane: bool TRUE;

long main()
{
a = true;
a = 2;
v#3.4 = 2;
v#2 = v[10-1];
for (i = 1 to 10)
Expand All @@ -37,8 +41,7 @@ long main()
{};
};

long incn (long x, long n)
return x+n;


short voidfunc() ;

Expand Down
34 changes: 34 additions & 0 deletions sample2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// UFRGS - Compiladores - Marcelo Johann - 2017/1

v: long[4] 0 0 0 0;

a2: short 0;

long incn2 (long x, float n)
return main();

long incn3 ()
return main();

long incn (long x, long n)
{
//v#true = 2;
a2 = incn3();
return a2+n;
};





long main()
{
a2 = 2;
//v#3.4 = 2;
//v#2 = v[10-1];
};

short voidfunc() ;



11 changes: 5 additions & 6 deletions semantic.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,17 @@ chama_parametros
;
*/
void checkParamPair(AST_NODE *declared, AST_NODE *called)
void checkParamPair(AST_NODE *declared, AST_NODE *called, int funcLineNumber)
{
int declaredDataType;

if (declared == NULL && called == NULL)
return;

if (declared == NULL && called != NULL)
semanticError("Numero de parametros errado!", called->lineNumber);

if (declared != NULL && called == NULL)
semanticError("Numero de parametros errado!", called->lineNumber);
semanticError("Numero de parametros errado!", funcLineNumber);

if (declared->type == AST_DEC_ARGS && called->type != AST_PARAM_LIST)
{
Expand All @@ -118,8 +117,8 @@ void checkParamPair(AST_NODE *declared, AST_NODE *called)

if (declared->type == AST_ARGS_LIST && called->type == AST_PARAM_LIST)
{
checkParamPair(declared->children[0], called->children[0]);
checkParamPair(declared->children[1], called->children[1]);
checkParamPair(declared->children[0], called->children[0], funcLineNumber);
checkParamPair(declared->children[1], called->children[1], funcLineNumber);
return;
}

Expand Down Expand Up @@ -183,7 +182,7 @@ int getExpressionDataType(AST_NODE *node)
checkIdentifierExists(node->symbol, node->lineNumber);
if (node->symbol->dataNature != NATURE_FUNC)
semanticError("O identificador nao eh uma funcao", node->lineNumber);
checkParamPair(node->symbol->funcParam, node->children[0]);
checkParamPair(node->symbol->funcParam, node->children[0], node->lineNumber);
return node->symbol->dataType;

case AST_LITERAL:
Expand Down
2 changes: 1 addition & 1 deletion semantic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void semanticError(const char * msg, int lineNumber);
void checkDeclr(AST_NODE *node);
int compareDataTypes(int a, int b, int lineNumber);
int getDataTypeFromVarType(AST_NODE *node);
void checkParamPair(AST_NODE *declared, AST_NODE *called);
void checkParamPair(AST_NODE *declared, AST_NODE *called, int funcLineNumber);
int getExpressionDataType(AST_NODE *node);
void checkIdentifier(HASH_NODE *node);
void checkChildren(AST_NODE *node);
Expand Down

0 comments on commit 584ff49

Please sign in to comment.