Moved all programs in fort to a new folder, finished program2
This commit is contained in:
parent
c7d211f0b5
commit
6a305f83c7
17 changed files with 2060 additions and 1844 deletions
|
|
@ -108,6 +108,7 @@ tokens = [
|
||||||
'openParen',
|
'openParen',
|
||||||
'closedParen',
|
'closedParen',
|
||||||
'string',
|
'string',
|
||||||
|
'comment',
|
||||||
'plus',
|
'plus',
|
||||||
'minus',
|
'minus',
|
||||||
'mul',
|
'mul',
|
||||||
|
|
@ -169,6 +170,7 @@ t_plus = r'\+'
|
||||||
t_minus = r'-'
|
t_minus = r'-'
|
||||||
t_mul = r'\*'
|
t_mul = r'\*'
|
||||||
t_string = r'\'[a-zA-Z0-9 \?\:\t\r\n\f()\[\]\&\!\@\#\$\%\^\-\=\+\/\,]*\''
|
t_string = r'\'[a-zA-Z0-9 \?\:\t\r\n\f()\[\]\&\!\@\#\$\%\^\-\=\+\/\,]*\''
|
||||||
|
t_comment = r'![a-zA-Z0-9 \?\:\t\r\n\f()\[\]\&\!\@\#\$\%\^\-\=\+\/\,]*!'
|
||||||
t_or = r'\.or\.'
|
t_or = r'\.or\.'
|
||||||
t_and = r'\.and\.'
|
t_and = r'\.and\.'
|
||||||
t_not = r'\.not\.'
|
t_not = r'\.not\.'
|
||||||
|
|
@ -287,6 +289,7 @@ def p_S(p):
|
||||||
| do then action_21 B action_22 end do
|
| do then action_21 B action_22 end do
|
||||||
| swap Dimensional coma Dimensional
|
| swap Dimensional coma Dimensional
|
||||||
| exit action_23
|
| exit action_23
|
||||||
|
| comment
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Adjust the action to support matrices
|
# Adjust the action to support matrices
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
42
final_lang/programas/programa2.fort
Normal file
42
final_lang/programas/programa2.fort
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
program p2
|
||||||
|
integer [10] :: vec
|
||||||
|
integer :: i, j, size, temp
|
||||||
|
subroutine readVec
|
||||||
|
do i = 0, size - 1 then
|
||||||
|
print 'Enter element ', i, ' of the vector', endline
|
||||||
|
read vec(i)
|
||||||
|
end do
|
||||||
|
end subroutine
|
||||||
|
subroutine printVec
|
||||||
|
do i = 0, size - 1 then
|
||||||
|
print vec(i), ' '
|
||||||
|
end do
|
||||||
|
print endline
|
||||||
|
end subroutine
|
||||||
|
subroutine readDim
|
||||||
|
do then
|
||||||
|
print 'Enter the size of the vector to sort', endline
|
||||||
|
read size
|
||||||
|
if (size <= 10 .and. size > 0) then
|
||||||
|
exit
|
||||||
|
end if
|
||||||
|
print 'The size of the vector must be greater than 0 and less than or equal to 10', endline
|
||||||
|
end do
|
||||||
|
end subroutine
|
||||||
|
subroutine sort
|
||||||
|
do i = 0, size - 2 then
|
||||||
|
do j = 0, size - i - 2 then
|
||||||
|
if (vec(j) > vec(j + 1)) then
|
||||||
|
temp = vec(j)
|
||||||
|
vec(j) = vec(j+1)
|
||||||
|
vec(j+1) = temp
|
||||||
|
end if
|
||||||
|
end do
|
||||||
|
end do
|
||||||
|
end subroutine
|
||||||
|
readDim()
|
||||||
|
readVec()
|
||||||
|
sort()
|
||||||
|
print 'Sorted vector: '
|
||||||
|
printVec()
|
||||||
|
end program
|
||||||
74
final_lang/programas/programa2.fort.out
Normal file
74
final_lang/programas/programa2.fort.out
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
goto 70
|
||||||
|
= 0 $210
|
||||||
|
- $212 1 $0
|
||||||
|
<= $210 $0 $1
|
||||||
|
gotoF $1 15
|
||||||
|
print 'Enter element '
|
||||||
|
print $210
|
||||||
|
print ' of the vector'
|
||||||
|
print endline
|
||||||
|
+ 200 $210 $2
|
||||||
|
read *2
|
||||||
|
+ $210 1 $3
|
||||||
|
= $3 $210
|
||||||
|
goto 4
|
||||||
|
goback
|
||||||
|
= 0 $210
|
||||||
|
- $212 1 $3
|
||||||
|
<= $210 $3 $4
|
||||||
|
gotoF $4 26
|
||||||
|
+ 200 $210 $5
|
||||||
|
print *5
|
||||||
|
print ' '
|
||||||
|
+ $210 1 $5
|
||||||
|
= $5 $210
|
||||||
|
goto 18
|
||||||
|
print endline
|
||||||
|
goback
|
||||||
|
print 'Enter the size of the vector to sort'
|
||||||
|
print endline
|
||||||
|
read $212
|
||||||
|
<= $212 10 $5
|
||||||
|
> $212 0 $6
|
||||||
|
.and. $5 $6 $7
|
||||||
|
gotoF $7 36
|
||||||
|
goto 39
|
||||||
|
print 'The size of the vector must be greater than 0 and less than or equal to 10'
|
||||||
|
print endline
|
||||||
|
goto 28
|
||||||
|
goback
|
||||||
|
= 0 $210
|
||||||
|
- $212 2 $7
|
||||||
|
<= $210 $7 $5
|
||||||
|
gotoF $5 69
|
||||||
|
= 0 $211
|
||||||
|
- $212 $210 $6
|
||||||
|
- $6 2 $8
|
||||||
|
<= $211 $8 $6
|
||||||
|
gotoF $6 66
|
||||||
|
+ 200 $211 $9
|
||||||
|
+ $211 1 $10
|
||||||
|
+ 200 $10 $11
|
||||||
|
> *9 *11 $12
|
||||||
|
gotoF $12 63
|
||||||
|
+ 200 $211 $12
|
||||||
|
= *12 $213
|
||||||
|
+ 200 $211 $12
|
||||||
|
+ $211 1 $9
|
||||||
|
+ 200 $9 $11
|
||||||
|
= *11 *12
|
||||||
|
+ $211 1 $12
|
||||||
|
+ 200 $12 $11
|
||||||
|
= $213 *11
|
||||||
|
+ $211 1 $11
|
||||||
|
= $11 $211
|
||||||
|
goto 47
|
||||||
|
+ $210 1 $11
|
||||||
|
= $11 $210
|
||||||
|
goto 42
|
||||||
|
goback
|
||||||
|
call 28
|
||||||
|
call 2
|
||||||
|
call 40
|
||||||
|
print 'Sorted vector: '
|
||||||
|
call 16
|
||||||
|
|
@ -7,89 +7,89 @@ print '2 - Calculate a number to the power of another number'
|
||||||
print endline
|
print endline
|
||||||
print '3 - Calculate e to the power of a number'
|
print '3 - Calculate e to the power of a number'
|
||||||
print endline
|
print endline
|
||||||
read $50
|
read $200
|
||||||
== $50 1 $0
|
== $200 1 $0
|
||||||
gotoF $0 29
|
gotoF $0 29
|
||||||
print 'Enter the number'
|
print 'Enter the number'
|
||||||
print endline
|
print endline
|
||||||
read $52
|
read $202
|
||||||
= 1 $51
|
= 1 $201
|
||||||
= 1 $54
|
= 1 $204
|
||||||
<= $54 $52 $0
|
<= $204 $202 $0
|
||||||
gotoF $0 25
|
gotoF $0 25
|
||||||
* $51 $54 $1
|
* $201 $204 $1
|
||||||
= $1 $51
|
= $1 $201
|
||||||
+ $54 1 $1
|
+ $204 1 $1
|
||||||
= $1 $54
|
= $1 $204
|
||||||
goto 18
|
goto 18
|
||||||
print 'The result is : '
|
print 'The result is : '
|
||||||
print $51
|
print $201
|
||||||
print endline
|
print endline
|
||||||
goto 89
|
goto 89
|
||||||
== $50 2 $1
|
== $200 2 $1
|
||||||
gotoF $1 50
|
gotoF $1 50
|
||||||
print 'Enter the base'
|
print 'Enter the base'
|
||||||
print endline
|
print endline
|
||||||
read $52
|
read $202
|
||||||
print 'Enter the exponent'
|
print 'Enter the exponent'
|
||||||
print endline
|
print endline
|
||||||
read $53
|
read $203
|
||||||
= 1 $51
|
= 1 $201
|
||||||
= 1 $54
|
= 1 $204
|
||||||
<= $54 $53 $1
|
<= $204 $203 $1
|
||||||
gotoF $1 46
|
gotoF $1 46
|
||||||
* $51 $52 $2
|
* $201 $202 $2
|
||||||
= $2 $51
|
= $2 $201
|
||||||
+ $54 1 $2
|
+ $204 1 $2
|
||||||
= $2 $54
|
= $2 $204
|
||||||
goto 39
|
goto 39
|
||||||
print 'The result is : '
|
print 'The result is : '
|
||||||
print $51
|
print $201
|
||||||
print endline
|
print endline
|
||||||
goto 89
|
goto 89
|
||||||
== $50 3 $2
|
== $200 3 $2
|
||||||
gotoF $2 87
|
gotoF $2 87
|
||||||
print 'Enter the exponent'
|
print 'Enter the exponent'
|
||||||
print endline
|
print endline
|
||||||
read $52
|
read $202
|
||||||
= 0 $51
|
= 0 $201
|
||||||
= 0 $54
|
= 0 $204
|
||||||
<= $54 10 $2
|
<= $204 10 $2
|
||||||
gotoF $2 83
|
gotoF $2 83
|
||||||
= 1 $56
|
= 1 $206
|
||||||
= 1 $55
|
= 1 $205
|
||||||
<= $55 $54 $3
|
<= $205 $204 $3
|
||||||
gotoF $3 68
|
gotoF $3 68
|
||||||
* $56 $55 $4
|
* $206 $205 $4
|
||||||
= $4 $56
|
= $4 $206
|
||||||
+ $55 1 $4
|
+ $205 1 $4
|
||||||
= $4 $55
|
= $4 $205
|
||||||
goto 61
|
goto 61
|
||||||
= 1 $57
|
= 1 $207
|
||||||
= 1 $55
|
= 1 $205
|
||||||
<= $55 $54 $4
|
<= $205 $204 $4
|
||||||
gotoF $4 77
|
gotoF $4 77
|
||||||
* $57 $52 $5
|
* $207 $202 $5
|
||||||
= $5 $57
|
= $5 $207
|
||||||
+ $55 1 $5
|
+ $205 1 $5
|
||||||
= $5 $55
|
= $5 $205
|
||||||
goto 70
|
goto 70
|
||||||
/ $57 $56 $5
|
/ $207 $206 $5
|
||||||
+ $51 $5 $6
|
+ $201 $5 $6
|
||||||
= $6 $51
|
= $6 $201
|
||||||
+ $54 1 $6
|
+ $204 1 $6
|
||||||
= $6 $54
|
= $6 $204
|
||||||
goto 57
|
goto 57
|
||||||
print 'The result is : '
|
print 'The result is : '
|
||||||
print $51
|
print $201
|
||||||
print endline
|
print endline
|
||||||
goto 89
|
goto 89
|
||||||
print 'Not a valid option'
|
print 'Not a valid option'
|
||||||
print endline
|
print endline
|
||||||
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)'
|
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)'
|
||||||
print endline
|
print endline
|
||||||
read $50
|
read $200
|
||||||
== $50 0 $6
|
== $200 0 $6
|
||||||
gotoF $6 95
|
gotoF $6 95
|
||||||
goto 96
|
goto 96
|
||||||
goto 2
|
goto 2
|
||||||
|
|
@ -1,44 +1,44 @@
|
||||||
goto 2
|
goto 2
|
||||||
= 1 $150
|
= 1 $300
|
||||||
= 2 $151
|
= 2 $301
|
||||||
* $150 10 $0
|
* $300 10 $0
|
||||||
+ 0 $0 $0
|
+ 0 $0 $0
|
||||||
+ 50 $0 $0
|
+ 200 $0 $0
|
||||||
= 1 *0
|
= 1 *0
|
||||||
* $151 10 $0
|
* $301 10 $0
|
||||||
+ 0 $0 $0
|
+ 0 $0 $0
|
||||||
+ 50 $0 $0
|
+ 200 $0 $0
|
||||||
= 2 *0
|
= 2 *0
|
||||||
print 'a(i) = '
|
print 'a(i) = '
|
||||||
* $150 10 $0
|
* $300 10 $0
|
||||||
+ 0 $0 $0
|
+ 0 $0 $0
|
||||||
+ 50 $0 $0
|
+ 200 $0 $0
|
||||||
print *0
|
print *0
|
||||||
print endline
|
print endline
|
||||||
print 'a(j) = '
|
print 'a(j) = '
|
||||||
* $151 10 $0
|
* $301 10 $0
|
||||||
+ 0 $0 $0
|
+ 0 $0 $0
|
||||||
+ 50 $0 $0
|
+ 200 $0 $0
|
||||||
print *0
|
print *0
|
||||||
print endline
|
print endline
|
||||||
* $150 10 $0
|
* $300 10 $0
|
||||||
+ 0 $0 $0
|
+ 0 $0 $0
|
||||||
+ 50 $0 $0
|
+ 200 $0 $0
|
||||||
* $151 10 $1
|
* $301 10 $1
|
||||||
+ 0 $1 $1
|
+ 0 $1 $1
|
||||||
+ 50 $1 $1
|
+ 200 $1 $1
|
||||||
* $150 10 $2
|
* $300 10 $2
|
||||||
+ 0 $2 $2
|
+ 0 $2 $2
|
||||||
+ 50 $2 $2
|
+ 200 $2 $2
|
||||||
+ *1 *2 $3
|
+ *1 *2 $3
|
||||||
= $3 *0
|
= $3 *0
|
||||||
print 'a(i) = '
|
print 'a(i) = '
|
||||||
* $150 10 $0
|
* $300 10 $0
|
||||||
+ 0 $0 $0
|
+ 0 $0 $0
|
||||||
+ 50 $0 $0
|
+ 200 $0 $0
|
||||||
print *0
|
print *0
|
||||||
print endline
|
print endline
|
||||||
+ $151 2 $0
|
+ $301 2 $0
|
||||||
= $0 $150
|
= $0 $300
|
||||||
print $150
|
print $300
|
||||||
print endline
|
print endline
|
||||||
Loading…
Add table
Add a link
Reference in a new issue