0% found this document useful (0 votes)
10 views

Project 1 Text

The document provides instructions for an assignment to write a lexical analyzer for FORTRAN 77. Students are asked to prompt the user for a source file name, open and read the file, then write the list of tokens to the screen and to an output file. The tokens must be in a suitable representation. Students must handle lexical errors and print error messages. The programming language is strictly C. A report explaining the analysis phase and describing all tokens is required, along with sample output and source code. The deadline is April 28 with a 20% late penalty for each extra day. Four sample code segments in FORTRAN are provided.

Uploaded by

Al Oy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Project 1 Text

The document provides instructions for an assignment to write a lexical analyzer for FORTRAN 77. Students are asked to prompt the user for a source file name, open and read the file, then write the list of tokens to the screen and to an output file. The tokens must be in a suitable representation. Students must handle lexical errors and print error messages. The programming language is strictly C. A report explaining the analysis phase and describing all tokens is required, along with sample output and source code. The deadline is April 28 with a 20% late penalty for each extra day. Four sample code segments in FORTRAN are provided.

Uploaded by

Al Oy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Languages 2014 spring assignment 1

Due: 28 April 2014


Teaching Assistants:
Oylum Alatl ([email protected])
Bekir Afar ([email protected])
Erkan Yaar ([email protected])
Task: Write a lexical analyzer for FORTRAN 77.
Input: Prompt for the source file name. Get the source file name from the user. If the name is
x for example, open and read the source file x.for
Output: Write the list of tokens in a suitable representation, on screen and also into an output
file (x.lex). Catch all the necessary lexical analyzer errors and print suitable error messages.
Language: C (strictly)
Performance: The types of tokens covered by sample codes are adequate.
Deliver: Report explaining the analysis phase and making a detailed description of all the
tokens, also containing the printout of source code and test output samples. Submit your
executable (.exe) under the homework topic present at the moodle site of the course.
Late delivery: Iteratively %20 punishment for each extra day.
Sample Codes:
1-

PROGRAM MAIN
INTEGER N, X
EXTERNAL SUB1
COMMON /GLOBALS/ N
X = 0
PRINT *, 'Enter number of repeats'
READ (*,*) N
CALL SUB1(X,SUB1)
END
SUBROUTINE SUB1(X,DUMSUB)
INTEGER N, X, Y
EXTERNAL DUMSUB
COMMON /GLOBALS/ N
DATA Y /0/
IF(X .LT. N)THEN
X = X + 1
Y = Y + 1
PRINT *, 'x = ', X, ', y = ', Y
CALL DUMSUB(X,DUMSUB)
END IF
END

2PROGRAM MAIN
INTEGER I, I_START, I_END, I_INC
REAL A(100)
I_START = 1
I_END = 100
I_INC = 1
DO I = I_START, I_END, I_INC
A(I) = 0.0E0
END DO
END
3C
C NUMERICAL MATHEMATICS AND COMPUTING, CHENEY/KINCAID, (c) 1985
C
C FILE: first.f
C
C FIRST PROGRAMMING EXPERIMENT
C
DATA N/25/, H/1.0/, X/0.5/
F = SIN(X)
G = COS(X)
DO 2 I = 1,N
H = 0.25*H
D = SIN(X + H) - F
Q = D/H
E = ABS(G - Q)
PRINT *,H,D,Q,E
2 CONTINUE
STOP
END
4C
C NUMERICAL MATHEMATICS AND COMPUTING, CHENEY/KINCAID, (c) 1985
C
C FILE: xsinx.f
C
C EXAMPLE OF PROGRAMMING F(X) = X - SIN(X) CAREFULLY (F)
C
DOUBLE PRECISION DX,DY,DZ
DX = 1.0D0/15.0D0
DY = DSIN(DX)
DZ = DX - DY
PRINT *,DX,DY,DZ
X = 16.0
DO 2 N = 1,52
X = 0.25*X
Y = F(X)
PRINT *,N,X,Y
2 CONTINUE
X = SIN(1.0)
Y = F(1.0)
PRINT *,X,Y

STOP
END

FUNCTION F(X)
IF(ABS(X) .GE. 1.9) THEN
F = X - SIN(X)
ELSE
T = X**3/6.0
F = T
DO 2 N = 1,9
T = -T*X*X/REAL((2*N+2)*(2*N+3))
F = F + T
CONTINUE
END IF
RETURN
END

You might also like