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

  • Thread starter Thread starter ChakanaX
  • Start date Start date
  • Tags Tags
    Compiler Program
Click For Summary

Discussion Overview

The discussion revolves around the assignment of writing a compiler program for an if-then-else statement as part of an Automata class. Participants explore the requirements of the assignment, including the design of an automata and the interpretation of what constitutes a compiler program for this specific statement.

Discussion Character

  • Debate/contested
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant questions whether the assignment requires writing compilers for expressions or other statements, noting that the IF statement condition evaluates to a boolean value and can be complex.
  • Another participant expresses uncertainty about the extent of the assignment, asking for clarification on what has been learned and attempted regarding the implementation.
  • Concerns are raised about the clarity of the assignment, with participants noting that the professor's expectations are not well understood, particularly regarding the grammar of the IF statement.
  • One participant suggests defining the grammar of the IF statement using Backus-Naur Form (BNF) as a potential approach to the assignment.
  • Another participant mentions the textbooks being used for the class, indicating that they may provide relevant context for the assignment.
  • There is confusion about the phrase "design a compiler program," with participants questioning why the assignment did not more directly request a BNF.

Areas of Agreement / Disagreement

Participants generally express uncertainty and confusion about the assignment requirements, indicating that there is no clear consensus on what is expected. Multiple competing interpretations of the assignment exist.

Contextual Notes

Participants mention having recently covered topics such as context-free grammar, formalism, and derivations, which may influence their understanding of the assignment. There is a noted lack of clarity regarding the specific expectations from the professor.

Who May Find This Useful

Students studying automata theory, compiler design, or related computer science topics may find this discussion relevant, particularly those facing similar assignments or challenges in understanding compiler requirements.

ChakanaX
Messages
6
Reaction score
0
< Mentor Note -- thread moved to HH from the technical physics forums, so no HH Template is shown >[/color]

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:
Physics news on Phys.org
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?
 
jedishrfu said:
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?

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 homework 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.
 
ChakanaX said:
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 homework 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. I have attached my attempt at part 1
 

Attachments

  • autom.jpg
    autom.jpg
    15.1 KB · Views: 717
ChakanaX said:
The class has been really unclear and nobody really knows what she wants in this assignment
What textbook are you using for the class? Is the class just about compilers, or is it a more general computer science class?
 
berkeman said:
What textbook are you using for the class? Is the class just about compilers, or is it a more general computer science class?
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?
 

Attachments

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
Replies
7
Views
3K
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 21 ·
Replies
21
Views
4K
Replies
11
Views
2K
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K