Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7637431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:56:15+00:00 2026-05-31T07:56:15+00:00

I am using YACC to do my compiler homework project. I found that my

  • 0

I am using YACC to do my compiler homework project. I found that my program could not get the syntax tree. So I printed it all out to see what is happening. According to my result, it seems that ClassDecl does not reduce to ClassDeclList here. But I can’t understand why… can anyone help me out?

The sample input is:

   program ex11;
   class ab {
   }

It printed out as:

    programXXXX ex11ID
    semicon abID
    RBRACEnum 
    ClassBody ClassDecl ClassDecl1 Error!

The first three lines are messages I printed from my LEX file, to ensure that the characters are recognized correctly.

According to the information, the parser successfully reduces {} to ClassBody and class ab {} to ClassDecl. And then it does not reduce to ClassDeclList, is it because I am writing a left recursive grammar here?

This is the part of my YACC rule base for the inference:

    Program: PROGRAMnum IDnum SEMInum ClassDeclList
{printf("program"); $$ = MakeTree(ProgramOp,$4, MakeLeaf(IDNode,$2)); printtree($$,0);};

   ClassDeclList: ClassDecl 
{printf("ClassDeclList1");$$ = MakeTree(ClassOp,NullExp(),$1); printf("ClassDeclListend");};
                  |ClassDecl ClassDeclList 
{printf("ClassDeclList2");$$ = MakeTree(ClassOp,$2,$1); printf("ClassDeclList");};

    ClassDecl: CLASSnum IDnum ClassBody
{printf("ClassDecl");$$=MakeTree(ClassDefOp,$3,MakeLeaf(IDNode,$2)); printf("ClassDecl1");};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:56:16+00:00Added an answer on May 31, 2026 at 7:56 am

    Have you tried

    | ClassDeclList ClassDecl
    

    instead of

    | ClassDecl ClassDeclList
    

    ?

    I remember this fixing many problems when I used to use CUP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I'm writing a compiler in ocaml, using ocamllex/yacc. Things are going well, but I've
How much time would it take to write a C++ compiler using lex/yacc? Where
My fsyacc code is giving a compiler error saying a variable is not found,
I'm having trouble finding a Yacc or Bison that doesn't require using darwinports for
using chrome 15 on osx 10.6.8 When adding event listeners, I've found that putting
Using Browserlab, it appears that the background image is not centred in Firefox7 for
How do I compile, link and call different YACC grammars using yyparse() in one
I am compiling a YACC file using Cygwin shell on a PC. I am
I am developing a simple translator from MathML to Latex, using Lex and Yacc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.