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 124775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:03:14+00:00 2026-05-11T05:03:14+00:00

I am trying to build a Lisp grammar. Easy, right? Apparently not. I present

  • 0

I am trying to build a Lisp grammar. Easy, right? Apparently not.

I present these inputs and receive errors…

( 1 1) 23 23 23  ui ui 

This is the grammar…

%% sexpr: atom                 {printf('matched sexpr\n');}     | list     ; list: '(' members ')'       {printf('matched list\n');}     | '('')'                {printf('matched empty list\n');}     ; members: sexpr              {printf('members 1\n');}     | sexpr members         {printf('members 2\n');}     ; atom: ID                    {printf('ID\n');}     | NUM                   {printf('NUM\n');}     | STR                   {printf('STR\n');}     ; %% 

As near as I can tell, I need a single non-terminal defined as a program, upon which the whole parse tree can hang. But I tried it and it didn’t seem to work.

edit – this was my ‘top terminal’ approach:

program: slist;  slist: slist sexpr | sexpr; 

But it allows problems such as:

( 1 1  

Edit2: The FLEX code is…

%{     #include <stdio.h>     #include 'a.yacc.tab.h'     int linenumber;     extern int yylval; %} %% \n                         { linenumber++; } [0-9]+                     { yylval = atoi(yytext); return NUM; } \'[^\'\n]*\'               { return STR; } [a-zA-Z][a-zA-Z0-9]*       { return ID; } . %% 

An example of the over-matching…

(1 1 1) NUM matched sexpr NUM matched sexpr NUM matched sexpr (1 1 NUM matched sexpr NUM matched sexpr 

What’s the error here?

edit: The error was in the lexer.

  • 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. 2026-05-11T05:03:14+00:00Added an answer on May 11, 2026 at 5:03 am

    The error is really in the lexer. Your parentheses end up as the last ‘.’ in the lexer, and don’t show up as parentheses in the parser.

    Add rules like

    \)     { return RPAREN; } \(     { return LPAREN; } 

    to the lexer and change all occurences of ‘(‘, ‘)’ to LPAREN and RPAREN respectively in the parser. (also, you need to #define LPAREN and RPAREN where you define your token list)

    Note: I’m not sure about the syntax, could be the backslashes are wrong.

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

Sidebar

Related Questions

No related questions found

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.