1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to write a compiler program for if then else statement?

  1. May 31, 2016 #1
    < Mentor Note -- thread moved to HH from the technical physics forums, so no HH Template is shown >

    I was given the following question to answer for my Automata class:
    function =

    if(condition) then

    statement

    else

    statement

    the gramma for this if-then-else is

    S0 -> iCtSA (if <condition> then <statement> A)

    A -> ;eS | ε (;else<statement>|ε)

    1. please design an automata to simulate the compiler.

    2. how to write a compiler program for if-then-else statement



    What exactly does it mean when it says "write a compiler program for the if-then-else statement?" I designed an automata/state machine simulating the basic if then else format for part 1, but is it asking for an arbitrary if then else programming example of my own choosing( like any kind of if statement example) or a code simulation of the automata I created for part 1? Forgive me if my question seems very basic, I'm very new to Automata theory
     
    Last edited by a moderator: May 31, 2016
  2. jcsd
  3. May 31, 2016 #2

    jedishrfu

    Staff: Mentor

    Have they asked you to write compilers for expressions or other statements?

    The IF statement condition is a specific form of expression that evaluates to a boolean value. Expressions may have a simple form or may be more complex with expressions within expressions. Similarly for IF statements, either the THEN or the ELSE statement block may contain more IF statements. As another complication the ELSE block may be optional.

    I'm not sure how far your teacher wants you to go with this.

    Can you tell us what you've learned and what you've tried to implement this?

    Does the teacher really want you to describe the grammar of an IF statement?
     
  4. May 31, 2016 #3
    The class has been really unclear and nobody really knows what she wants in this assignment, but this was assigned right after we went over context free grammar, we reviewed the basics of Formalism, Derivations, Backup-Naur FORM, and Left-most and right-most derivations. And i assume that's as far as she wanted to go for this particular hw assignment. But it's still confusing since I have this due before i have the chance to go to the TA and ask what we are suppose to do. The professor is really hard to understand.
     
  5. May 31, 2016 #4
     

    Attached Files:

  6. May 31, 2016 #5

    jedishrfu

    Staff: Mentor

  7. May 31, 2016 #6

    berkeman

    User Avatar

    Staff: Mentor

    What textbook are you using for the class? Is the class just about compilers, or is it a more general computer science class?
     
  8. May 31, 2016 #7
    We have two textbooks that we can use, they are:

    1. Introduction to the Theory of Computation, by Michael Sipser
    and
    2. Introduction to Automata Theory, Languages, Computation

    I have also attached the POWER POINTS slides that we used for this assignment, but from what jedishrfu stated previously, i'm left to assume she wants a bnf....only i'm confused about the "design a compiler program" part of the assignment so it's unclear....why couldn't she just say design a bnf more directly?
     

    Attached Files:

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: How to write a compiler program for if then else statement?
Loading...