Moved all programs in fort to a new folder, finished program2

This commit is contained in:
Mariano Uvalle 2019-05-04 23:01:29 -05:00
parent c7d211f0b5
commit 6a305f83c7
17 changed files with 2060 additions and 1844 deletions

View file

@ -108,6 +108,7 @@ tokens = [
'openParen',
'closedParen',
'string',
'comment',
'plus',
'minus',
'mul',
@ -169,6 +170,7 @@ t_plus = r'\+'
t_minus = r'-'
t_mul = r'\*'
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_and = r'\.and\.'
t_not = r'\.not\.'
@ -286,7 +288,8 @@ def p_S(p):
| do id action_24 equals EA action_25 coma EA action_26 IntOrEmpty then B action_29 end do
| do then action_21 B action_22 end do
| swap Dimensional coma Dimensional
| exit action_23
| exit action_23
| comment
'''
# 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

View 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

View 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

View file

@ -7,89 +7,89 @@ print '2 - Calculate a number to the power of another number'
print endline
print '3 - Calculate e to the power of a number'
print endline
read $50
== $50 1 $0
read $200
== $200 1 $0
gotoF $0 29
print 'Enter the number'
print endline
read $52
= 1 $51
= 1 $54
<= $54 $52 $0
read $202
= 1 $201
= 1 $204
<= $204 $202 $0
gotoF $0 25
* $51 $54 $1
= $1 $51
+ $54 1 $1
= $1 $54
* $201 $204 $1
= $1 $201
+ $204 1 $1
= $1 $204
goto 18
print 'The result is : '
print $51
print $201
print endline
goto 89
== $50 2 $1
== $200 2 $1
gotoF $1 50
print 'Enter the base'
print endline
read $52
read $202
print 'Enter the exponent'
print endline
read $53
= 1 $51
= 1 $54
<= $54 $53 $1
read $203
= 1 $201
= 1 $204
<= $204 $203 $1
gotoF $1 46
* $51 $52 $2
= $2 $51
+ $54 1 $2
= $2 $54
* $201 $202 $2
= $2 $201
+ $204 1 $2
= $2 $204
goto 39
print 'The result is : '
print $51
print $201
print endline
goto 89
== $50 3 $2
== $200 3 $2
gotoF $2 87
print 'Enter the exponent'
print endline
read $52
= 0 $51
= 0 $54
<= $54 10 $2
read $202
= 0 $201
= 0 $204
<= $204 10 $2
gotoF $2 83
= 1 $56
= 1 $55
<= $55 $54 $3
= 1 $206
= 1 $205
<= $205 $204 $3
gotoF $3 68
* $56 $55 $4
= $4 $56
+ $55 1 $4
= $4 $55
* $206 $205 $4
= $4 $206
+ $205 1 $4
= $4 $205
goto 61
= 1 $57
= 1 $55
<= $55 $54 $4
= 1 $207
= 1 $205
<= $205 $204 $4
gotoF $4 77
* $57 $52 $5
= $5 $57
+ $55 1 $5
= $5 $55
* $207 $202 $5
= $5 $207
+ $205 1 $5
= $5 $205
goto 70
/ $57 $56 $5
+ $51 $5 $6
= $6 $51
+ $54 1 $6
= $6 $54
/ $207 $206 $5
+ $201 $5 $6
= $6 $201
+ $204 1 $6
= $6 $204
goto 57
print 'The result is : '
print $51
print $201
print endline
goto 89
print 'Not a valid option'
print endline
print 'Would you like to make another calculation? (type 1 for yes or 0 for no)'
print endline
read $50
== $50 0 $6
read $200
== $200 0 $6
gotoF $6 95
goto 96
goto 2

View file

@ -1,44 +1,44 @@
goto 2
= 1 $150
= 2 $151
* $150 10 $0
= 1 $300
= 2 $301
* $300 10 $0
+ 0 $0 $0
+ 50 $0 $0
+ 200 $0 $0
= 1 *0
* $151 10 $0
* $301 10 $0
+ 0 $0 $0
+ 50 $0 $0
+ 200 $0 $0
= 2 *0
print 'a(i) = '
* $150 10 $0
* $300 10 $0
+ 0 $0 $0
+ 50 $0 $0
+ 200 $0 $0
print *0
print endline
print 'a(j) = '
* $151 10 $0
* $301 10 $0
+ 0 $0 $0
+ 50 $0 $0
+ 200 $0 $0
print *0
print endline
* $150 10 $0
* $300 10 $0
+ 0 $0 $0
+ 50 $0 $0
* $151 10 $1
+ 200 $0 $0
* $301 10 $1
+ 0 $1 $1
+ 50 $1 $1
* $150 10 $2
+ 200 $1 $1
* $300 10 $2
+ 0 $2 $2
+ 50 $2 $2
+ 200 $2 $2
+ *1 *2 $3
= $3 *0
print 'a(i) = '
* $150 10 $0
* $300 10 $0
+ 0 $0 $0
+ 50 $0 $0
+ 200 $0 $0
print *0
print endline
+ $151 2 $0
= $0 $150
print $150
+ $301 2 $0
= $0 $300
print $300
print endline