Next: , Up: Assembler Program Structure   [Contents][Index]


Look-ahead Analysis Sub-block

A look-ahead analysis sub-block provides branching based on a look-ahead terminal symbol. The sub-block has the following general structure:

        ; Look-ahead terminal symbol analysis, where blockIdx is the index
        ; of this look-ahead analysis sub-block in an assembler program. In
        ; labels tblockIdx_termIdxI, ‘t’ means "terminal".

        peek    ORD                           ; Set the outcome equal to
                                              ; the identifier of a
                                              ; look-ahead terminal symbol

        joe     termIdx1, tblockIdx_termIdx1  ; Terminal symbol id termIdx1
        ...
        joe     termIdxN, tblockIdx_termIdxN  ; Terminal symbol id termIdxN

        abrt                                  ; Unexpected terminal symbol

        ; Branching for a look-ahead terminal symbol with id termIdx1,
        ; where probEq1 is equal to 1.0/n1.

tblockIdx_termIdx1:
        choice
        case    probEq1, branch1_1
        ...
        case    probEq1, branch1_n1-1
        end     choice

        jmp     branch1_n1

        ...

        ; Branching for a look-ahead terminal symbol with id termIdxN,
        ; where probEqN is equal to 1.0/nN.

tblockIdx_termIdxN:
        choice
        case    probEqN, branchN_1
        ...
        case    probEqN, branchN_nN-1
        end     choice

        jmp     branchN_nN

If a set of expected look-ahead terminal symbols is equal to a set of all possible terminal symbols, the abrt instruction is unnecessary. In this case, the following instruction replaces that abrt instruction:

        jmp     tblockIdx_termIdxN+1  ; Terminal symbol id termIdxN+1

For only two possible branches, a branching sub-block looks like this:

tblockIdx_termIdxI:
        jprob   0.5, branchI_1
        jmp     branchI_2

For only one possible branch, a joe instruction transfers control to that branch directly:

        joe     termIdxI, branchI     ; Terminal symbol id termIdxI

Below there is an example look-ahead analysis sub-block for the expression ‘"a"|["a" "b"]|["a" "b" "c"]’, where the set of all possible terminal symbols is { ‘a’, ‘b’, ‘c’ }.

        ; FIRST: [ "a" "b" "c" ]
        peek    0
        joe     0, t1_0 ; "a"
        joe     1, t1_1 ; "b"
        jmp     a3      ; "c"
t1_0:
        ; "a"
        choice
        case    3.333333333333333E-01, a1
        case    3.333333333333333E-01, a2
        end     choice
        jmp     a3
t1_1:
        ; "b"
        jprob   0.5, a2
        jmp     a3

Next: , Up: Assembler Program Structure   [Contents][Index]