-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBASIC_IO.mch
107 lines (97 loc) · 3.55 KB
/
BASIC_IO.mch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/******************************* CLEARSY *************************************
* File : $Id: $
* (C) 1998 CLEARSY
*
* Description : BASIC_IO : definition of input and output functions
*
*
* History : $Log: $
*
******************************************************************************/
MACHINE
BASIC_IO
DEFINITIONS
CHAR == 0..255
OPERATIONS
/*----------------------------------------------------------------------**
INTERVAL_READ: input of a number in (mm..nn). The cursor reappears at
current position, the operator has to enter the number followed
by Return, with no other character before. Characters after the number
are ignored. As long as the number is inconsistent, the error message
"THIS IS NOT A VALUE IN mm..nn" is displayed and a new input is required.
**----------------------------------------------------------------------*/
bb <-- INTERVAL_READ(mm,nn) = PRE
nn: NAT &
mm: NAT &
mm<=nn
THEN
bb:: mm..nn
END;
/*----------------------------------------------------------------------**
INT_WRITE: write a number into stdout, with no carriage return
**----------------------------------------------------------------------*/
INT_WRITE(vv) = PRE
vv: NAT
THEN
skip
END;
/*----------------------------------------------------------------------**
BOOL_READ: input of TRUE or FALSE. The cursor reappears at current
position, the operator has to enter TRUE or FALSE in plain characters.
As long as the input is inconsistent, the error message
"THIS IS NOT A BOOLEAN VALUE, TYPE TRUE OR FALSE" is displayed and a new
input is required.
**----------------------------------------------------------------------*/
bb <-- BOOL_READ = BEGIN
bb:: BOOL
END;
/*----------------------------------------------------------------------**
BOOL_WRITE: write TRUE or FALSE in plain characters into stdout, with no
carriage return
**----------------------------------------------------------------------*/
BOOL_WRITE(bb) = PRE
bb: BOOL
THEN
skip
END;
/*----------------------------------------------------------------------**
CHAR_READ: input characters by the operator. The first call to CHAR_READ
makes the cursor reappear at the current position, the operator types
some characters followed by carriage return. Then CHAR_READ returns the
first input character; the next calls will return the following
characters, till the carriage return character included. The next call to
CHAR_READ will lead to another input.
**----------------------------------------------------------------------*/
cc <-- CHAR_READ = BEGIN
cc:: CHAR
END;
/*----------------------------------------------------------------------**
BOOL_WRITE: write a character into stdout.
WARNING: do not use characters between quotes. For instance:
. CHAR_WRITE('n') is meaningless.
NB: CHAR_WRITE(10) is used to print a carriage return.
**----------------------------------------------------------------------*/
CHAR_WRITE(cc) = PRE
cc: CHAR
THEN
skip
END;
/*----------------------------------------------------------------------**
STRING_WRITE: write a string into stdout.
Strings between double quotes are part of the B syntax, with the following
conventions:
. \n = carriage return
. \t = TAB
. \B = bell
. \E = escape
. \" = "
. \\ = \
Example: STRING_WRITE("\tHello\n")
NB: STRING_WRITE can only be used with a literal parameter.
**----------------------------------------------------------------------*/
STRING_WRITE(ss) = PRE
ss: STRING
THEN
skip
END
END