프로그래밍언어론 2023-04-18 수업정리

Flow

Extended BNF


optional Elements

Alternative Elements

Sequence of Elements

Syntax Chart


Pascal if-then-else Railroad Diagram

Pascal Railroad Diagram

<if else then> := 'if' <boolean expression> 'then' <compound> 
					( <else if> | <else> ) 'end'

Recursive-Descent Parser


Recursive-Descent Parser

Transform Grammar to Recursive-Descent Parser

#include <stdio.h>
 
int LA;
int yylex() {
    return getchar();
}
 
void match(int t) {
    if(LA == t) LA = yylex();
    else fprintf(stderr, "Syntax Error\n");
}
 
int S() {
    if(LA == '(') {
        match('(');
        S();
        match(')');
        S();
    }
    else
    ;
}
 
int L() {
    S(); match('\n');
}
 
int A() {
    if(LA == EOF)
    ;
    else {
        L(); A();
    }
}
 
int main() {
    LA = yylex();
    A();
    return 0;
}