编译原理之不带回溯的递归子程序

文法G1:
S -> a | ∩ | (T)
T -> T , S | S

(1) 消去G1的左递归。
S -> a | ∩ | (T)
T -> ST’
T -> ,ST’ | ε

(2)写出不带回溯的递归子程序

PROCEDURE S;
BEGIN 
    IF SYM = 'a' OR SYM = '∩' 
    THEN 
    BEGIN
        ADVANCE; 
    END
    ELSE IF SYM = '('
    THEN 
    BEGIN
        ADVANCE; 
        T;
        IF SYM = ')' THEN ADVANCE
        ELSE ERROR
    END
END

PROCEDURE T;
BEGIN
    S;T'
END

PROCEDURE T';
BEGIN
    IF SYM = ',' THEN
    BEGIN
        ADVANCE;
        S;T'
    END
END 

你可能感兴趣的:(编译原理)