#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    4
    Rep Power
    0

    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 :P

    Thanks in advance!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    4
    Rep Power
    0
    worry not ive resolved them. can somwone lock this plz?
  4. #3
  5. fork while true;
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2005
    Location
    England, UK
    Posts
    5,538
    Rep Power
    1051
    Only if you post your solution

    We don't lock threads here.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    4
    Rep Power
    0
    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)

    Comments on this post

    • LinuxPenguin agrees : Thanks for posting the solution :)

IMN logo majestic logo threadwatch logo seochat tools logo