e.g.
Code: Select all
MODULE ObxTest;
IMPORT Log := StdLog;
PROCEDURE Do* ();
VAR str: ARRAY 12 OF CHAR;
BEGIN
str := "hello5";
CASE str OF
| "hello", "hello2", 'book':
Log.String('world'); Log.Ln;
| "world":
Log.String('hello'); Log.Ln;
(*ELSE*)
END;
END Do;
END ObxTest.
Code: Select all
PROCEDURE (scanner: Scanner) GetAttributes (IN str: ARRAY OF CHAR):
TextModels.Attributes, NEW;
VAR a: TextModels.Attributes;
BEGIN
a := scanner.syntax.Ident;
IF (str$ = "PROCEDURE") THEN
a := scanner.syntax.KeyWord;
state := regular;
(* интерпретировать звездочку как маркер экспорта *)
stateExport := exportCare;
ELSIF (str$ = "VAR") OR (str$ = "TYPE") OR (str$ = "CONST")THEN
a := scanner.syntax.KeyWord;
state := regular;
(* интерпретировать звездочку как маркер экспорта *)
stateExport := exportCare;
ELSIF(str$ = "BEGIN")THEN
a := scanner.syntax.KeyWord;
state := regular;
stateExport := regular;
ELSIF(str$ = "END")THEN
a := scanner.syntax.KeyWord;
IF state = declare THEN
stateExport := exportCare;
ELSE
state := regular;
END;
ELSIF
(str$ = "MODULE")
OR (str$ = "DEFINITION") OR (str$ = "IMPORT")
OR (str$ = "CLOSE") OR (str$ = "ARRAY")
OR (str$ = "IF") OR (str$ = "THEN")
OR (str$ = "ELSIF") OR (str$ = "ELSE") OR (str$ = "REPEAT")
OR (str$ = "UNTIL") OR (str$ = "WHILE") OR (str$ = "DO")
OR (str$ = "LOOP") OR (str$ = "FOR") OR (str$ = "TO") OR (str$ = "BY")
OR (str$ = "POINTER") OR (str$ = "OF") OR (str$ = "CASE")
OR (str$ = "WITH") OR (str$ = "MENU") OR (str$ = "SEPARATOR")
THEN
a := scanner.syntax.KeyWord;
state := regular;
ELSIF (str$ = "RECORD")
THEN
a := scanner.syntax.KeyWord;
state := regular;
IF stateExport = declare THEN
(* разблокируем для выделения жирным идентификаторов в полях записей *)
stateExport := exportCare
END
ELSIF (str$ = "RETURN") OR (str$ = "EXIT") OR (str$ = "HALT")
OR (str$ = "ASSERT")
THEN
a := scanner.syntax.Exit;
state := regular;
ELSIF (str$ = "BYTE") OR (str$ = "CARDINAL") OR (str$ = "CHAR")
OR (str$ = "INTEGER") OR (str$ = "LONGCARD") OR (str$ = "LONGINT")
OR (str$ = "REAL") OR (str$ = "BOOLEAN") OR (str$ = "SET") OR (str$ = "STRING")
OR (str$ = "SHORTCARD") OR (str$ = "SHORTCHAR") OR (str$ = "SHORTINT")
OR (str$ = "SHORTREAL") OR (str$ = "LONGREAL") OR (str$ = "HUGEINT")
OR (str$ = "LONGSET") OR (str$ = "ANYPTR") OR (str$ = "ANYREC")
THEN
a := scanner.syntax.PrimeType;
state := regular;
ELSIF (state = systemDot) & ((str$ = "ADR") OR (str$ = "LSH")
OR (str$ = "ROT") OR (str$ = "TYP") OR (str$ = "VAL") OR (str$ = "GET")
OR (str$ = "PUT") OR (str$ = "MOVE")
OR (str$ = "SIZE") OR (str$ = "BIT") OR (str$ = "COPY")) (* O7 *)
THEN
a := scanner.syntax.SystemMod;
state := regular;
ELSIF (str$ = "OR") OR (str$ = "DIV") OR (str$ = "MOD") OR (str$ = "DIV0")
OR (str$ = "REM0") OR (str$ = "ORD") OR (str$ = "CHR") OR (str$ = "ODD")
OR (str$ = "MAX") OR (str$ = "MIN") OR (str$ = "INC") OR (str$ = "DEC")
OR (str$ = "INCL") OR (str$ = "EXCL") OR (str$ = "LEN") OR (str$ = "ABS")
OR (str$ = "BITS") OR (str$ = "SHORT") OR (str$ = "SIZE") OR (str$ = "LONG")
OR (str$ = "ENTIER") OR (str$ = "CAP") OR (str$ = "ASH") OR (str$ = "IS")
OR (str$ = "IN") OR (str$ = "OUT") OR (str$ = "COPY") OR (str$ = "FLOOR")
OR (str$ = "FLT") OR (str$ = "ASR") OR (str$ = "LSL") OR (str$ = "ROR")
THEN
a := scanner.syntax.Oper;
state := regular;
ELSIF (str$ = "NEW") OR (str$ = "FINALIZE") OR (str$ = "ABSTRACT")
OR (str$ = "EXTENSIBLE") OR (str$ = "LIMITED") OR (str$ = "EMPTY") OR (str$ = "DISPOSE")
THEN
a := scanner.syntax.New;
state := regular;
ELSIF (str$ = "NIL") OR (str$ = "TRUE") OR (str$ = "FALSE")
OR (str$ = "INF")
THEN
a := scanner.syntax.Const;
state := regular;
ELSIF (str$ = "SYSTEM") THEN
a := scanner.syntax.SystemMod;
state := system; (* после SYSTEM чувствуем SIZE иначе *)
END;
RETURN a;
END GetAttributes;
many modern languages have the syntax of "case/switch string" , but CP not;
I have done a simple patch for this syntax,but not sure our community like it or not.
wellcome someone who interesting it to test and improve it;
luowy