elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  error de sintaxis
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] 2 Ir Abajo Respuesta Imprimir
Autor Tema: error de sintaxis  (Leído 7,175 veces)
mapers


Desconectado Desconectado

Mensajes: 638


Ver Perfil
error de sintaxis
« en: 18 Septiembre 2010, 08:41 am »

porque me sale este error
Código:
syntax error before `bool'


En línea

bizco


Desconectado Desconectado

Mensajes: 698


Ver Perfil
Re: error de sintaxis
« Respuesta #1 en: 18 Septiembre 2010, 08:48 am »

pon el codigo


En línea

mapers


Desconectado Desconectado

Mensajes: 638


Ver Perfil
Re: error de sintaxis
« Respuesta #2 en: 18 Septiembre 2010, 09:06 am »

Código
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #define AFN_MAX 11
  7. #define EPSILON -1
  8. #define ACEPTA -2
  9. #define STACKSIZE 100
  10. #define MAXIMO 80
  11. #define TRUE  1
  12. #define FALSE 0
  13.  
  14. enum bool {FALSE,TRUE};
  15.  
  16.  
  17.  
  18.  
  19. bool no_marcado(int* t,int m,int estadosD[][AFN_MAX],int nest)
  20. {
  21. int k=0,j,i;
  22. for(k=0;k<nest;k++) {
  23. i=0;
  24. for(j=0;j<m;j++)
  25. if(t[j]==estadosD[k][j])
  26. i++;
  27. if(i==m)
  28. return FALSE;
  29. }
  30. return TRUE;
  31. }
  32.  
  33.  
  34.  
En línea

bizco


Desconectado Desconectado

Mensajes: 698


Ver Perfil
Re: error de sintaxis
« Respuesta #3 en: 18 Septiembre 2010, 09:40 am »

bool no esta definido como tipo de dato, usalo con typedef. usa o define o enum:

enum
{
 tal //0
 tal //1
 ...
 ...
 tal N
}
En línea

Komodo


Desconectado Desconectado

Mensajes: 352



Ver Perfil
Re: error de sintaxis
« Respuesta #4 en: 18 Septiembre 2010, 11:34 am »

A mi me ocurria exactamente lo mismo...

Pero con gcc si que me funciono :S
En línea


bizco


Desconectado Desconectado

Mensajes: 698


Ver Perfil
Re: error de sintaxis
« Respuesta #5 en: 18 Septiembre 2010, 12:04 pm »

ese codigo tal cual esta te compila bien en gcc?
En línea

Komodo


Desconectado Desconectado

Mensajes: 352



Ver Perfil
Re: error de sintaxis
« Respuesta #6 en: 18 Septiembre 2010, 13:25 pm »

Ese code no lo he probado, pero yo tenía un code con una función booleana que no me compilaba en minGW y me daba el mismo error.

Sigo sin saber porque es..
En línea


bizco


Desconectado Desconectado

Mensajes: 698


Ver Perfil
Re: error de sintaxis
« Respuesta #7 en: 18 Septiembre 2010, 13:34 pm »

eso sera pq en c no esta definido el tipo de dato bool, sin ver el codigo es dificil decirte. pero en este caso tiene definido 2 veces TRUE y FALSE una con define y otra en el enum, luego la funcion esta mal si quiere devolver un tipo de dato propio como seria el "bool" de su enum tendria que definirlo como tal.

PD: aparte de todo eso, parece como si quisiera ser c++ y este si tiene el tipo bool definido.
« Última modificación: 18 Septiembre 2010, 13:44 pm por ctlon » En línea

Garfield07


Desconectado Desconectado

Mensajes: 1.121


¡Este año voy a por todas! JMJ 2011


Ver Perfil WWW
Re: error de sintaxis
« Respuesta #8 en: 18 Septiembre 2010, 22:15 pm »

personalmente, por compatibilidad te recomiendo en vez de usar un typedef y estructura bool usa int. INT 0, en INT  1. es suficiente
En línea



* Quiero cambiar el mundo, pero estoy seguro de que no me darían el código fuente.
* No estoy tratando de destruir a Microsoft. Ese será tan solo un efecto colateral no intencionado.
* Si compila esta bien, si arranca es perfecto.

¡Wiki elhacker.net!
Un saludo
mapers


Desconectado Desconectado

Mensajes: 638


Ver Perfil
Re: error de sintaxis
« Respuesta #9 en: 22 Septiembre 2010, 05:15 am »

este es el codigo
Código
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #define AFN_MAX 11
  7. #define EPSILON -1
  8. #define ACEPTA -2
  9. #define STACKSIZE 100
  10. #define MAXIMO 80
  11. #define TRUE  1
  12. #define FALSE 0
  13.  
  14. typedef bool {
  15.     FALSE,TRUE
  16.    };
  17. struct stack {
  18. int top;
  19. int items[STACKSIZE];
  20. };
  21. typedef stack *STACKPTR;
  22. bool empty(STACKPTR ps);
  23. int pop(STACKPTR ps);
  24. void push(STACKPTR ps,int x);
  25. void init(STACKPTR ps);
  26. void e_clausura(int* ,int,int* ,int &na);
  27. void mover(int *,int,int* t,int &m,int c);
  28. void print(int* t,int m,char c);
  29. void copy(int*,int,int estadosD[][AFN_MAX],int &nest,int*);
  30. bool no_marcado(int*,int,int estadosD[AFN_MAX][AFN_MAX],int nest);
  31. void aceptacion();
  32. void print_estadosD(int estadosD[][AFN_MAX],int nest,int nD[]);
  33. // 0 1 2 3 4 5 6 7 8 9 10
  34. int aristas[][AFN_MAX]=
  35. {0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0,
  36. 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0,
  37. 0, 0, 0,'a', 0, 0, 0, 0, 0, 0, 0,
  38. 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0,
  39. 0, 0, 0, 0, 0,'b', 0, 0, 0, 0, 0,
  40. 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0,
  41. 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0,
  42. 0, 0, 0, 0, 0, 0, 0, 0,'a', 0, 0,
  43. 0, 0, 0, 0, 0, 0, 0, 0, 0,'b', 0,
  44. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'b',
  45. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2
  46. };
  47. int main() // afnafd.cpp
  48. {
  49. int m,i,j,k;
  50. int t[AFN_MAX];
  51. int estadosD[AFN_MAX][AFN_MAX],nest=0;
  52. int nD[AFN_MAX];
  53. int a[AFN_MAX],na;
  54. char* alfabeto="ab";
  55. //clrscr();
  56. *t=0;m=1;
  57. cout << "estado : " << nest << endl;
  58. e_clausura(t,m,a,na);
  59. copy(a,na,estadosD,nest,nD);
  60. for(i=0;i<strlen(alfabeto);i++) {
  61. mover(a,na,t,m,alfabeto[i]);
  62. cout << "estado : " << nest << endl;
  63. print(t,m,alfabeto[i]);
  64. copy(t,m,estadosD,nest,nD);
  65. }
  66. for(k=1;k<nest;k++) {
  67. for(j=0;j<nD[k];j++)
  68. t[j]=estadosD[k][j];
  69. m=nD[k];cout << " K : " << k << endl;
  70. e_clausura(t,m,a,na);
  71. for(i=0;i<strlen(alfabeto);i++) {
  72. mover(a,na,t,m,alfabeto[i]);
  73. if(m) {
  74. if(no_marcado(t,m,estadosD,nest)) {
  75. cout << "estado : " << nest << endl;
  76. copy(t,m,estadosD,nest,nD);
  77. print(t,m,alfabeto[i]);
  78. }
  79. else
  80. print(t,m,alfabeto[i]);
  81. }
  82. }
  83. }
  84. aceptacion();
  85. print_estadosD(estadosD,nest,nD);
  86. }
  87. void print_estadosD(int estadosD[][AFN_MAX],int nest,int nD[])
  88. {
  89. register int i,j;
  90. //clrscr();
  91. cout << " AFD AFN " << endl;
  92. cout << "---------------------------------------" << endl;
  93. for(i=0;i<nest;i++) {
  94. cout << setw(4) << i << " : ";
  95. for(j=0;j<nD[i];j++)
  96. cout << setw(4) << estadosD[i][j];
  97. cout << endl;
  98. }
  99. cout << "---------------------------------------" << endl;
  100. getch();
  101. }
  102. void aceptacion()
  103. {
  104. cout << "estados de aceptacion tienen los nodos : ";
  105. for(int i=0;i<AFN_MAX;i++)
  106. if(aristas[i][i]==ACEPTA)
  107. cout << setw(4) << i;
  108. getch();
  109. }
  110. void e_clausura(int* s,int n,int* a,int &na)
  111. {
  112. int i,j,t,u;
  113. STACKPTR p;
  114. // meter todos los estados en pila
  115. // inicializar cerradura a
  116. init(p);
  117. na=0;
  118. for(i=0;i<n;i++) {
  119. push(p,s[i]);
  120. a[i]=s[i];
  121. na++;
  122. }
  123. while(!empty(p)) {
  124. t=pop(p);
  125. for(u=0;u<AFN_MAX;u++)
  126. if(aristas[t][u]==EPSILON) {
  127. i=0;
  128. while(i<na && u!=a[i])
  129. i++;
  130. if(i==na) {
  131. // a¤adir u a cerradura
  132. a[na++]=u;
  133. // meter u a pila
  134. push(p,u);
  135. }
  136. }
  137. }
  138. cout << " T : " ;
  139. for(j=0;j<na;j++)
  140. cout << setw(4) << a[j];
  141. cout << endl;
  142. }
  143. void print(int* t,int m,char c)
  144. {
  145. register int j;
  146. cout << " mover(T," << c << ") : ";
  147. for(j=0;j<m;j++)
  148. cout << setw(4) << t[j];
  149. cout << endl;
  150. }
  151. void copy(int* t,int m,int estadosD[][AFN_MAX],int &nest,int* nD)
  152. {
  153. register int i;
  154. for(i=0;i<m;i++)
  155. estadosD[nest][i]=t[i];
  156. nD[nest]=m;
  157. ++nest;
  158. }
  159. void mover(int* a,int na,int* t,int &m,int c)
  160. {
  161. int i,j,k;
  162. m=0;
  163. for(i=0;i<na;i++) {
  164. k=a[i];
  165. for(j=0;j<AFN_MAX;j++)
  166. if(aristas[k][j]==c)
  167. t[m++]=j;
  168. }
  169. }
  170. bool no_marcado(int* t,int m,int estadosD[][AFN_MAX],int nest)
  171. {
  172. int k=0,j,i;
  173. for(k=0;k<nest;k++) {
  174. i=0;
  175. for(j=0;j<m;j++)
  176. if(t[j]==estadosD[k][j])
  177. i++;
  178. if(i==m)
  179. return FALSE;
  180. }
  181. return TRUE;
  182. }
  183.  
  184.  
  185. bool empty(STACKPTR ps)
  186. {
  187. if(ps->top==-1)
  188. return TRUE;
  189. else
  190. return FALSE;
  191. }
  192. int pop(STACKPTR ps)
  193. {
  194. if(empty(ps)) {
  195. cout << "\n pila vacia " << endl;
  196. exit(1);
  197. }
  198. return (ps->items[ps->top--]);
  199. }
  200. void push(STACKPTR ps,int x)
  201. {
  202. if(ps->top==STACKSIZE-1) {
  203. cout << "\n stack overflow" << endl;
  204. exit(1);
  205. }
  206. else
  207. ps->items[++(ps->top)]=x;
  208. }
  209. void init(STACKPTR ps)
  210. {
  211. ps->top=-1;
  212. }
  213.  
  214.  
En línea

Páginas: [1] 2 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Error de sintaxis [Python]
Scripting
Ricardo95 3 4,817 Último mensaje 2 Diciembre 2010, 17:53 pm
por Ricardo95
Error de sintaxis en la instrucción INSERT INTO
Bases de Datos
GhostLT 6 11,351 Último mensaje 9 Marzo 2011, 22:49 pm
por Nakp
Error con funcion if, me da error de sintaxis
Scripting
Danyel_Casvill 4 3,433 Último mensaje 30 Abril 2011, 16:32 pm
por Danyel_Casvill
error sintaxis INSERT INTO
PHP
soru13 3 2,485 Último mensaje 15 Mayo 2012, 16:40 pm
por soru13
volviendome loco error en sql sintaxis LA 1 ME DA ERROR Y SI REPITO ME DA ok
Java
yo_lestat 0 1,915 Último mensaje 17 Agosto 2012, 20:43 pm
por yo_lestat
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines