|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Lex/Yacc (shift | reduce)/reduce conflicts
hi everyone, i posted this in the archives forum foolishly. however, moving on, i am complete novice at lex, yacc, and the whole compiler thing, but i was wondering, if i go ahead and post my yacc file, will anyone be able to help identify some of my...
yacc: 14 shift/reduce conflicts yacc: 42 reduce/reduce conflicts ?? I'm sorry if this is some massive task but i have been at this for hours, and i'm really not sure what i'm doing, so i apologise if this is a jerk move on my part Code:
%{
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
char *fname;
extern int lastentry;
%}
%token IDENTIFIER INTCONSTANT BOOLCONSTANT ASSIGNMENT NOTEQUAL LESSTHANOREQUAL
%token GREATERTHANOREQUAL WHITESPACE COMMENT INTEGER BOOLEAN BEGINN END WHILE
%token DO IF THEN READ WRITE PROGRAM
%left '+' '-'
%left '*' '/'
%%
program: PROGRAM IDENTIFIER ';' declarationlist statementlist '.'
;
declarationlist: declarationlist declaration
|
;
declaration: type identifierlist ';'
;
identifierlist: IDENTIFIER ',' identifierlist
|
;
type: INTEGER
| BOOLEAN
;
statementlist: BEGINN statements END
;
statements: statements statement
|
;
statement: assignmentstatement
| ifstatement
| whilestatement
| writestatement
| readstatement
;
assignmentstatement: IDENTIFIER ASSIGNMENT expression ';'
;
ifstatement: IF expression THEN statementlist ';'
;
whilestatement: WHILE expression DO statementlist ';'
;
writestatement: WRITE expressionlist ';'
;
readstatement: READ identifierlist ';'
;
expressionlist: expression ',' expressionlist
|
;
expression: relation relationallist
;
relationallist: relationallist relationaloperator relation
|
;
relationaloperator: '='
| NOTEQUAL
| '<'
| LESSTHANOREQUAL
| '>'
| GREATERTHANOREQUAL
;
relation: term addingoplist
;
addingoplist: addingoplist addingop term
|
;
addingop: '+'
| '-'
;
term: factor multioplist
;
multioplist: multioplist multiop factor
|
;
multiop: '*'
| '/'
;
factor: IDENTIFIER
| INTEGER
| expression
;
%%
int main(void)
{
yyparse();
return 0;
}
Any help any of you can give me will be hugely appreciated. if this isnt enough info to be able to do anything, i apologise and will tell you what i can. <-- this guy articulates my feelings well :PThanks in advance! |
|
#2
|
|||
|
|||
|
worry not ive resolved them. can somwone lock this plz?
![]() |
|
#3
|
||||
|
||||
|
Only if you post your solution
![]() We don't lock threads here.
__________________
~James [Not currently seeking freelance work] Like philosophy or interested in spirituality? Philosophorum. Game Dev Experts Forums Foresight Linux - Because your desktop should be cool! Linux FAQ FedoraFAQ UbuntuGuide |
|
#4
|
|||
|
|||
|
the sloution was that for example:
Code:
declarationlist: declarationlist declaration
| declaration
|
should be: Code:
declarationlist: declarationlist declaration
|
i updated the original post.....just in case anyone spotted anything else is wrong.....seeing as its still not functioning coorectly (but the yacc conflicts are gone....and thats why i started this) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Lex/Yacc (shift | reduce)/reduce conflicts |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|