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

  • Home
  • SEARCH
  • 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 8325659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:30:47+00:00 2026-06-09T00:30:47+00:00

I am trying to find out where I went wrong in the below code.

  • 0

I am trying to find out where I went wrong in the below code.

Flex input:

%{
        #include "jq.tab.h"
        void yyerror(char *);
%}
method          add|map|.. and other methods go here

%%

"/*"            { return CS; }

"*/"            { return CE; }

"jQuery"        {
                printf("%s is yytext\n", yytext);
                return *yytext;
                }

"args"          { return ARGUMENT; }

{method}        { return METHOD; }

[().\n]         { return *yytext; }

[ \t]+          { return WS; }

.               { return IGNORE; }

%%

int yywrap(void) {
        return 1;
}

Bison input:

%{
        #include <stdio.h>
        int yylex(void);
        void yyerror(char *);
%}

%token ARGUMENT METHOD IGNORE WS CS CE
%error-verbose

%%

stmts:
        stmt '\n'               { printf("A single stmt\n"); }
        | stmt '\n' stmts       { printf("Multi stmts\n"); }
        ;

stmt:
        jQuerycall                      { printf("A complete call ends here\n"); }
        | ignorechars                   { printf("Ignoring\n"); }
        | ignorechars WS jQuerycall     { printf("ignore+js\n"); }
        | jQuerycall WS ignorechars     { printf("js+ignore\n"); }
        | optionalws stmt optionalws
        | CS stmt CE                    { printf("comment\n"); }
        ;

jQuerycall:
        'jQuery' '(' ARGUMENT ')' '.' methodchain       { printf("args n methodchain\n"); }
        | 'jQuery' '(' ')' '.' methodchain              { printf("methodchain\n"); }
        | 'jQuery' '(' ARGUMENT ')'                     { printf("args\n"); }
        | 'jQuery' '(' ')'                              { printf("empty call\n"); }
        ;

methodchain:
        methodchain '.' methodcall
        | methodcall
        ;

methodcall:
        METHOD '(' ')'
        ;

ignorechars:
        IGNORE
        | IGNORE optionalws ignorechars
        ;

optionalws:
        | WS
        ;

%%

void yyerror(char *s) {
        fprintf(stderr, "%s\n", s);
}

int main(void) {
        yyparse();
        return 0;
}

My aim is to recognize any jQuery call with all its elements, and ignore any other statement / string. Also ignore comments. Right now, this code makes many assumptions – like ‘args’ to be the only selector element inside jQuery().

Edit

I am using the following input-output cases. Cases like 10 and 12 are the ones I’m trying to figure out:

> 1.input: statement\n output: Ignoring
> 
> 2.input: statement statement\n output: Ignoring
> 
> 3.input: statement statement statement\n output: Ignoring
> 
> 4.input: jQuery()\n output: jQuery is yytext empty call A complete call ends here
> 
> 5.input: jQuery(args)\n output: jQuery is yytext args A complete call ends here
> 
> 6.input: jQuery().add()\n output: jQuery is yytext methodchain A complete call ends here
> 
> 7.input: jQuery(args).add().map()\n output: jQuery is yytext args n methodchain A complete call ends here
> 
> 8.input: /*comment*/\n output: Ignoring comment
> 
> 9.input: /*jQuery()*/\n output: jQuery is yytext empty call A complete call ends here comment
> 
> 10.input: /* comment */\n output: syntax error, unexpected CE, expecting IGNORE
> 
> 11.input: var a = b\n output: Ignoring
> 
> 12.input: var a = jQuery(args)\n output: jQuery is yytext syntax error, unexpected 'jQuery', expecting IGNORE
  • 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-06-09T00:30:49+00:00Added an answer on June 9, 2026 at 12:30 am

    In your lex file, the rule:

    "jQuery"        {
                    printf("%s is yytext\n", yytext);
                    return *yytext;
                    }
    

    returns the token 'j' when it sees an input string of jQuery. Since your bison file never does anything with the token 'j' this will generally give you a syntax error.

    You need to add JQUERY to your %token declaration and have this lex rule return that.

    edit

    Usually a comment can appear anywhere in the program (between any two other tokens) and are completely ignored. So the easiest way to deal with them is in the lexer:

    %x comment
    %%
    "/*"           { BEGIN comment; }
    <comment>.     ;
    <comment>"*/"  { BEGIN 0; }
    

    this will skip over comments (returning no tokens at all), so the grammar doesn’t need to worry about them. If you don’t want to use a lexer start state, you could instead use the complex regex:

    "/*"([^*]|\*+[^*/])*\*+"/"          ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find out exactly when some part of a site went live
New to Python and trying to figure out what went wrong here. Making a
I am trying to find out all the oEmbed providers out there. I went
Trying to find out if it's possible to use SQLAlchemy on Heroku. Thanks.
I trying to find out the visibility of the Excel and do some activities
I am trying to find out how to write an SQL statement that will
i m trying to find out how to convert timestamp date and time (
I am trying to find out a way to set a time tag to
I am trying to find out if an instance of an application (not vb.net)
I'm trying to find out how to change the icon of a JStree node

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.