What does Syntax mean?

unevenoliveΛογισμικό & κατασκευή λογ/κού

1 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

75 εμφανίσεις

Turing


Turing

is a
programming language

developed in
1982

by
Ric Holt

and
James Cordy
.


At that time they
both
attended the

University of
Toronto
,
Canada
.

The
Turing
Program
was
n
amed after British
computer scientist
Alan Turing
, Turing is used
primarily as a teaching language at the high
sc
hool and university level.

1939
-
40:
Designed “
The Bombe

, machine for
Enigma
code
decryption

1939
-
42: Breaking of
German
U
-
boat Enigma

code
,
helping to save

battle of the Atlantic


What does Syntax mean?

Syntax
refers to the spelling and grammar of a
prog
ramming language. Computers are inflexible
machines that understand what you type only if
you type it in the exact form that the computer
expects. The expected form is called the syntax.




What is a Keyword?

A Keyword is a word that is easy for humans to
understand. Its use in programming is to make
coding a program more user friendly. Keywords
are words that the programming language
(Turing) understands as a command to follow
different procedures. Like a dog jumps because
it’s master tells it to jump e
ven though it has no
understanding of the English language.

Although there are many different recognized

keywords (words that the
Turing
program
understands as an operation)

the 3 main
keywords we will be working with are
:


parallelput


Delay


getch






p
arallelput


parallelput is the keyword that the Turing
program understands as a command to place

Positive 5 Volts on the Data Ports of the
computers Parallel Port.


There are 8 Data Ports on the parallel port of a
computer

D0, D1, D2, D3, D4, D5, D6 and D
7. As
a computer works with digit logic each port is
represented by a different eight digit Binary
Number which is referred to as a Bite of
information. Their respective numbers are:


Port

Binary Number

Decimal
Number

D0

00000001

1

D1

0000001
0

2

D2

00
0001
00

4

D3

00001
000

8

D4

0001
0000

16

D5

001
00000

32

D6

01
000000

64

D7

1
0000000

128





The proper Syntax for using the parallelput
keyword would be:


parallelput (1)

this command would have
the comp
uter provide 5Volts
to Data

Port D0


parallelput
(15)

this command
when
converted to
an 8 bit data
word (Binary)
would

be
represented by the number
00001111.

This command
would

have the computer
provide
5 Vo
lts to ports D0,
D1, D2 and
D3
output



parallelput (0)

this command when
converted to
an 8 bit da
ta
word (Binary)
would be
represented by the nu
mber
00000000. This command
would have the computer
provide 0Volts to all
port
(noth
ing
turned on)






d
elay


First it must be noted that Turing is a language
that works on lines of code placed one after the
other. The program reads the first line of code
and does as it is told. Once the tasks related to
that line of code is completed it moves on to the
next line of code immediately, hence the need
for the keyword
d
elay.


d
elay
is a keyword that the program
understands
as a pause before it moves on to the next line of
code


T
he proper Syntax for using the d
elay keyword
is:


Delay (1
000)

this would tell the program
to wait 1 second before
moving to the next line of
code
. In T
uring a second is
broken up
into 1
000 units


You can see the importance of this if you think
about how a
LED or motor

would be kept on for
a
n

exact
amount

of time
.



How

you could use the keywords parallelput and
d
elay together would be:


parallelput (0)

%make sure there is no
voltage on t
he parallel port

parallelput (1)


%provides 5 Volts to D0

Delay (1000)

%wait 1 second before
reading next line

parallelput (0)


%remove power from all
Data Ports



If you had a LED connected to D0 you can see
the above simple program would
make sure the
LE
D is off before the program runs then it would
turn the LED on for 1 second and finally
turn the
LED off.













getch


getch is a keyword that the program
understands as get a character (keyboard key).

For the getch keyword to work it has to know
wha
t part of the keyboard it is working with.
You can have it work with specific characters or
you can have the pressing of any character (key)
work with it.


For getch to work the key that is going to be

used must be


declared


(
in other words the
program m
ust

to be told you will be using this
particular key in the program
)
.


This is

done at the beginning of your program
and is called Declaring a Variable










The Syntax to declare a variable is


v
ar key
:
string

(1)


%This line tells the program
that th
e keyword
key
is a
variable so
if any key is
pressed do as the line of
code requires


How the getch command can be used is as
followed:


var key
:
string

(1)


%declare key as a
variable



parallelput (0)

%make sure there is no
voltage on the parallel
port

parallelput (1)



%provides 5 Volts to D0

getch (key)

%wait until any key is
pressed before reading
next line

parallelput (0)

%remove power from all
Data Ports


If you had a LED connected to D0 you can see
the above simple program would make sure the
LED i
s off before the program runs then it would
turn the LED on until a key on the keyboard is
pressed and finally turn the LED off.


Just for interest sakes if you input a line of code
in Turing like the following it will output to the
screen

(Computer Monito
r)


put “Hello”

Once you have inputted your code in the Turing
program you must
click on Run from the top
menu for Turing

to run the program.


If for some reason it does not like the syntax of a
particular line of code it will stop running the
program and
return to the programming window.
There will be a Text box telling you that the
program found an error. If it finds more than 1
error the message will look like:


3

errors found



At this time a line will be highlighted in grey.
The program is telling yo
u that
Turing

has a
problem understanding this particular line
.

(Syntax error)