|
From: | Gurunathan_Murthy |
Subject: | RE: Help-bison Digest, Vol 2, Issue 2 |
Date: | Fri, 3 Jan 2003 09:45:09 +0530 |
Dear JotaO,
You do not a rule which identifies a decl_var followed by a decl_var
Thats what happens when you declare a int x; followed by int y;
decl_var
:type_var list_var ';'
;
so a rule like this
decl_var statement:
decl_var decl_var;
should solve your problem.
Include the decl_varStatement in your declarations rule.
This should work. Get back incase you are not clear.
All the Best!!
GSM(G S Murthy)
Satyam,India
-----Original Message-----
From: address@hidden [mailto:address@hidden]
Sent: Friday, January 03, 2003 2:44 AM
To: address@hidden
Subject: Help-bison Digest, Vol 2, Issue 2
Send Help-bison mailing list submissions to
address@hidden
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.gnu.org/mailman/listinfo/help-bison
or, via email, send a message with subject or body 'help' to
address@hidden
You can reach the person managing the list at
address@hidden
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Help-bison digest..."
Today's Topics:
1. Help with error in Bison (Jorge Oliveira)
----------------------------------------------------------------------
Date: 01 Jan 2003 21:31:29 +0000
From: Jorge Oliveira <address@hidden>
To: address@hidden
Subject: Help with error in Bison
Message-ID: <address@hidden>
Content-Type: multipart/mixed; boundary="=-XxPkl9xR0yPM4OEBCp8N"
MIME-Version: 1.0
Precedence: list
Message: 1
--=-XxPkl9xR0yPM4OEBCp8N
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Hello!
For a project at college i am working in a "look like C language"
grammar in a Flex/Bison environment
I'm having one problem.
It goes like this:
After compiling with no errors i try a small phrase like
int x;
This phrase is correct and is accepted by the parser.
If I write another phrase like that its generated the following parser
error
int x;
int y;
parse error, unexpected V_INT, expecting $
parse error, unexpected ID, expecting V_INT
parse error, unexpected ';', expecting V_INT
An odd thing is that if i do not put the ";" at the end of the first
phrase the parser does not generate any error and the error at the
second phrase is like this
int x
int y
parse error, unexpected V_INT, expecting ';' or ','
parse error, unexpected ID, expecting V_INT
This should be a problem of communication between Flex and Bison but I
cant see what.
I'm including the Flex and the Bison sources as well as the script I use
to compile them. These are not the complete sources but can well
illustrate the problem I described.
Thanks in advance for any help
JotaO (Jorge Oliveira)
Braga-Portugal
--=-XxPkl9xR0yPM4OEBCp8N
Content-Disposition: attachment; filename=tpf3-help.flex
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=tpf3-help.flex; charset=UTF-8
%{=0D
#include <stdio.h>
#include "tpf3-help.tab.h"
int linha=3D1;
%}=0D
%%=0D
[ \t]+ /*ESPA=C3=87OS - NAO FAZ NADA*/=0D
INT|int return V_INT;=0D
";" return ';';
"," return ',';=0D
([a-zA-Z]|_)([a-zA-Z]|[0-9]|_)* return ID;=0D
%%=0D
int yywrap()
{=0D
return(1);=0D
}
--=-XxPkl9xR0yPM4OEBCp8N
Content-Disposition: attachment; filename=tpf3-help.y
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=tpf3-help.y; charset=UTF-8
%{
#include <stdio.h>=0D
#define YYERROR_VERBOSE
extern int yyline;
extern char yytext[];
%}
%token V_INT
ID
%%
program
:declarations
/* |code */
;
declarations
:decl_var
/* |decl_const
|decl_main
|decl_func */
;
decl_var
:type_var list_var ';'
;
list_var
:ID =09
|list_var ',' ID
;
type_var
:V_INT
/* |V_CHAR
|V_FLOAT */
;
%%
main ()=20
{=20
while (1) yyparse ();=20
}
yyerror(s)
char *s;
{
fprintf (stderr, "%s\n", s);
}
--=-XxPkl9xR0yPM4OEBCp8N
Content-Disposition: attachment; filename=g
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-sh; name=g; charset=UTF-8
#!/bin/bash
if [ $# !=3D "1" ]
then
echo;echo;echo;
echo "Falta o parametro"
echo;echo;echo;
exit
fi
rm -f $1.tab.*
rm -f lex.yy.*
rm -f *~
rm -f tpf3
bison -d $1.y
/bin/echo "Pausa depois do Bison ...................................";#read=
c
flex $1.flex
/bin/echo "Pausa depois do Flex ....................................";#read=
c
gcc -g -c lex.yy.c
/bin/echo "Pausa depois de compilar output do Flex .................";#read=
c
gcc -g -c $1.tab.c
/bin/echo "Pausa depois de compilar output do Bison ................";#read=
c
gcc -o $1 lex.yy.o $1.tab.o -lfl && \
/bin/echo "Foi feita a compilacao final ............................"
--=-XxPkl9xR0yPM4OEBCp8N--
------------------------------
_______________________________________________
Help-bison mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/help-bison
End of Help-bison Digest, Vol 2, Issue 2
****************************************
**************************************************************************
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.
**************************************************************************
[Prev in Thread] | Current Thread | [Next in Thread] |