The first step in understanding how Takmela works! The next step is 1+2+3
Grammar
// The 'arithmetic' example, with shorter names
// to make graph labels clear in visualization
e : e '+' t
| t ;
t :
NUM
;
NUM: [0-9]+;
WS skip: [ \r\n\t]*;
Input
1+2
Trace appears confusing? This might help
| Call start nonterminal | |||
![]() |
#0: Called e/0 at the top level (will process)
Processing e/0 codePos e → • e `+` t inputPos 0
Calling: e/0 with Cont e/0 ; e → e• `+` t [already processed]
Processing e/0 codePos e → • t inputPos 0
Calling: t/0 with Cont e/0 ; e → t• [will process]
Processing t/0 codePos t → • NUM inputPos 0
Match NUM to 1, matched; inputPos now 1
Reached end of rule, success! t/0 → 1
e/0 → e/0 ; e → e• `+` t ; e
t/0 → e/0 ; e → t• ; e
|
||
t/0 → 1, t('1')
| |||
| Iteration 0 | |||
| |||
![]() |
#1: JoinS: t/0 → 1 will resume cont: e/0 ; e → t•
Processing e/0 codePos e → t• inputPos 1
Reached end of rule, success! e/0 → 1
|
||
t/0 → 1, t('1')
e/0 → 1, e(t('1'))
| |||
| Iteration 1 | |||
| |||
![]() |
#2: JoinS: e/0 → 1 will resume cont: Root/0 ; Root → e•
×Didn't reach end of input, not a successful parse
t/0 → 1, t('1')
e/0 → 1, e(t('1'))
| ||
![]() |
#3: JoinS: e/0 → 1 will resume cont: e/0 ; e → e• `+` t
Processing e/0 codePos e → e• `+` t inputPos 1
Match + to +, matched; inputPos now 2
Calling: t/2 with Cont e/0 ; e → e `+` t• [will process]
Processing t/2 codePos t → • NUM inputPos 2
Match NUM to 2, matched; inputPos now 3
Reached end of rule, success! t/2 → 3
t/2 → e/0 ; e → e `+` t• ; e(e(t('1')), '+')
|
||
t/0 → 1, t('1')
e/0 → 1, e(t('1'))
t/2 → 3, t('2')
| |||
| Iteration 2 | |||
| |||
![]() |
#4: JoinS: t/2 → 3 will resume cont: e/0 ; e → e `+` t•
Processing e/0 codePos e → e `+` t• inputPos 3
Reached end of rule, success! e/0 → 3
|
||
t/0 → 1, t('1')
e/0 → 1, e(t('1'))
t/2 → 3, t('2')
e/0 → 3, e(e(t('1')),'+',t('2'))
| |||
| Iteration 3 | |||
| |||
![]() |
#5: JoinS: e/0 → 3 will resume cont: Root/0 ; Root → e•
✓Reached end of input, successful parse!
t/0 → 1, t('1')
e/0 → 1, e(t('1'))
t/2 → 3, t('2')
e/0 → 3, e(e(t('1')),'+',t('2'))
Root/0 → 3, Root(e(e(t('1')),'+',t('2')))✓
| ||
![]() |
#6: JoinS: e/0 → 3 will resume cont: e/0 ; e → e• `+` t
Processing e/0 codePos e → e• `+` t inputPos 3
Match `+` to (eof), fail
|
||
t/0 → 1, t('1')
e/0 → 1, e(t('1'))
t/2 → 3, t('2')
e/0 → 3, e(e(t('1')),'+',t('2'))
Root/0 → 3, Root(e(e(t('1')),'+',t('2')))✓
| |||
| Iteration 4 | |||
| |||
| (No new calls or successes that can be further processed) | |||
| Iteration 5 [Fixed point reached] | |||