help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Grammar error


From: Miguel Ángel Molina Hernández
Subject: Grammar error
Date: Fri, 19 Jul 2013 10:17:52 +0200

* Hello,

  I'm a informatic student from Spain, i'm making my final project which it
is relationed with mathematics. I'm trying to solve for a few days but i
don't solve it. Maybe you can help me, :).*
*
*
*  My parser is too much difficult but i will show the problem of a reduced
form. I have this lexic.l :*

*%{*
*
*
*#include <iostream>*
*#include <string>*
*
*
*using namespace std;*
*
*
*#include "parser.tab.h"*
*%}*
*
*
*WS              [ \t\n\r\f]*
*BEZEICHNER      [a-zA-Z][a-zA-Z0-9]**
*ZAHL            0|([1-9][0-9]*)*
*GLEICH =*
*
*
*%%*
*
*
*{WS}       ;*
*
*
*{ZAHL}        {yylval.value = atoi(yytext); return NUM;}*
*
*
*{BEZEICHNER}  { yylval.name = new string (yytext); return ID;}*
*
*
*{GLEICH} return _GLEICH;*
*
*
*
*
*.       { cerr << "lexikalisch Fehler, ("<< yytext<<") unbekannt Zeichen
\n";}*


*And here the parser.y :*

*%{*
*
*
*#include <iostream>*
*#include <string>*
*#include <cstdio>*
*
*
* using namespace std;*
* *
* int yyerror(const char* msj);*
* int yylex(void); *
*
*
*
*
*%}*
*
*
*%union{*
*  int value;*
*  string* name;*
*}*
*
*
*
*
*%token <name> ID <value> NUM*
*%token _GLEICH*
*%type <value> formula atom equality_atom term name*
*
*
*%start start*
*
*
*%%*
*
*
*start : formula  { cout << "start--> formula\n";}*
* ;*
*
*
*formula : atom  { cout << "formula--> atom\n";}*
*;*
*atom :    equality_atom { cout << "atom --> equality_atom\n";}*
*;*
*
*
*equality_atom : term _GLEICH term { cout << "equality_atom --> term =
term\n";}*
*;*
*
*
*term :    name { cout << "term --> name\n";}*
*;*
*
*
*
*
*name :   ID { cout << "identifier --> ID (" << *$1 <<")\n";}*
*     | NUM { cout << "identifier --> NUM (" << $1 <<")\n";}*
*;*
*
*
*%%*
*
*
*int main(){*
* cout << " Introduce formula : ";*
* yyparse();*
* cout << "End of the programm"<< endl;*
* return EXIT_SUCCESS;*
*}*
*
*
*int yyerror(const char* msj){*
* cout << msj << endl;*
* return 1;*
*}*
*
*
*My question is : Why do the exit give no error with x =?, and why do the
exit give error with = x?.*
*
*
*I solved that with one add , a toke ';' so :*
*
*
*start :  formula ';'   { cout << "start--> formula\n";}*
* ;*
*
*
*Please, i will wait an answer, because it's very important for another
parts of the grammar, and so i can learn more about for my final project.*
*
*
*A lot of thanks.*
*
*
*Miguel.*


reply via email to

[Prev in Thread] Current Thread [Next in Thread]