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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:06:22+00:00 2026-06-01T20:06:22+00:00

I am wondering if all programming language reserve keys words? Says If , While

  • 0

I am wondering if all programming language reserve keys words? SaysIf,While are reserved key words. We should not use it as ordinary variable or function name say if I have If = 3 is illegal. So compiler will generate error during sanner phase. What if a language allow programmer use reserved keywords say If as variable name or function name. How do the compiler can handle this? Does this get handled in the scanner or parser? What should semantic analysis do?

update:
I understand this is not a good practice but the real reason for most/all programming language not support this is because scanner or parser cannot do acurately scanning the language or parsing the language OR what it is really behind scenes? Thanks.

  • 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-01T20:06:22+00:00Added an answer on June 1, 2026 at 8:06 pm

    You definitely could do such a thing, but obviously it would destroy the intuitiveness of the source code. Imagine this:

    if if == 1
    

    As far as actually implementing it, the lexer wouldn’t have to be changed at all. If the lexer matches “if” in the source it returns a token with an IF type. Suppose we have the following assignment statement, where if is a variable name and it’s getting assigned the value 1.

    if <- 1;
    

    The lexer’s token stream to be fed to the parser is:

    IF, LARROW, INTLITERAL, SEMICOLON
    

    I might have the following productions to describe an assignment statement (\w integer rvals):

    assignStmt::= id:i LARROW intExpr:e SEMICOLON {: RESULT = new AssignmentStatement(i, e) :}
    intExpr::= INTLITERAL:i {: RESULT = i.intVal; :}
    id::= ID:i {: RESULT = i.strVal; :}
    

    LARROW, ID, IF, INTLITERAL, and SEMICOLON are terminals, which are tokens returned by the lexer, and assignStmt, id, and intExpr are non-terminals. ID represents an identifier (e.g. class/variable/method name).

    After failing the production for an if statement, we’ll eventually enter the first production for an assignment statement. We expand the id non-terminal, whose only production is ID, but the token I want to match is IF, so the assignStmt production fails altogether.

    For my language to allow a variable to be named “if” all I have to do is:

    assignStmt::= id:i LARROW intExpr:e SEMICOLON {: RESULT = new AssignmentStatement(i, e) :}
    intExpr::= INTLITERAL:i {: RESULT = i.intVal; :}
    id::= ID:i {: RESULT = i.strVal; :}
         |IF {: RESULT = "if"; :}
    

    Note that | defines an alternate production for the non-terminal. Now we have that second production for the id non-terminal, which matches the current token, and ultimately results in matching an assignment statement.

    AssignmentStatement is an AST node defined as follows:

    class AssignmentStatement {
         String varName;
         int intVal;
         AssignmentStatement(String s, int i){varName = s; intVal = i; }
    }
    

    Once the parser decides the source is syntactically correct, nothing else should be affected. The names of your variables shouldn’t affect the latter stages of compilation, that is if you don’t create conditions that would allow that to happen.

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

Sidebar

Related Questions

Just wondering why people like case sensitivity in a programming language? I'm not trying
Hi all I was wondering is it true that the first-language of monitors is
Wondering if it is at all possible. found: <script type=javascript> isSafari3 = false; if(window.devicePixelRatio)
Hullo all, Wondering if there are any Java hackers who can clue me in
Hey all. I'm wondering how to implement a timeout event in the System.Windows.Forms.Webbrowser control?
Hey all, I am wondering what the best way to do the following is:
I have been wondering how to put all the stored procedures on a SQL
I am wondering why I can't see all page events in visual studio 2008,
I was wondering if you could show me all the various ways to declare
Hey all, I'm just wondering if it is possible to get the name of

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.