-
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
Open
Bormotoon
wants to merge
5
commits into
antlr:master
Choose a base branch
from
Bormotoon:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Kumir lang support #4477
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
657d280
Kumir lang support
Bormotoon 66566da
Updated according to recommendations; examples from the textbook have…
Bormotoon 10cfb4a
Another update with some fixes from recommendations
Bormotoon 354c096
Some fixes as suggested.
68bf09e
Fixed stuff that copilot found
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| // 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_FRAGMENT | '_') 'исп' | ||
| | 'конец' (WS_FRAGMENT | '_')? 'модуля' | ||
| ; | ||
| ALG_HEADER : 'алг'; | ||
| ALG_BEGIN : 'нач'; | ||
| ALG_END : 'кон'; | ||
| PRE_CONDITION : 'дано'; | ||
| POST_CONDITION : 'надо'; | ||
| ASSERTION : 'утв'; | ||
| LOOP : 'нц'; | ||
| ENDLOOP_COND : 'кц' (WS_FRAGMENT | '_')? 'при'; | ||
| 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_FRAGMENT | '_')? 'рез'; | ||
| 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_FRAGMENT | '_')? 'таб'; | ||
| REAL_ARRAY_TYPE : 'вещ' (WS_FRAGMENT | '_')? 'таб'; | ||
| CHAR_ARRAY_TYPE : 'сим' (WS_FRAGMENT | '_')? 'таб'; | ||
| STRING_ARRAY_TYPE : 'лит' (WS_FRAGMENT | '_')? 'таб'; | ||
| BOOLEAN_ARRAY_TYPE : 'лог' (WS_FRAGMENT | '_')? 'таб'; | ||
|
|
||
| // --- Constants --- | ||
| TRUE : 'да'; | ||
| FALSE : 'нет'; | ||
| // Color constants | ||
| PROZRACHNIY : 'прозрачный'; | ||
| BELIY : 'белый'; | ||
| CHERNIY : 'ч' E_OR_YO 'рный'; | ||
| SERIY : 'серый'; | ||
| FIOLETOVIY : 'фиолетовый'; | ||
| SINIY : 'синий'; | ||
| GOLUBOY : 'голубой'; | ||
| ZELENIY : 'зел' E_OR_YO 'ный'; | ||
| ZHELTIY : 'ж' E_OR_YO 'лтый'; | ||
| 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'; | ||
|
Bormotoon marked this conversation as resolved.
Outdated
|
||
|
|
||
| // --- 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 : WS_FRAGMENT+ -> skip; | ||
|
|
||
| // --- Fragments --- | ||
| fragment WS_FRAGMENT: [ \t\r\n]+; | ||
| fragment E_OR_YO : 'ё' | 'е'; | ||
| fragment DIGIT : [0-9]; | ||
| fragment HEX_DIGIT : [0-9a-f]; | ||
| fragment LETTER : [a-zа-яё]; | ||
| fragment DecInteger : DIGIT+; | ||
| fragment HexInteger : '$' HEX_DIGIT+; | ||
| fragment ExpFragment: [e] [+-]? DIGIT+; | ||
| fragment EscapeSequence | ||
| : '\\' [btnfr"'\\] | ||
| ; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.