aboutsummaryrefslogtreecommitdiff
path: root/plugin/examples/highlighting.cps
blob: 10d93d81eb07429c161d9716f43b6619f6b9d51c (plain)
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

// Open in a dark theme; keywords are uppercase and comments ignore [(
TYPE Season = (Spring, Summer, Autumn, Winter)
TYPE IntPointer = ^INTEGER
TYPE Student
	DECLARE Name : STRING
	DECLARE Initial : CHAR
ENDTYPE

CONSTANT Limit = 3

DECLARE Values : ARRAY[1:3] OF INTEGER
DECLARE Index : INTEGER
DECLARE Total : REAL
DECLARE Ready : BOOLEAN
DECLARE Text : STRING
DECLARE Letter : CHAR
Ready <- TRUE AND NOT FALSE
Total <- -3.5 + 2 * 4 / 2
Text <- "CIE // [()]" & " pseudocode"
Letter <- '\''
Text <- "Quote: \"; slash: \\; byte: \x41; Unicode: \u0042"
DECLARE RawText : C_STRING
RawText <- "Native text"C

FOR Index <- 1 TO 3 STEP 1
	Values[Index] <- Index MOD 2
NEXT Index
IF Ready OR Total >= 1 THEN
	OUTPUT MID(Text, 1, LENGTH(Text))
ELSE
	OUTPUT "Try again"
ENDIF

FUNCTION Double(Value : INTEGER) RETURNS INTEGER
	RETURN Value * 2
ENDFUNCTION
PROCEDURE Swap(BYREF X : INTEGER, Y : INTEGER)
	DECLARE Temp : INTEGER
	Temp <- X
	X <- Y
	Y <- Temp
ENDPROCEDURE

OPENFILE "example.txt" FOR WRITE
WRITEFILE "example.txt", Text
CLOSEFILE "example.txt"

TRY
	THROW
CATCH
	OUTPUT "Caught an exception"
ENDTRY

CASE OF Index
	1 : OUTPUT "First"
	2 TO Limit : OUTPUT "In range"
	OTHERWISE : OUTPUT "Other"
ENDCASE

TEMPLATE <T>
FUNCTION _echo(Value : T) RETURNS T
	RETURN Value
ENDFUNCTION
OUTPUT _echo<INTEGER>(Limit)

CLASS Counter
	PRIVATE Value : INTEGER
	PUBLIC PROCEDURE Add(Amount : INTEGER)
		this.Value <- this.Value + Amount
	ENDPROCEDURE
	PUBLIC FUNCTION Get() RETURNS INTEGER
		RETURN this.Value
	ENDFUNCTION
ENDCLASS
DECLARE Count : Counter
CALL Count.Add(Limit)
OUTPUT Count.Get()