-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* migrate to antlr4 * apply ide suggestions * Refactor * Introduce BstVM, wip * read, entry, sort wip * functions visitor * bstEntryContext * function, identifier, stackitem, exception * reorder * execute, iterate, reverse * removed old vm, prepared test architecture * fixed parser * fixed stringscommand * fixed macrocommand * fixed functioncommand * added exception handling for functions * testVisitEntryCommand * testVisitReadCommand * reorder and cleanup * testdata cleanup * fix function call * fixed call.type * wip if * wip if * addedTests * finally fixed if * wip tests * stylistic issues * Reworded * Improved error logging * Fix error msg * wip * Fixed tests * Fixed tests * Removed TestVM * Added reverse test * Added visitStackitem test * Added bbl tests * clean up Co-authored-by: Oliver Kopp <kopp.dev@gmail.com>
- Loading branch information
Showing
35 changed files
with
2,971 additions
and
2,698 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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,85 @@ | ||
grammar Bst; | ||
|
||
// Lexer | ||
|
||
STRINGS : 'STRINGS'; | ||
INTEGERS : 'INTEGERS'; | ||
FUNCTION : 'FUNCTION'; | ||
EXECUTE : 'EXECUTE'; | ||
SORT : 'SORT'; | ||
ITERATE : 'ITERATE'; | ||
REVERSE : 'REVERSE'; | ||
ENTRY : 'ENTRY'; | ||
READ : 'READ'; | ||
MACRO : 'MACRO'; | ||
|
||
GT : '>'; | ||
LT : '<'; | ||
EQUAL : '='; | ||
ASSIGN : ':='; | ||
ADD : '+'; | ||
SUB : '-'; | ||
CONCAT : '*'; | ||
LBRACE : '{'; | ||
RBRACE : '}'; | ||
|
||
fragment LETTER : ('a'..'z'|'A'..'Z'|'.'|'$'); | ||
fragment NUMERAL : ('0'..'9'); | ||
|
||
IDENTIFIER : LETTER (LETTER|NUMERAL|'_')*; | ||
INTEGER : '#' ('+'|'-')? NUMERAL+; | ||
QUOTED : '\'' IDENTIFIER; | ||
STRING : '"' (~('"'))* '"'; | ||
|
||
WS: [ \r\n\t]+ -> skip; | ||
LINE_COMMENT : '%' ~('\n'|'\r')* '\r'? '\n' -> skip; | ||
|
||
// Parser | ||
|
||
bstFile | ||
: commands+ EOF | ||
; | ||
|
||
commands | ||
: STRINGS ids=idListObl #stringsCommand | ||
| INTEGERS ids=idListObl #integersCommand | ||
| FUNCTION LBRACE id=identifier RBRACE function=stack #functionCommand | ||
| MACRO LBRACE id=identifier RBRACE LBRACE repl=STRING RBRACE #macroCommand | ||
| READ #readCommand | ||
| EXECUTE LBRACE bstFunction RBRACE #executeCommand | ||
| ITERATE LBRACE bstFunction RBRACE #iterateCommand | ||
| REVERSE LBRACE bstFunction RBRACE #reverseCommand | ||
| ENTRY idListOpt idListOpt idListOpt #entryCommand | ||
| SORT #sortCommand | ||
; | ||
|
||
identifier | ||
: IDENTIFIER | ||
; | ||
|
||
// Obligatory identifier list | ||
idListObl | ||
: LBRACE identifier+ RBRACE | ||
; | ||
|
||
// Optional identifier list | ||
idListOpt | ||
: LBRACE identifier* RBRACE | ||
; | ||
|
||
bstFunction | ||
: LT | GT | EQUAL | ADD | SUB | ASSIGN | CONCAT | ||
| identifier | ||
; | ||
|
||
stack | ||
: LBRACE stackitem+ RBRACE | ||
; | ||
|
||
stackitem | ||
: bstFunction | ||
| STRING | ||
| INTEGER | ||
| QUOTED | ||
| stack | ||
; |
This file contains 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
Oops, something went wrong.