-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Kumir lang support #4477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Kumir lang support #4477
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,143 @@ | ||||||||||||||||||||||
// KumirLexer.g4 | ||||||||||||||||||||||
// ANTLR v4 Lexer Grammar for the Kumir language. | ||||||||||||||||||||||
// Source: Refined based on official documentation and extensive testing | ||||||||||||||||||||||
// against K.Y. Polyakov's examples. Developed collaboratively. | ||||||||||||||||||||||
// Author: [Your Name/GitHub Handle] | ||||||||||||||||||||||
// License: MIT License | ||||||||||||||||||||||
|
||||||||||||||||||||||
lexer grammar KumirLexer; | ||||||||||||||||||||||
|
||||||||||||||||||||||
options { caseInsensitive = true; } | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Keywords (Core Language) --- | ||||||||||||||||||||||
// Keywords are case-insensitive (both lowercase and uppercase Cyrillic are matched). | ||||||||||||||||||||||
MODULE : 'модуль'; | ||||||||||||||||||||||
ENDMODULE : ('конец' WS 'модуля' | 'конецмодуля' | 'конец_модуля'); | ||||||||||||||||||||||
ALG_HEADER : 'алг'; | ||||||||||||||||||||||
ALG_BEGIN : 'нач'; | ||||||||||||||||||||||
ALG_END : 'кон'; | ||||||||||||||||||||||
PRE_CONDITION : 'дано'; | ||||||||||||||||||||||
POST_CONDITION : 'надо'; | ||||||||||||||||||||||
ASSERTION : 'утв'; | ||||||||||||||||||||||
LOOP : 'нц'; | ||||||||||||||||||||||
ENDLOOP_COND : ('кц' WS 'при' | 'кц_при'); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
ENDLOOP : 'кц'; | ||||||||||||||||||||||
IF : 'если'; | ||||||||||||||||||||||
THEN : 'то'; | ||||||||||||||||||||||
ELSE : 'иначе'; | ||||||||||||||||||||||
FI : 'все'; | ||||||||||||||||||||||
SWITCH : 'выбор'; | ||||||||||||||||||||||
CASE : 'при'; | ||||||||||||||||||||||
INPUT : 'ввод'; | ||||||||||||||||||||||
OUTPUT : 'вывод'; | ||||||||||||||||||||||
ASSIGN : ':='; | ||||||||||||||||||||||
EXIT : 'выход'; | ||||||||||||||||||||||
PAUSE : 'пауза'; | ||||||||||||||||||||||
STOP : 'стоп'; | ||||||||||||||||||||||
IMPORT : 'использовать'; | ||||||||||||||||||||||
FOR : 'для'; | ||||||||||||||||||||||
WHILE : 'пока'; | ||||||||||||||||||||||
TIMES : 'раз'; | ||||||||||||||||||||||
FROM : 'от'; | ||||||||||||||||||||||
TO : 'до'; | ||||||||||||||||||||||
STEP : 'шаг'; | ||||||||||||||||||||||
NEWLINE_CONST : 'нс'; | ||||||||||||||||||||||
NOT : 'не'; | ||||||||||||||||||||||
AND : 'и'; | ||||||||||||||||||||||
OR : 'или'; | ||||||||||||||||||||||
OUT_PARAM : 'рез'; | ||||||||||||||||||||||
IN_PARAM : 'арг'; | ||||||||||||||||||||||
INOUT_PARAM : ('аргрез' | 'арг' WS 'рез' | 'арг_рез'); | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
RETURN_VALUE : 'знач'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Data Types --- | ||||||||||||||||||||||
INTEGER_TYPE : 'цел'; | ||||||||||||||||||||||
REAL_TYPE : 'вещ'; | ||||||||||||||||||||||
BOOLEAN_TYPE : 'лог'; | ||||||||||||||||||||||
CHAR_TYPE : 'сим'; | ||||||||||||||||||||||
STRING_TYPE : 'лит'; | ||||||||||||||||||||||
TABLE_SUFFIX : 'таб'; | ||||||||||||||||||||||
// Actor-specific types | ||||||||||||||||||||||
KOMPL_TYPE : 'компл'; | ||||||||||||||||||||||
COLOR_TYPE : 'цвет'; | ||||||||||||||||||||||
SCANCODE_TYPE : 'сканкод'; | ||||||||||||||||||||||
FILE_TYPE : 'файл'; | ||||||||||||||||||||||
// Explicit array/table types (handle variations with space, no space, underscore) | ||||||||||||||||||||||
INTEGER_ARRAY_TYPE : ('цел' WS? 'таб' | 'цел_таб'); | ||||||||||||||||||||||
REAL_ARRAY_TYPE : ('вещ' WS? 'таб' | 'вещ_таб'); | ||||||||||||||||||||||
CHAR_ARRAY_TYPE : ('сим' WS? 'таб' | 'сим_таб'); | ||||||||||||||||||||||
STRING_ARRAY_TYPE : ('лит' WS? 'таб' | 'лит_таб'); | ||||||||||||||||||||||
BOOLEAN_ARRAY_TYPE : ('лог' WS? 'таб' | 'лог_таб'); | ||||||||||||||||||||||
Comment on lines
+66
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Constants --- | ||||||||||||||||||||||
TRUE : 'да'; | ||||||||||||||||||||||
FALSE : 'нет'; | ||||||||||||||||||||||
// Color constants | ||||||||||||||||||||||
PROZRACHNIY : 'прозрачный'; | ||||||||||||||||||||||
BELIY : 'белый'; | ||||||||||||||||||||||
CHERNIY : 'чёрный' | 'черный'; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
SERIY : 'серый'; | ||||||||||||||||||||||
FIOLETOVIY : 'фиолетовый'; | ||||||||||||||||||||||
SINIY : 'синий'; | ||||||||||||||||||||||
GOLUBOY : 'голубой'; | ||||||||||||||||||||||
ZELENIY : 'зелёный' | 'зеленый'; | ||||||||||||||||||||||
ZHELTIY : 'жёлтый' | 'желтый'; | ||||||||||||||||||||||
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
ORANZHEVIY : 'оранжевый'; | ||||||||||||||||||||||
KRASNIY : 'красный'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Operators --- | ||||||||||||||||||||||
POWER : '**'; | ||||||||||||||||||||||
GE : '>=' | '≥'; | ||||||||||||||||||||||
LE : '<=' | '≤'; | ||||||||||||||||||||||
NE : '<>' | '≠'; | ||||||||||||||||||||||
PLUS : '+'; | ||||||||||||||||||||||
MINUS : '-'; | ||||||||||||||||||||||
MUL : '*'; | ||||||||||||||||||||||
DIV : '/'; | ||||||||||||||||||||||
EQ : '='; | ||||||||||||||||||||||
LT : '<'; | ||||||||||||||||||||||
GT : '>'; | ||||||||||||||||||||||
LPAREN : '('; | ||||||||||||||||||||||
RPAREN : ')'; | ||||||||||||||||||||||
LBRACK : '['; | ||||||||||||||||||||||
RBRACK : ']'; | ||||||||||||||||||||||
LBRACE : '{'; | ||||||||||||||||||||||
RBRACE : '}'; | ||||||||||||||||||||||
COMMA : ','; | ||||||||||||||||||||||
COLON : ':'; | ||||||||||||||||||||||
SEMICOLON : ';'; | ||||||||||||||||||||||
ATAT : '@@'; | ||||||||||||||||||||||
AT : '@'; | ||||||||||||||||||||||
DIV_OP : 'div'; | ||||||||||||||||||||||
MOD_OP : 'mod'; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Literals --- | ||||||||||||||||||||||
CHAR_LITERAL : '\'' ( EscapeSequence | ~['\\\r\n] ) '\'' ; | ||||||||||||||||||||||
STRING : '"' ( EscapeSequence | ~["\\\r\n] )*? '"' | ||||||||||||||||||||||
| '\'' ( EscapeSequence | ~['\\\r\n] )*? '\'' | ||||||||||||||||||||||
; | ||||||||||||||||||||||
REAL : (DIGIT+ '.' DIGIT* | '.' DIGIT+) ExpFragment? | ||||||||||||||||||||||
| DIGIT+ ExpFragment | ||||||||||||||||||||||
; | ||||||||||||||||||||||
INTEGER : DecInteger | HexInteger ; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Identifier --- | ||||||||||||||||||||||
ID : LETTER (LETTER | DIGIT | '_' | '@')* ; | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Comments --- | ||||||||||||||||||||||
LINE_COMMENT : '|' ~[\r\n]* -> channel(HIDDEN); | ||||||||||||||||||||||
DOC_COMMENT : '#' ~[\r\n]* -> channel(HIDDEN); | ||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Whitespace --- | ||||||||||||||||||||||
WS : [ \t\r\n]+ -> skip; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the previously introduced
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
// --- Fragments --- | ||||||||||||||||||||||
fragment DIGIT : [0-9]; | ||||||||||||||||||||||
fragment HEX_DIGIT : [0-9a-fA-F]; | ||||||||||||||||||||||
fragment LETTER : [a-zA-Zа-яА-ЯёЁ]; | ||||||||||||||||||||||
Comment on lines
+135
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The UPPER case is not needed since the grammar sets up
Suggested change
|
||||||||||||||||||||||
fragment DecInteger : DIGIT+; | ||||||||||||||||||||||
fragment HexInteger : '$' HEX_DIGIT+; | ||||||||||||||||||||||
fragment ExpFragment: [eE] [+-]? DIGIT+; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
fragment EscapeSequence | ||||||||||||||||||||||
: '\\' [btnfr"'\\] | ||||||||||||||||||||||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend simplifying: