Starting from:

$25+

CmpE150.03 - HW5 - Solved

Introduction to Computing,                           

In this homework, you are going to implement the SiNiR compiler. The details are as follows:

Given a file named calc.in, your program should check whether there are any syntax errors.         There will always be a file named calc.in             There will be no tab character in the file.

•       If there is a syntax error, 

◦ Create a new file, named calc.out and print “Dont Let Me Down” inside.

•       If there are no syntax errors,

◦ Create a new file, named calc.out and print “Here Comes the Sun” inside.

•       Do not print out anything to the terminal in the submitted file. calc.in is composed of three parts. If one of those parts are missing, there is a syntax error.

 
AnaDegiskenler







<init-statement>

<init-statement>

<init-statement>

….

YeniDegiskenler
<mid-statement

<mid-statement

<mid-statement …..

Sonuc
<final-statement
The general structure of calc.in should be in the following form:

•       Empty lines are allowed anywhere in the file. 

•       Spaces are allowed at any point unless specified. There should be no space in the shaded sequences. For example, there might be space before AnaDegiskenler or after; however there should be no space between <digit>.<digit>. 

•       The file should start with the AnaDegiskenler statement. If not, there is a syntax error.

•       There are zero or more <init-statement>s after AnaDegiskenler statement. Each <init-statement> should be in a single line. If not, there is a syntax error.

•       The file then continues with the YeniDegiskenler statement. If not, there is a syntax error.

•       There are zero or more <mid-statement>s after the YeniDegiskenler statement. Each <mid-statement> should be in a single line. If not, there is a syntax error.

•       The file continues with the Sonuc statement.  If not, there is a syntax error.

•       There is zero or one <final-statement> after the Sonuc statement. <final-statement> should be in a single line. If not, there is a syntax error.

Important: 

•       The language is case sensitive.

•       Keywords cannot be used as variable names.

<init-statement>

is constructed by        


<var-name> degeri <value> olsun





Any number of spaces (including space and tab) are allowed in <init-statement> <var-name> is composed of at most ten alpha-numeric characters The same variable cannot be assigned more than once.

<value> := <a-term> | <l-term> 

◦ the above line means that <value> can be <a-term> or <l-term>






<a-term> := <digit> | <digit>.<digit> | <t-digit> | <t-digit> nokta <t-digit> 

<digit>     :=  0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

<t-digit>   :=  sifir | bir | iki | uc | dort | bes | alti | yedi | sekiz | dokuz

<l-term>   := dogru | yanlis

If above rules do not hold, it’s syntax error.

<mid-statement>

is constructed by        


<var-name> degeri <expression> olsun





Any number of spaces are allowed in <mid-statement> <var-name> is composed of at most ten alpha-numeric characters the same variable cannot be assigned more than once.

<expression> := <arith-expr> | <logic-expr>

◦ i.e. <expression> should be either <arith-expr> or <logic-expr>



<var-name> will be of type float if it is <arith-expr>

<var-name> will be of type boolean if it is <logic-expr>


<arith-exp> := <open-paran> <arith-exp> <close-paran>

                   := <arith-exp> <binaop> <arith-exp>

                   := <a-term>

                   := <a-var-name>


 <open-paran> := (  | ac-parantez


<clos-paran>  := ) | kapa-parantez


<binaop> := + | - | * | arti | eksi | carpi



<a-var-name> should represent a variable of type int or float <a-var-name> should be defined in the previous lines.


<logic-exp> := <open-paran> <logic-exp> <close-paran>

                    := <logic-exp> <binlop> <logic-exp>

                    := <l-term>

                    := <l-var-name>





<binlop> := ve | veya

<l-var-name> should represent a variable of type boolean <l-var-name> should be defined in the previous lines.

If above rules do not hold, it’s syntax error.


<final-statement> is constructed by:

<expression> 




The same rules for <expression> apply (as above). Any number of spaces are allowed in <final-statement> If above rules do not hold, there is a syntax error

More products