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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:46:31+00:00 2026-06-10T19:46:31+00:00

I must do a grammar for some compiler that I’m creating: Binary operators &&

  • 0

I must do a grammar for some compiler that I’m creating:
Binary operators && and || and unary operators # and * in a way that they:

I) || that have precedence over &&
II) && be associative to the left : a && b && c means ((a&&b)&&c)
III) || be associative to the right
IV) unary operators have equal precedence and more than binary operators

I was thinking something like this:

E -> E || T | E && T | T
T -> T # F | T * F
F -> (E) | Numbers
Numbers -> 0 | 1 | 2 | 3 | ... | 9

Would it be wrong ?
Any ideas ?

  • 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-10T19:46:33+00:00Added an answer on June 10, 2026 at 7:46 pm

    For simple expressions like these, you could always start from the least precedence.

    So you want to have a bunch of &&ed expressions, each of which are ||ed expressions of equally precedented unary operators.

    Before writing that down, look at these two rules:

    E -> E + T
    

    and

    E -> T + E
    

    The first rule makes + left associative while the second one makes it right associative (think about it). So you want your && to be left associative and || to be right associative:

    E -> E '&&' T | T         # left associative &&
    T -> F '||' T | F         # right associative ||
    

    The rule for unary operators is fairly easy:

    F -> '#' F | '*' F | N    # apply unary operators without precedence from right to left
    

    Finally, the most precedent is parentheses, which is as if you had an unbreakable token. Except, inside the parentheses you can have any expression:

    N -> '(' E ')' | number
    

    The number itself can be expressed by a regular expression, such as '[1-9][0-9]*'

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

Sidebar

Related Questions

I have some Fortran 77 source files that I'm trying to convert from a
I'm using ocamlyacc and ocamllex. I have an error production in my grammar that
I have a problem with the following language: I must write a context-free grammar:
So I have one issue with context free grammar that I didn't manage to
I want to parse some data, and I have a BNF grammar to parse
I have a collection of documents that I'm attempting to parse. Like HTML, they
Must be stupid question but for some time using Emacs I have no idea
Must be a way to avoid doing this in R. Some kind of mapping
Must be a way looping through this code: private void loadSprites() { this.sprites[0] =
I have file of some random text size = 27 gb and after compression

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.