Skip to content

Commit

Permalink
Lexing iban (#125)
Browse files Browse the repository at this point in the history
* Lecture: add IBAN challenge (lexing)

* fix typo
  • Loading branch information
cagix committed Nov 6, 2023
1 parent 0e5638e commit d609986
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lecture/frontend/lexing/antlr-lexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ challenges: |
Können Sie die Grammatik so anpassen, dass Sie nur möglichst wenige verschiedene Token an den Parser weitergeben?
Ergänzen Sie Ihre Grammatik um Lexer-Aktionen, so dass Sie die Zeilen, die Zeichen (in den Namen) und die Ziffern (in den Telefonnummern) zählen können.
**Lexing mit ANTLR**
IBAN für Deutschland bestehen aus dem Kürzel "DE" sowie einer zweistelligen Checksumme, gefolgt von 2x 4 Ziffern für die
Bank (ehemalige Bankleitzahl) sowie 2x 4 Ziffern für die ehemalige Kontonummer sowie zwei weiteren Ziffern. Typisch sind
zwei Formate:
- Menschenlesbares Format: `DEcc bbbb bbbb kkkk kkkk xx`
- Maschinenlesbares Format: `DEccbbbbbbbbkkkkkkkkxx`
Definieren Sie eine Lexer-Grammatik für ANTLR, mit der Sie die verschiedenen IBAN-Formate für Deutschland einlesen können.
---


Expand Down
22 changes: 22 additions & 0 deletions lecture/frontend/lexing/src/Iban.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
grammar Iban;

/*
DEcc bbbb bbbb kkkk kkkk xx
DEccbbbbbbbbkkkkkkkkxx
DE12 3456 7890 1234 5678 42
DE12345678901234567842
*/

iban: COUNTRY QUARTET QUARTET QUARTET QUARTET CHECK ;

COUNTRY: 'DE' CHECK ;
CHECK: DIGIT DIGIT ;
QUARTET: DIGIT DIGIT DIGIT DIGIT ;

fragment
DIGIT: [0-9] ;


ID: [a-zA-Z] ;
WS: [\t\r\n ]+ -> skip ;

0 comments on commit d609986

Please sign in to comment.