G?a - PowerPoint PPT Presentation

About This Presentation
Title:

G?a

Description:

v v ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 122
Provided by: GOS56
Category:
Tags: lpar

less

Transcript and Presenter's Notes

Title: G?a


1
G?aµµat???? ?
2
G?aµµat???? ??
3
G?aµµat???? ???
4
G?aµµat???? ?V
5
G?aµµat???? V
6
G?aµµat???? ?a? s??ta?t??? a????s? ?
?st?, ? ??aµµat??? ????? s?µf?a??µe?a
G(?,?,S,R), ?p?? ?NUMBER,,-,,/,(,) N
E SE µe ?a???e? pa?a????? E ? EE
(1) E-E (2) EE (3) E/E
(4) (E) (5) NUMBER (6)
7
G?aµµat???? ?a? s??ta?t??? a????s? ??
? pa?ap??? ??aµµat??? µp??e? ?a a?a??se? t??
pa??stas? (37)/(8-6). ???ta ???s?µ?p??e? t??
?a???a pa?a????? (4) ?a? s??µat??e? t?
d??d?? ?et? s??µat??e? t? a??ste?? ?a? t?
de?? ?p?d??d?? ???s?µ?p????ta? t?? ?a???a
pa?a????? (5)
8
G?aµµat???? ?a? s??ta?t??? a????s? ???

? a????s? s??e???e? µe ta f???a ? sta d??
?p?d??d?a. ?? ? st? a??ste?? ?p?d??d?? a?a??eta?
µe t?? ?a???a pa?a????? (1) ?a? t? ? st? de??
?p?d??d?? a?a??eta? µe t?? ?a???a pa?a????? (2).
9
G?aµµat???? ?a? s??ta?t??? a????s? ?V
  ????? ??a ta f???a ? a?a????ta? µe t?? ?a???a
pa?a????? (6).
10
G?aµµat???? ?a? s??ta?t??? a????s? V
11
G?aµµat???? ?a? s??ta?t??? a????s? VI
?? ap?t??esµa t?? a????s?? e??a? ??a pa??????
d??d??. ?ta? ? a????s? p??????e? p??ta p??ta µe
t? s??µat?sµ? t?? a??ste??? ?p?d??d???, t?te
??µe ?t? ? a????s? s??µat??e? a??ste???
p??tas?a??? µ??f??.
  • ??µe ?t? ? s?µί???se??? e??a? µ?a a??ste??
    p??tas?a?? µ??f?, a? ??e? p?????e? ap? t??
    p??????µe?e?, efa?µ????ta? ???e f??? pa?a????,
    p?? a?t??a??st? t? p??t? µ? te?µat??? s?µί??? ap?
    a??ste??. ??t? ???feta? ??,
  • ??a s?µί???se??? e??a? de??? p??tas?a?? µ??f?,
    a? ??e? p?????e? efa?µ????ta? ???e f??? pa?a????,
    p?? a?t??a??st? t? p??t? µ? te?µat??? s?µί??? ap?
    de???. ??t? ???feta? ??

12
G?aµµat???? ?a? s??ta?t??? a????s? VII
  • ??µe ?t? µ?a ??aµµat??? e??a? ??aµµat??? LL(k) a?
    ???e t?? p??tas? µp??e? ?a p?????e? ap? t?? a???
    t?? µ?s? a??ste??? p??tas?a??? µ??f??, ?p?? ?
    ?a???a? p?? efa?µ??eta? se ???e pa?a???? µp??e?
    ?a p??ί?ef?e? µe ί?s? ta k ep?µe?a s?µί??a t??
    s?µί???se????.
  • ??e? ?? ???sse? t?? ???????e?a? LL e??a?
    p??sd????st????.
  • ??a ??aµµat??? e??a? ??aµµat??? LR(k) a? ???e t??
    p??tas? µp??e? ?a pa?a??e? ap? t?? a??? t?? µ?s?
    de???? p??tas?a??? µ??f??, p?? p????pt??? µe
    efa?µ??? ?a???a ? ?p???? µp??e? ?a a????e??e? µe
    ί?s? ta k p??ta te?µat??? s?µί??a t?? p??tas?a???
    µ??f??.
  • ??e? ?? ???sse? t?? ???????e?a? LR e??a?
    p??sd????st????.
  • ? ???????e?a t?? ???ss?? LR(1) e??a? a???ί?? ?
    ???????e?a t?? p??sd????st???? ???ss?? ?a? e??a?
    e???te?? ap? t?? ???????e?a t?? ???ss?? LL.

13
S?µί???sµ?? BNF ?a? EBNF I

14
S?µί???sµ?? BNF ?a? EBNF II
  • ???????G?? G?aµµat??? a???µ?t???? e?f??se??
  • S ??f?as?.
  • ??f?as? ??f?as? ???? ??f?as? - ????
    ????.
  • ???? ???? pa?????ta? ???? / pa?????ta?
    pa?????ta?.
  • pa?????ta? ( ??f?as? ) a???µ??.
  • a???µ?? ??f?? ??f?? .
  • ??f?? 0 1 2 3 4 5 6
    7 8 9.

15
?a?????a ?a? s??ta?t??? d??d?a I
  • ??a pa?????? d??d?? a?apa??st? t? d?µ? µ?a?
    p??tas?? ?a? ??e? t? ?a?a?t???st??? ?t? µp??e? ?a
    a?t?st???e? se pe??ss?te?e? ap? µ?a pa?a?????.
  • ???????G??
  • S ??f?as?.
  • ??f?as? ??f?as? ?? ??f?as? ( ??f?as? )
    a???µ??.
  • ?? - /.
  • ?????S? (27-5)8

16
?a?????a ?a? s??ta?t??? d??d?a II
  • ?a?a???? µ?s? de???? p??tas?a??? µ??f??
  • ?a?a???? µ?s? a??ste??? p??tas?a??? µ??f??

17
?a?????a ?a? s??ta?t??? d??d?a II?

18
?a?????a ?a? s??ta?t??? d??d?a IV
  • S??ta?t??? d??d?? p?? s?µpa??? d?µ? p??
    pa??????a pe????e? ?a? t?? p????f???a ??a t?
    stat??? s?µas?a t?? p??tas??

19
G?aµµat???? µe as?fe?e? ?
  • ??µe ?t? µ?a ??aµµat??? pe????e? as?fe?e?, ?ta?
    se µ?a p??tas? t?? µp??e? ?a a?t?st??????
    pe??ss?te?a ap? ??a d??d?a.
  • ?S?F??? ?????????????S ????S?O?
  • S ??f?as?.
  • ??f?as? ??f?as? ?? ??f?as? ( ??f?as? )
    a???µ??.
  • ?? - /.
  • ?????S? 27-58

20
G?aµµat???? µe as?fe?e? ??

21
G?aµµat???? µe as?fe?e? ???

22
G?aµµat???? µe as?fe?e? ?V
  • S?st? d??d?? e??a? t? d??d?? e?e??? p?? e??a?
    s?µίat? µe t? s?µas?a p?? ???e? ?a ap?d?se? ?
    ?atas?e?ast?? se ???e st???e?? t?? ???ssa?.
  • G?a t?? as?fe?a p??te?a??t?ta? te?est??
    apa?te?ta? ? ???s? ?a????? ap?saf???s??
    p??te?a??t?t??.
  • S ??f?as?.
  • ??f?as? ??f?as? ??_?T ??f?as? ????.
  • ??_?T -.
  • ???? ???? ??_G? ???? pa?????ta?.
  • ??_G? /.
  • pa?????ta? ( ??f?as? ) a???µ??.

23
G?aµµat???? µe as?fe?e? V
  • ? p??????µe?? ??aµµat??? pa?aµ??e? d?sµ?a
    as?fe?a? ?? p??? t?? p??seta???st???t?ta t??
    p???e?? p?? ???eta? ? a????s? t?? 27-5-8 ?
    s???e???µ??? ??aµµat??? af??e? a????t? ?a? t?
    e?de??µe?? (27-5)-8 a??? ?a? t? e?de??µe??
    27-(5-8).
  • S?????? µa? e?d?af??e? ?a d?asfa?????µe a??ste??
    p??seta???st???t?ta ?a? a?t? ep?t?????eta? a? ?
    a?t?st????? ?a???a? t?? ??aµµat????
    ?a?a?t????eta? ap? a??ste?? ?a? µ??? a??ste??
    a?ad??µ???t?ta.

24
G?aµµat???? µe as?fe?e? V?
  • ??????µ??? ??aµµat??? S ??f?as?.
  • ??f?as? ??f?as? ??_?T ???? ????.
  • ??_?T -.
  • ???? ???? ??_G? pa?????ta? pa?????ta?.
  • ??_G? /.
  • pa?????ta? ( ??f?as? ) a???µ??.
  • ???tas? 27-58

25
G?aµµat???? µe as?fe?e? V??
  • ???tas? 27-5-8

26
G?aµµat???? µe as?fe?e? V??I
  • ?? ???????? ??? ????O??? ELSE
  • S e?t???.
  • e?t??? if ??f?as? then e?t???
  • if ??f?as? then e?t??? else e?t???
  • ????.
  • if EK1 then if EK2 then ???1 else ???2

27
G?aµµat???? µe as?fe?e? I?

28
G?aµµat???? µe as?fe?e? ?
  • G????????? ??? ???F??G?? ?? ???????? ??? ????O???
    ELSE ?? ?????S??
  • S e?t???.
  • e?t??? s??_e?t??? as??_e?t???.
  • s??_e?t???if ??f?as? then s??_e?t??? else
    s??_e?t???
  • ????.
  • as??_e?t??? if ??f?as? then e?t???
  • if ??f?as? then s??_e?t???
    else as??_e?t???.

29
??apa??stas? pa??????? d??d???
  • define astEmptyProgram 399
  • define astProgram 400
  • define astEmptyDeclSeq 401
  • define astDeclSeq 402
  • define astDecl 403
  • . . . . . . . . . . . . . .
  • / -----------------------------------------------
    ------------ /
  • / ----- THE STRUCTURE FOR THE ABSTRACT SYNTAX
    TREE NODES ---- /
  • / -----------------------------------------------
    ------------ /
  • typedef struct AstNode_tag
  • int NodeType
  • struct symbol_tag SymbolNode
  • struct AstNode_tag pAstNode4
  • AstNode

30
?a??d??? ?????s?
  • ?e???? ap? t? a??? t?? ??aµµat???? (???a d??d???)
    ??a ?a a?apt??e? t? s?µί???se???, p?? a?a??e?, a?
    a?t? ap?te?e? p??tas?.
  • ?aµ?a ap? t?? te?????? p?? ?a e?et?s??µe de?
    µp??e? ?a efa?µ?s?e? se a??ste?? a?ad??µ????
    ??aµµat????.
  • ??a??????µe t?? te?????? t?? ?p?s??d??µ?s?? ?a?
    t?? te?????? t?? p?????s??.

31
?a??d??? a????s? µe ?p?s??d??µ?s? ?
  • ?????t?? s???e???µ???? µ? te?µat???? s?µί????
    efa?µ??eta? ? p??t?? ?a???a? t?? ??aµµat????.
  • St?? p??tas?a?? µ??f?, p?? p????pte? ep????eta?
    t? p??t? ap? a??ste?? µ? te?µat??? s?µί??? ?a?
    efa?µ??eta? ? p??t?? ?a???a?, p?? a?af??eta? se
    a?t?.
  • G??eta? epa?a??pt??? efa?µ??? t?? ί?µat?? 2, ??a
    ???e ??a ap? ta µ? te?µat??? s?µί??a, p??
    a?????????, µ???? t? st??µ? t?? pa?a?????,
  • µ?a? se???? te?µat???? s?µί???? (p??tas? ???ssa?
    a? ta?t??eta?) ?
  • tµ?µat?? te?µat???? s?µί???? t?? p??tas?a???
    µ??f??, p?? d?af??e? ap? t? a?t?st???? tµ?µa t??
    s?µί???se???? e?s?d??
  • ? de?te?? pe??pt?s? µp??e? ?a e??a? ap?t??esµa
    esfa?µ???? ep?????? ?a???a. ??a??e?ta? ? ?a???a?
    p?? efa?µ?s???e te?e?ta??? ?a? ???s?µ?p??e?ta? ?
    ep?µe??? p?? ?s??e? ??a t? ?d?? µ? te?µat???
    s?µί???. ?? ????? ???s?µ?p????e? ???? ?? ?a???e?,
    t?te ? a??????µ?? d?at??e? t? s?µί??? ?? ??e? ?a?
    p?????? st?? a?a??es? t?? ?a???a ??a t?
    p??????µe?? µ? te?µat??? s?µί??? ?a? ?p?s??d??µe?
    st?? ?at?????? ??s? t?? s?µί???se???? e?s?d??.

32
?a??d??? a????s? µe ?p?s??d??µ?s? ??
  • ???????G??
  • S k X n k Y.
  • X l m.
  • Y mmn nnm. ?????S? kmmm

33
?a??d??? a????s? µe ?p?s??d??µ?s? ??I
  • ?d?a?te?a p???p????
  • ??? ap?d?t???
  • ???et? ?e????, d??. a?a??????e? p?? p?????
    ???sse? ap? t?? ???e? te?????? ?a??d???? a????s??
  • ???e? st?? e?t?p?sµ? t?? ?a??? ?a? ?ts? ? a??????
    ???eta? p??? d?s????

34
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ?
  • St?? a????s? a?ad??µ???? ?at?ίas?? ? ???e
    ?a???a?, p?? a?af??eta? se ??p??? µ? te?µat???
    s?µί???, e?f???eta? ap? t?? ???sµ? µ?a?
    d?ad??as?a?, p?? ?a t? a?a??????e?.
  • ??a? a?a??t?? p??ί??p??sa? a?ad??µ???? ?at?ίas??
    ap?te?e?ta?
  • ap? µ?a ?a?????? µetaί??t?, p?? pe????e? t??
    t?µ? t?? t?????sa? ?e????? µ???da?
  • ap? µ?a ί????t??? d?ad??as?a a?a?????s??, p??
    e????e? a? ? t?????sa ?e???? µ???da e??a? ?
    a?aµe??µe?? ?a? ?a?e? t? d?ad??as?a ?e?????
    a????s??, ??a t?? a?????s? t?? ep?µe??? ?e?????
    µ???da? ?a? t?? e??µ???s? t?? ?a???????
    µetaί??t??
  • ap? t?? d?ad??as?e? a????s??, p?? a?t?st??????
    sta µ? te?µat??? s?µί??a t?? ??aµµat????
  • ap? µ?a d?ad??as?a e?????s??, p?? af?? d?aί?se?
    t?? p??t? ?e???? µ???da ?a?e? t? d?ad??as?a, p??
    a?t?st???e? st? µ? te?µat??? s?µί??? t?? a????.

35
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ??
  • ???????G??
  • S ??f?as?.
  • ??f?as? ??f?as? ???? ??f?as? - ????
    ????.
  • ???? ???? pa?????ta? ???? / pa?????ta?
    pa?????ta?.
  • pa?????ta? ( ??f?as? ) a???µ??.

pa?????ta? ?p??e?e ???_??? pe??pt?s? ( a?a?????se (() ??f?as? a?a?????se ()) pe??pt?s? a???µ?? a?a?????se(a???µ??) a????? ????? ????? pa?????ta. //a?_?e?_µ?? a?aµe??µe?? ?e?. µ???da a?a?????se (a?_?e?_µ??) a? (???_???a?_?e?_µ??) t?te d??ίase t?? ep?µe?? µ???da ?a? e??µ???se t? µetaί??t? ???_??? a????? ????? t???? a? ????? a?a?????se.
36
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ??I
? p??ί??p??sa a?ad??µ??? ?at?ίas? st????eta? st??
p?????s? t?? ?at??????? ???e f??? ?a???a, p??
?d??e? st?? pa?a???? t?? d??d??? t?? p??tas??. ?e
µp??e? ?a efa?µ?s?e? se a??ste?? a?ad??µ????
??aµµat????, ?p?? a?t? t?? p??????µe???
pa?ade??µat??. ?? ?e???s??µe t? µ? a??ste??
a?ad??µ??? ??aµµat??? t?? a???µ?t????
e?f??se?? S ??f?as?. ??f?as? ????
?p_????. ?p_???? ???? ?p_???? - ????
?p_???? e. ???? pa?????ta? ?p_pa?a?. ?p_pa?a?
pa?????ta? ?p_pa?a? / pa?????ta?
?p_pa?a? e. pa?????ta? (??f?as? )
a???µ??.
37
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ?V
  • G?a t? µ? te?µat??? s?µί??? ??f?as?, µp??e?
    e?a??a?t??? ?a ????µe t?? pa?a????,
  • ??f?as? ? ???? ?p_???? ? pa?????ta? ?p_pa?a?
    ?p_???? ? (??f?as?) ?p_pa?a? ?p_???? . . . .
  • ? t?? pa?a????
  • ??f?as? ? ???? ?p_???? ? pa?????ta? ?p_pa?a?
    ?p_???? ? a???µ?? ?p_pa?a? ?p_???? . . . .
  • Ge????, ??a ?a st?????e? ? a????s? st?? te?????
    t?? p?????s?? ??e???eta? ??a ???e µ? te?µat???
    s?µί???, ?a e??a? e? t?? p??t???? ???st? to
    s????? t?? te?µat????, p?? e??a? d??at? ?a
    eµfa??s???? st?? a??? t?? s?µί???se????, p??
    pa?????ta? ap? a?t? (s????? FIRST). ?p?p????, a?
    ? ??aµµat??? pe???aµί??e? ?a???e?-e, t?te ??a
    ???e µ? te?µat??? s?µί??? p?? ί??s?eta? st?
    a??ste?? µ???? e??? t?t???? ?a???a, ep?ί???eta?
    ?a? ? ?p?????sµ?? t?? s?????? t?? te?µat????, p??
    µp??e? ?a eµfa??s???? aµ?s?? µet? ap? a?t?
    (s????? FOLLOW).

38
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? V
  • ?????s? p?????s?? ?e?t???? ?d?a
  • ???e?s?? µ?a? pa?a????? A ? ? ? ?, ? a?a??t??
    p??pe? ?a e??a? se ??s? ?a ep????e? µeta?? ? ?
  • S????a FIRST
  • G?a ??a de?? µ???? pa?a????? ??G, ??????µe ??
    FIRST(?) t? s????? t?? a?a?????st???? p??
    eµfa?????ta? p??ta st?? s?µί???se???? p??
    pa?????ta? ap? t? ?.
  • ???ad? ?s??e?, x ? FIRST(?) a? ?a? µ??? a? ? ?
    x ?, ??a ??p??a s?µί???se??? ?
  • G?aµµat??? LL(1)
  • ?? A ? ? ?a? A ? ? eµfa?????ta? st? ??aµµat???
    p??pe?
  • FIRST(?) ? FIRST(?) ?
  • ??t? ep?t??pe? st?? a?a??t? ?a p?????se? µe
    asf??e?a t?? pa?a???? p?? ?a ???s?µ?p??e? se ???e
    ί?µa!

39
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? V?
  • ???e?s?? µ?a? ??aµµat???? p?? ??e? t?? ?d??t?ta
    LL(1)
  • µp????µe ?a ??????µe d?ad??as?e? p?? ?a
    a?a????????? t? a??ste?? µ???? t?? ???e pa?a?????
  • ? ??d??a? t?? a????s?? e??a? ap??? ?a? ????????

?? ??aµµat???? µe t?? ?d??t?ta LL(1) ???µ????ta?
p?????s?µe? ??aµµat???? ??at? ? a?a??t?? µp??e?
?a p?????se? t? s?st? a??pt??? se ???e s?µe??
t?? a????s??. ?? a?a??t?? p?? e?µeta??e???ta? t??
?d??t?ta LL(1) ???µ????ta? a?a??t??
p?????s??. ??a pe??pt?s? a????s?? p?????s?? e??a?
? a????s? p??ί??p??sa? a?ad??µ???? ?at?ίas??.
40
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? V?I
  • ?a??de??µa d?????µ???? ??aµµat???? a???µ?t????
    e?f??se??
  • (ί?. d?af??e?a ?????s? p??ί??p??sa? a?ad??µ????
    ?at?ίas?? ???)

int PLUS1, MINUS2, ... int lookahead
getNextToken() //?a?????? µetί??t?
???_??? void advance() lookahead
getNextToken() void match(int token) if
(lookahead token) advance() else error()
void Term() Factor() TermPrime() void
TermPrime() switch(lookahead) case
TIMES match(TIMES) Factor()
TermPrime() break case DIV match(DIV)
Factor() TermPrime() break
default return void Factor()
switch(lookahead) case LPAR match(LPAR)
Expr() match(RPAR) break
case NUMBER match(NUMBER) break
default error()
void S() Expr() void Expr() Term()
ExprPrime() void ExprPrime()
switch(lookahead) case PLUS match(PLUS)
Term() ExprPrime() break
case MINUS match(MINUS) Term() ExprPrime()
break default return
41
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? V?II
  • ?a??de??µa d?????µ???? ??aµµat???? a???µ?t????
    e?f??se??
  • (ί?. d?af??e?a ?????s? p??ί??p??sa? a?ad??µ????
    ?at?ίas?? ???)
  • G?a t?? ?atas?e?? pa??????? d??d???
  • G??f??µe µ?sa st?? d?ad??as?e? ??d??a ??a
    d?µ??????a ??µί??
  • ?e???µe t??? ??µί??? ap? d?ad??as?a se d?ad??as?a
    µ?s? µ?a? st??ίa?
  • ?fa????µe ap? t? st??ίa t??? ??µί??? t?? de????
    µ????? t?? pa?a?????, t??? ?????µe ap??????? t??
    ??µί?? t?? a??ste??? µ????? ?a? e?s????µe t??
    te?e?ta?? st? st??ίa
  • G?a t?? ?atas?e?? s??ta?t???? d??d???
  • ?atas?e?????µe ????te???? ??µί???
  • ??e???eta? ?a t??? ί????µe st? st??ίa µe t??
    ?at?????? se??? ?ste ?a e?asfa?????µe a??ste??
    p??seta???st???t?ta

Expr() Term() ExprPrime() / d?µ??????a
??µί?? Expr e?a???? ??µί?? ExprPrime ap?
st??ίa e?a???? ??µί?? Term ap? st??ίa
?a??st??µe ExprPrime ?a? Term ap??????? t??
Expr e?sa???? ??µί?? Expr st? st??ίa /
42
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? I?
  • ???? pa??de??µa

S if E then S else S begin S
L print E. L end S
L. E num num
void S() switch(lookahead) case IF
match(IF) E() match(THEN) S()
match(ELSE) S() break case BEGIN
matvh(BEGIN) S() L() break case PRINT
match(PRINT) E() break default error()
void E() match(NUM) match(EQ)
match(NUM)
void L() switch(lookahead) case END
match(END) break case SEMI match(SEMI)
S() L() break default
error()
43
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ?
main ???s? S() S1 efa?µ??? t?? pa?a????? (S,
IF) S?if E then S else S S1 match(IF) S1
???s? E() E1 efa?µ??? t?? pa?a????? ??a (E,
NUM) E?num num E1 match(NUM) match(EQ)
match(NUM) E1 return ??a E1 st? S1 S1
match(THEN) S1???s? S() S2 efa?µ??? t??
pa?a????? ??a (S, PRINT) S?print E S2
match(PRINT) S2 ???s? E() E2 efa?µ???
t?? pa?a????? ??a (E, NUM) E?num num E2
match(NUM) match(EQ) match(NUM) E2 return
??a E2 st? S2 S2 return ??a S2 st? S1 S1
match(ELSE) S1 ???s? S() S3 efa?µ??? t??
pa?a????? ??a (S, PRINT) S?print E S3
match(PRINT) S3 ???s? E() E3 efa?µ???
t?? pa?a????? ??a (E, NUM) E?num num E3
match(NUM) match(EQ) match(NUM) E3 return
??a E2 st? S3 S3 return ??a S3 st? S1 S1
return ??a S1 st? main main match(EOF) return
success
  • ???? pa??de??µa (s????e?a)
  • p??tas? if 22 then print 55 else
    print 11

44
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ??
Ge???? µ??f? d?ad??as??? p??ί??p??sa? a?ad??µ????
?at?ίas?? ?? ??a t? µ? te?µat??? s?µί??? ?
????eta? st? ??aµµat??? ? ?a???a? ?a? a?
?p???s??µe ?t? ? e??a? apa?e???µ?,
t?te ? ?p??e?e ???_??? pe??pt?se?? FIRST(
) d?ad??as?e? a?a?????s?? pe??pt?se??
FIRST( ) d?ad??as?e? a?a?????s??
.... pe??pt?se?? FIRST( ) ?
FOLLOW(X) d?ad??as?e? a?a?????s?? ?
t?? s?µί???? p?? a????????? a????? ?????
????? ?.
45
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ???
  • S????? FIRST G?? S?????? G?????????S
  • G?a µ?a se??? s?µί???? ? t?? ??aµµat????
    ??????µe FIRST(?) ?? t? s????? t?? a?a?????st????
    p?? eµfa?????ta? st?? a??? t?? s?µί???se???? p??
    pa?????ta? ap? t?? ?
  • G?a ?a ?p?????sete t? FIRST(X) ??a ??a s?µί??? X,
    efa?µ??ete t??? ep?µe???? ?a???e? µ???? ?ta? de?
    p??st??e?ta? p???? st? FIRST(X) ??a s?µί??a
  • ?? t? X e??a? te?µat???, t?te FIRST(X) e??a? t?
    X
  • ?? ?p???e? pa?a???? X ?? t?te t? ?
    pe???aµί??eta? st? FIRST(X)
  • ?? t? X e??a? µ? te?µat??? ?a? X ?Y1Y2 ... Yk
    e??a? µ?a pa?a????, t?te s?µpe???aµί????µe st?
    FIRST(X) ???e st???e?? t?? FIRST(Y1) e?t?? ap? t?
    ?
  • ?? t? X e??a? µ? te?µat??? ?a? X ?Y1Y2 ... Yk
    e??a? µ?a pa?a????, t?te s?µpe???aµί????µe t?
    te?µat??? a st? FIRST(X) a? t? a e??a? st?
    FIRST(Yi) ?a? ? e??a? sta FIRST(Yj) ??a ??a ta 1
    ? j ? i
  • ?? X e??a? ??a µ? te?µat??? ?a? X ?Y1Y2 ... Yk
    µ?a pa?a????, t?te s?µpe???aµί????µe t? ? st?
    FIRST(X) a? t? ? e??a? sta FIRST(Yi) ??a ??a 1 ?
    i ? k

46
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ????
  • S????? FIRST G?? S????S S?????O? ??S G?????????S
  • G?a ?a ?p?????s??µe t? s????? FIRST ??a µ?a
    se??? X1X2 ... Xn s?µί???? t?? ??aµµat????
    (ef?s?? ????µe ?p?????se? ta s????a FIRST ??a ta
    X1, ?2 , ... , Xn) efa?µ????µe ta a??????a
  • ?? FIRST(X1X2 ... Xn) ?a pe???aµί??e?
  • ??a ta s?µί??a t?? FIRST(X1) e?t?? ap? t? ?
  • ??a ta s?µί??a t?? FIRST(Xi) e?t?? ap? t? ?, a?
    t? ? e??a? sta FIRST(Xj) ??a ??a ta 1 ? j ? i
  • ?a? t? ? , a? ? e??a? sta FIRST(Xi) ??a ??a ta 1
    ? i ? n

47
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ??V
  • ???????G?? ?????G?S??? S????O? FIRST

S ??f?as?. ??f?as? ???? ?p_????. ?p_????
???? ?p_???? - ???? ?p_????
e. ???? pa?????ta? ?p_pa?a?. ?p_pa?a?
pa?????ta? ?p_pa?a? / pa?????ta?
?p_pa?a? e. pa?????ta? (??f?as? )
a???µ??.
S?µί??a FIRST S?µί??a FIRST S?µί/??? FIRST S
(, a???µ?? pa?????ta? (, a???µ??
???? ?p_???? ??f?as? (, a???µ??
a???µ?? a???µ?? - ????
?p_???? - ?p_???? ? , , -
pa?????ta? ?p_pa?a?
???? (, a???µ?? - - / pa?????ta?
?p_pa?a? / ?p_pa?a? ? , , /
/ / ( (
48
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ?V
  • S????? FOLLOW G?? MH ????????? S??????
    G?????????S
  • G?a ??a µ? te?µat??? s?µί??? A ??????µe t?
    FOLLOW(A) ?? t? s????? t?? te?µat???? p?? µp?????
    ?a eµfa??s???? de??? t?? A se ??p??a p??tas?a??
    µ??f?
  • G?a t?? ?p?????sµ? t?? FOLLOW(A) ??a ??a µ?
    te?µat??? A efa?µ????µe t??? ?a???e? p??
    a????????? µ???? ?ta? de? p??st??e?ta? p???? ??a
    s?µί??a st? FOLLOW(A)
  • ??s????µe t? st? FOLLOW(S) ( e??a? t? t????
    s?µί???se????, S e??a? ? a??? t?? ??aµµat????)
  • ?? ?p???e? pa?a???? A ? ? B ?, t?te
    pe???aµί????µe st? FOLLOW(B) ??a ta s?µί??a t??
    FIRST(?) e?t?? t?? ?
  • ?? ?p???e? pa?a???? A ? ? B, t?te pe???aµί????µe
    st? FOLLOW(B) ??a ta s?µί??a t?? FOLLOW(A)
  • ?? ?p???e? pa?a???? A ? ? B ?, ?a? t? ? e??a? st?
    FIRST(?) t?te pe???aµί????µe st? FOLLOW(B) ??a ta
    s?µί??a t?? FOLLOW(A)

49
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ?V?
  • ?a?ade??µata FOLLOW (??aµµat??? a???µ?t????
    e?f??se??)

50
?????s? p??ί??p??sa? a?ad??µ???? ?at?ίas?? ?V??
  • ?e? µp????? ?a ???s?µ?p??????? a??ste??
    a?ad??µ???? ??aµµat????.
  • ?e? µp????? ?a ???s?µ?p??????? ??aµµat????, p??
    de? e??a? LL(1), ?p?? p.?.
  • se???_e?t???? e?t??? se???_e?t????
    e?t???.
  • e?t??? te?µat???.

51
?????s? LL(1) I
52
?????s? LL(1) II
  • ???????µ?? ?p?????sµ?? p??a?a a????s?? ?
  • G?a ??e? t?? pa?a????? A ? ?, ef??µ?se ta e???
    ί?µata
  • G?a ???e te?µat??? a st? FIRST(?), ??se A ? ? st?
    ??s? MA, a
  • ?? t? ? pe???aµί??eta? st? FIRST(?), ??se A ? ?
    st?? ??se?? MA, b ??a ???e te?µat??? b t??
    FOLLOW(A) ?a? ??se A ? ? st? ??s? MA, a? t?
    pe???aµί??eta? st? FOLLOW(A)
  • ??e? ?? ?p????pe? ??se?? t?? p??a?a M e?f??????
    t?? a?a?????s? ??????.

53
?????s? LL(1) II?
  • ???????G?? (??aµµat??? a???µ?t???? e?f??se??)

S ??f?as?. ??f?as? ???? ?p_????. ?p_????
???? ?p_???? - ???? ?p_????
e. ???? pa?????ta? ?p_pa?a?. ?p_pa?a?
pa?????ta? ?p_pa?a? / pa?????ta?
?p_pa?a? e. pa?????ta? (??f?as? )
a???µ??.
54
?????s? LL(1) IV
  • ???????G?? (??aµµat??? a???µ?t???? e?f??se?? -
    s????e?a)

55
?????s? LL(1) V
  • ???????µ?? a????s?? LL(1)

push() // e??a? t? s?µί??? t????? t??
s?µί???se???? push(S) // S e??a? ? a??? t??
??aµµat???? lookahead get_next_token() //
d??ίase t? ep?µe?? a?a?????st??? repeat X
top_of_stack() if (X e??a? te?µat??? ? X
) then if (X lookahead) then
pop(X) lookahead
get_next_token() else error() else
// X ??a µ? te?µat??? if ( MX,
lookahead X ? Y1 Y2 ... Yk) then
pop(X) push(Yk) push(Yk-1) ...
push(Y1) else error() until (X )

56
?p?µ?????s? a??ste??? a?ad??µ???t?ta? ?
  • ??a??????µe t?? ?µes? ?a? t?? ?µµes? a??ste??
    a?ad??µ???t?ta
  • ???????G?? ???S?S ??. ??????????????S
  • ??f?as? ??f?as? ??_?T ???? ????.
  • ???????G?? ????S?S ??. ??????????????S
  • G????? ???F? ???S?S ??. ??????????????S
  • µetas??µat??eta? st?? ?s?d??aµ? µ??f?

57
?p?µ?????s? a??ste??? a?ad??µ???t?ta? ??
  • ???????G??
  • ? S ??f?as?.
  • ??f?as? ??f?as? ???? ??f?as? - ????
    ????.
  • ???? ???? pa?????ta? ???? / pa?????ta?
    pa?????ta?.
  • pa?????ta? ( ??f?as? ) a???µ??.
  • µetas??µat?st??e st??
  • S ??f?as?.
  • ??f?as? ???? ?p_????.
  • ?p_???? ???? ?p_???? - ???? ?p_????
    e.
  • ???? pa?????ta? ?p_pa?a?.
  • ?p_pa?a? pa?????ta? ?p_pa?a? /
    pa?????ta? ?p_pa?a? e.
  • pa?????ta? (??f?as? ) a???µ??.

58
?p?µ?????s? a??ste??? a?ad??µ???t?ta? ???
  • ???????µ?? ap?µ?????s?? ?µes?? ?a? ?µµes??
    a??ste??? a?ad??µ???t?ta?

59
?p?µ?????s? a??ste??? a?ad??µ???t?ta? ?V
  • ?at? t?? ap?µ?????s? t?? a??ste???
    a?ad??µ???t?ta? de? a????e? ? ???ssa t??
    ??aµµat????.
  • ?????e? ? µ??f? t?? d??d??? p?? pa???e? ?
    ep??e?e?sa µ???d?? a????s??.
  • S?µa?t???te?? s???pe?a e??a? t? ?e????? ?t?
    ???eta? ? ep???µ?t? ?d??t?ta t?? a??ste???
    p??seta???st???t?ta?.

60
???ste?? pa?a???t?p???s? ?
  • ?????e?ta? ?p??asd?p?te p??ί??p??sa? a????s??, a?
    ??a t? ?d?? µ? te?µat??? s????? ?p?????? d?? ?
    pe??ss?te??? ?a???e? µe t? ?d?? p???eµa st? de??
    µ????.
  • ???????G????
  • se???_e?t???? e?t??? se???_e?t????
    e?t???.
  • e?t??? te?µat???.
  • ?
  • e?t???_if if ??f?as? then e?t???
  • if ??f?as? then e?t??? else
    e?t???.

61
???ste?? pa?a???t?p???s? ??
  • Ge????, ? ?a???a?
  • µetas??µat??eta? st??

62
???d??? a????s? Ge???? ?
  • ? s?µί???se??? e?s?d?? stad?a?? ap??p??e?ta? st?
    s?µί??? t?? a???? t?? ??aµµat????, ?a???
    d?aί??eta? ap? a??ste?? p??? ta de??? pa??????a
    µe t?? efa?µ??? ?a????? ??a ta s?µί??a, p?? ?????
    ?d? d?aίas?e?.
  • ? a?t?st??f? t?? ap??p???s?? p?? e?te?e? µ?a
    d?ad??as?a a??d???? a????s?? e??a? µ?a pa?a????
    de???? p??tas?a??? µ??f??.
  • ?? d??d?? a?apt?sseta? ί?µa p??? ί?µa, ap?
    a??ste?? p??? ta de??? ?a? ap? ta f???a p??? t?
    ???a.
  • ???e d?ad??as?a a??d???? a????s?? s??t????e? t??
    e?t??es? e?e??e??? ???s?? (st? st??ίa),
    ap??p???s?? ?a? ap?d????.

63
???d??? a????s? Ge???? ??
  • ?????e?a ???s??
  • O?e?ta? ? t?????sa ?e???? µ???da st? st??ίa ?a?
    d?aί??eta? ? ep?µe??.
  • ??µ?????e?ta? ??a t? s?µί??? p?? ??e?ta? ?
    a?t?st????? ??µί?? µe t? µ??f? ???? d??d???, sta
    de??? t?? d?s??? p?? ap?te?e?ta? ap? d??d?a, p??
    d?µ?????????a? sta p??????µe?a ί?µata t??
    a????s??.
  • ?????e?a ap??p???s??
  • Se µ?a e????e?a ap??p???s?? µe ί?s? ??a
    s???e???µ??? ?a???a
  • t?? ??aµµat????, ????µe d?µ??????a e??? ????
    ??µί?? ??a t? µ? te?µat??? s?µί??? ? ?a?
    µetat??p? t?? n ????? p?? ί??s???ta? sta de???
    t?? d?s???, se ap??????? t?? ???? ??µί??.

64
???d??? a????s? ???s?? ap??p???s?? ?
  • S ??f?as?.
  • ??f?as? ??f?as? a???µ?? a???µ??.

65
???d??? a????s? ???s?? ap??p???s?? ??

66
???d??? a????s? ???s?? ap??p???s?? ???
  • ?? ??t??? p???eµa µ?a? ?p??asd?p?te de????
    p??tas?a??? µ??f?? e??a? t? s????? t?? s?µί????,
    p?? pe??????ta? st? st??ίa, se ??p??? ί?µa t??
    a????s?? (d??. ?? ???e? t?? d??d??? p??
    s??µat????ta?).
  • ??a s????? s?µί????, p?? µp??e? ?a ί??s?eta? st??
    ????f? t?? st??ίa? ?a? s?µίa??e? ?a ta?????e? µe
    t? de?? µ???? e??? ?a???a pa?a????? ???µ??eta?
    ?aί? ap??p???s??.
  • ???????G??

67
???d??? a????s? ???s?? ap??p???s?? ?V
  • ??ad??as?e? ???s?? ap??p???s??
  • - a????s? p??te?a??t?ta? te?est??
  • - a????s? ap??? p?????s??
  • - a????s? LR (? p?? s?µa?t???)
  • ?? ???sse? LR e??a? p??sd????st???? (d??. ?p???e?
    a?t?µat? st??ίa? p?? t?? a?a??????e? µe
    p??sd????st??? t??p?).
  • ?? te?????? a????s?? LR, p?? ???s?µ?p????µe, de?
    a?a????????? t?? p??t?se?? t?? ???ssa? µe
    p??sd????st??? t??p? se ??e? t?? pe??pt?se??.
    ???a?? p??ί??µata
  • S??????s? ???s?? ap??p???s?? (p??ί??µa µet?????
    else).
  • S??????s? ap??p???s?? ap??p???s??.

68
?????s? LR I
  • ? ???????e?a t?? ??aµµat???? LR e??a? ??a
    ?pe?s????? t?? ??aµµat????, p?? a?a????ta? µe
    ???s? t?? te?????? LL(1). ??e??e?t?µata
  • ?µes?? e?t?p?sµ?? ?a???.
  • ? p?? ?e???? a????s? ???s?? ap??p???s??, p??
    µp??e? ?a ???p????e? ????? ?p?s??d??µ?s? ?a? ?a
    ?e?t????e? t? ?d?? ap?d?t??? µe t?? ?p????pe?
    te?????? t?? ?d?a? ?at?????a?.
  • ???a? ? t?p?? t?? ??d??a a????s??, p?? pa???eta?
    ap? t?? p?? d?aded?µ??e? ?e???t??e? ??d??a.
  • ?? te?????? LR d?af????? µeta?? t??? a?????a µe
    t?? t??p? µe t?? ?p??? ???eta? ? s??t???sµ?? t??
    e?t??es?? t?? e?e??e??? ???s?? ?a? ap??p???s??.

69
?????s? LR I?
  • G?a t?? ?a????sµ? t?? ep?µe??? e????e?a? ?
    a?a??t?? ???s?µ?p??e? ??a? a???µ?, p?? s???de?e?
    t?? ???e? t?? d??d??? t?? d?s???.
  • ? a???µ?? a?t?? ???µ??eta? ?at?stas? ?a? e?d??? ?
    ?at?stas? t?? ???a? t?? d??d??? p?? ί??s?eta? sta
    de??? t?? d?s??? ???µ??eta? t?????sa ?at?stas?.
  • ?p?p????, st? a??ste?? µ???? t?? d?s??? ?p???e? ?
    a????? ?at?stas?, p?? ???s?µ?p??e?ta? ??a t??
    ?a????sµ? t?? p??t?? e????e?a? t?? a?a??t?.
  • ?? e????e?e? e??? a?a??t? LR e?a?t??ta? ap? t??
    e??st?te t?????sa ?at?stas? t??.

70
?????s? LR I??
  • St?? e????e?a t?? ???s??, ? ?at?stas? t?? ???a?
    t?? ???? d??d??? ?a?????eta? ap? t?? t?????sa
    ?at?stas? ?a? ap? t? s?µί???, p?? ??e?ta? st?
    st??ίa (?a? st? d?s??).
  • Se e????e?a ap??p???s??, d?µ?????e?ta? ??a? ????
    ??µί?? ??a t? µ? te?µat??? s?µί??? st? ?p???
    a?af??eta? ? ?a???a? ?a? s??d???ta? s? a?t?? ??
    ap??????, ?? n p?? de???? ???e? t?? d?s???, p??
    a?t?st?????? sta s?µί??a t?? de???? µ????? t??
    ?a???a. ??te d?a???f??ta? ?? ?atast?se?? p??
    s???de???? t?? n ???e?. ? ?at?stas? p??
    ep?s???pteta? st? ??a ???a, ?a?????eta? µe ί?s?
    t?? ?at?stas? t?? ???a?, p?? ί??s?eta? aµ?s?? p??
    a??ste?? ?a? t? µ? te?µat??? s?µί??? t?? ????
    ??µί??.
  • G?a t?? ?a????sµ? t?? e?e??e??? t?? a????s??
    ???s?µ?p????µe ??a? p??a?a e?e??e??? ?a? ??a?
    p??a?a µetaί?se??.

71
?????s? LR IV

72
?????s? LR V

73
?????s? LR VI
  • ???????G??
  • (1) ??f?as? ??f?as? ????.
  • (2) ??f?as? ??f?as? - ????.
  • (3) ??f?as? ????.
  • (4) ???? ???? pa?????ta?.
  • (5) ???? ???? / pa?????ta?.
  • (6) ???? pa?????ta?.
  • (7) pa?????ta? ( ??f?as? ).
  • (8) pa?????ta? a???µ??.

74
?????s? LR VI?

75
?????s? LR VI??

76
?????s? LR ??

77
??a??t?? LR ???s?? - ap??p???s?? ?

78
??a??t?? LR ???s?? - ap??p???s?? ?I
push() // t? s?µί??? t?????
s?µί???se???? push(s0) // s0 ? a?????
?at?stas? lookahead get_next_token() repeat
forever s top_of_stack() // ACTION e??a? ?
p??a?a? e?e??e??? if ( ACTIONs,lookahead
ap??p???s? ??? ) then pop 2? s?µί??a
//afa?????ta? ta s?µί??a ?? ?atast?se??
s top_of_stack() push(?)
push(GOTOs,?) // GOTO e??a? ? p??a?a?
µetaί?se?? else if ( ACTIONs,lookahead
???s? si ) then push(lookahead)
push(si) lookahead
get_next_token() else if ( ACTIONs,lookahead
ap?d??? and lookahead ) then
return (ep?t???? a?a?????s?) else error()
79
??a??t?? LR ???s?? - ap??p???s?? ?I?
  • ??a ??aµµat??? e??a? LR(k) a?, d??e?s?? µ?a?
    de???? pa?a?????
  • S ? ?0 ? ?1 ? ?2 ? ? ?n-1 ? ?n ? p??tas?
  • µp????µe
  • 1. ?a a?a?????s??µe µ?a ?aί? ap??p???s?? ??a ???e
    de??? p??tas?a?? µ??f? ?i , ?a?
  • 2. ?a ?a????s??µe t?? ?a???a t?? ap??p???s??
  • µe t?? a?????s? t?? ?i ap? a??ste?? p??? ta
    de???, p???????ta? t? p??? k s?µί??a p?? de???
    ap? t? t???? t?? ?aί?? ap??p???s?? t?? ?i .

80
??a??t?? LR ???s?? - ap??p???s?? ?V
  • ?? µ?a ??aµµat??? e??a? LR(?) ? ?p???e? µ?a ?a?
    µ??? µ?a de??? pa?a???? t?? ???e p??tas??
  • St? p??? µ???? t?? st??ίa? e?te
  • ?p?????? ??e? ?? e?e???? ?aί?? ap??p???s?? p??
    pe???aµί????? t?? ????f? t?? st??ίa?, e?te
  • ?????ta? s?µί??a µ???? ?a ap?te?e? ? ????f? t?
    de?? ???? µ?a? ?aί?? ap??p???s??
  • ? ???ssa t?? ?aί?? ap??p???s?? e??a? ?a?????? ?a?
    ??a
  • µp??e? ?a ?atas?e?as?e? ??a p??sd????st???
    pepe?asµ??? a?t?µat? p?? ?a e?te?e? a?a?????s?
    ?aί?? ap??p???s??
  • ?? p??a?e? e?e??e??? ?a? µet?ίas?? ??s?ast???
    e?f?????? t? s???e???µ??? a?t?µat?
  • ???e ??a ?at?stas? t?? a?t?µat?? t?? e?s????µe
    st? st??ίa
  • ?? te????? ?atast?se?? t?? a?t?µat?? a?t?st??????
    se e????e?e? ap??p???s??
  • ??a ?at?stas? e??a? ? GOTOa??ste?? s?µί???
    ?a???a , ?at?stas? ????f??

81
??a??t?? LR ???s?? - ap??p???s?? V
  • ??? ft??????µe t??? p??a?e? e?e??e???
    µetaί?se??

St??ίa
p??a??? ??d??a?
??d??µes? ??apa??stas?
??aµµat???
82
??a??t?? LR ???s?? - ap??p???s?? V?
  • ??? ft??????µe t??? p??a?e? e?e??e???
    µetaί?se?? (????? t? yacc)
  • ?atas?e?????µe ap? t? ??aµµat??? t? a?t?µat?
    a?a?????s?? ?aί?? ap??p???s??
  • ??????µe t??? p??a?e? e?e??e??? µetaί?se??
  • a? ? ?atas?e?? t?? a?t?µ?t?? pet??e? t?te ?
    ??aµµat??? e??a? ??aµµat??? LR(?)
  • a????? e??a? p??a?? ?a p???????? s??????se??
    ???s?? ap??p???s?? ? s??????se?? ap??p???s??
    ap??p???s??
  • t?te ? ?a p??pe? ?a efa?µ?s?e? µ?a ???? ?atas?e??
    LR(?) ? ?a ?atas?e??s??µe t?? a?a??t? ?ts? ?ste
    se µ?a pe??pt?s? s??????s?? ?a ep????e? ???e f???
    µ?a s???e???µ??? e????e?a
  • ?? a?a??t?? t?? byacc ?ta? ????µe s??????s?
    ???s?? ap??p???s?? e?te???? ???e f??? t?? ???s?

83
??a??t?? LR ???s?? - ap??p???s?? V??
  • ??? ft??????µe t? a?t?µat? a?a?????s?? ?aί??
    ap??p???s?? (????? t? yacc)
  • ???s?µ?p????µe st???e?a LR(k) ??a ?a
    ??d???p???s??µe t? s????? t?? ?a????? p?? µp??e?
    t? de?? t??? µ???? ?a ap?te??se? ?aί? ap??p???s??
    se µ?a ded?µ??? ?at?stas?
  • ?p????????µe ??a ???e ?at?stas? ta goto( s, ? )
    ?a? closure( s ), d??ad? t? ??e?s?µ? (ί?.
    s????e?a)
  • ?ata???f??µe t?? ?atast?se?? ?a? t?? µetaί?se??
    t?? a?t?µat??
  • s?µp???????µe t??? p??a?e? e?e??e??? µetaί?se??

84
??a??t?? LR ???s?? - ap??p???s?? V???
  • St???e?? LR(k) e??a? ??a ?e???? A , B, ?p??
  • A e??a? µ?a pa?a???? ????? µe µ?a ??p?? st?
    de?? µ????
  • B s?µί??a e?s?d?? µe µ???? k
    (te?µat??? ? )
  • ?a?ade??µata
  • ????? , a
  • ????? , a
  • ????? , a
  • ????? , a
  • ? de???e? t?? t?????sa ??s? p?? µp????µe ?a
    ?e???s??µe ?t? a?apa??st? ? ????f? t?? st??ίa?
  • st???e?a LR(0) ??? ?? (de? ?p??????
    s?µί??a e?s?d??)
  • st???e?a LR(1) ??? ?? , a (??a µ???
    s?µί??? e?s?d??)
  • st???e?a LR(2) ??? ?? , a b (d?? s?µί??a
    e?s?d??) ...

85
???a?e? a????s?? LR(1) I
  • ? pa?a???? ?????, µe s?µί??? e?s?d?? a, pa???e? 4
    st???e?a LR(1)
  • ????? , a, ????? , a, ????? , a,
    ????? , a
  • ?? s????? t?? LR(1) st???e??? µ?a? ??aµµat????
    e??a? pepe?asµ???.
  • ???a e??a? ? s?µas?a t?? s?µί???? e?s?d?? sta
    st???e?a
  • ta ?ata???f??µe ?ts? ?ste ?a ?d????µaste st?
    s?st? ap??p???s?
  • a? ? ί??s?eta? se e?d??µes? ??s? se ??a µ???
    st???e?? de? pa??e? ??p??? ?d?a?te?? ????
  • p.?. st? ????? , a, t? s?µί??? e?s?d?? de?
    ??e? ?d?a?te?? s?µas?a
  • st? ????? , a, t? s?µί??? a ?d??e? st??
    ap??p???s? ?????
  • st? s????? ??? , a,???? , b
  • s?µί??? e?s?d?? a ? ap??p???s? se ?
  • s?µί??? e?s?d?? ? FIRST(?) ? ???s?
  • se µ?a LR(1) ??aµµat??? ??a s?µί??? e?s?d?? e??a?
    a??et? ??a ?a ?a????se? t?? ep?µe?? e????e?a

86
???a?e? a????s?? LR(1) II
  • ?? ?atast?se?? t?? p??sd????st???? a?t?µat??
    a?a?????s?? ?aί?? ap??p???s?? ??????ta? ?? s????a
    st???e???, I0 , I1 , ... , In
  • a. ??s????µe ??a ??? s?µί??? S ?a? µ?a pa?a????
  • S ? S ?p?? S ? a??? t?? ??aµµat????
  • b. ? a????? ?at?stas?, I0 pe???aµί??e? ta
    st???e?a
  • S ?S, ?a? ??a ta ?s?d??aµa p?? d????ta? ??
  • closure( I0 )
  • c. G?a ???e s????? Ik ?a? ???e s?µί??? ?,
    ί??s???µe t? goto(Ik , ?)
  • a? t? s????? t?? goto(Ik , ?) de? ??e? ?d?
    d?µ???????e? t?te t? d?µ???????µe
  • ?ata???f??µe ??e? t?? µetaί?se?? goto( )
  • S?µp???????µe t??? p??a?e? e?e??e??? ?a?
    µetaί?se?? t?? a????s??

87
???a?e? a????s?? LR(1) II?
  • ?????G?S??S closure(I)
  • ?? closure(I) p??s??te? st? s????? I ??a ta
    st???e?a p?? p????pt??? ap? ta ?d? ?p?????ta st?
    I
  • ???e st???e?? ?????? , a d?µ?????e? ep?s?? ??a
    ta ??? ? , x ??a ???e pa?a???? µe ? sta
    a??ste?? ?a? ??a ??a ta x ? FIRST(?a)
  • ef?s?? s?µpe????f???? ??a ta st???e?a t??
    pa?a????? ? pe???aµί????ta? ?a? ?sa p????pt???
    ap? a?t? efa?µ????ta? t?? ?d?a p????

Closure( I ) while ( t? s????? I µe?a???e? )
for ???e ? ? ? ?? , a ? I
for ???e pa?a???? ? ? ? ? P for
???e te?µat??? b ? FIRST(?a)
if ? ? ? , b ? I
then p??s??ese t? ? ? ? , b st? I
88
???a?e? a????s?? LR(1) IV
  • ?????G?S??S goto(I,x)
  • ?p??????e? t? ??a ?at?stas? p?? ? a?a??t??
    p??se????e? a? a?t?? ί??s?eta? st?? ?at?stas? I
    ?a? a?a??????e? t? te?µat??? x
  • goto( ??? ? ?? , a , ? ) pa???e? ?at?stas?
    p?? pe???aµί??e? t? ???? ? ? , a
  • a? de? ?p???e? d?µ?????e?ta? ?a? pe???aµί??eta?
    se a?t? ?a? t? closure( ???? ? ? , a )

Goto( I, x ) new Ψ for ???e ? ? ?
x ? , a ? I new new ? ? ? ?x
? , a return closure(new)
89
???a?e? a????s?? LR(1) V
  • ??G???T??S ????S????S ?????????
  • ?e????µe ap? t? I0 closure( S? S , )
  • ??µ???????µe s????e?a ??e? ?atast?se?? µ???? t?
    st??µ? p?? de? ?a µp??e? ?a d?µ?????????? ???e?

I0 closure( S ? S , ) C I0
while ( p??st??e?ta? st? C ??a s????a st???e???
) for ???e Ii ? C ?a? ???e x ? ( T?NT )
Inew goto(Ii , x) if Inew ? C
then C C ? Inew
?at???a?e t? µet?ίas? Ii ? Inew µe a?a?????s?
t?? x
90
???a?e? a????s?? LR(1) V?
  • ??G???T??? ????S????S ?????O? LR(1)

Closure( I ) while ( t? s????? I µe?a???e? )
for ???e ? ? ? ?? , a ? I
for ???e pa?a???? ? ? ? ? P for
???e te?µat??? b ? FIRST(?a)
if ? ? ? , b ? I
then p??s??ese t? ? ? ? , b st? I
Goto( I, x ) new Ψ for ???e ? ? ?
x ? , a ? I new new ? ? ? ?x
? , a return closure(new)
I0 closure( S ? S , ) C I0
while ( p??st??e?ta? st? C ??a s????a st???e???
) for ???e Ii ? C ?a? ???e x ? ( T?NT )
Inew goto(Ii , x) if Inew ? C
then C C ? Inew
?at???a?e t? µet?ίas? Ii ? Inew µe a?a?????s?
t?? x
91
?a??de??µa a????s?? LR(1) ?
S ? ??f?as? ??f?as? ? ???? - ??f?as? ??f?as? ?
???? ???? ? pa?????ta? ???? ???? ?
pa?????ta? pa?????ta? ? id
S?µί??? FIRST S id ??f?as? id ???? id
pa?????ta? id - - id id
92
?a??de??µa a????s?? LR(1) ??
93
?a??de??µa a????s?? LR(1) ???
  • ???????G?? ?????O?

for ???e s????? st???e??? Ix ? C for ???e
st???e?? ? Ix if st???e?? e??a? ???
a?,b ?a? a ? T ?a? goto(Ix,a) Ik ,
then ACTIONx,a ? ???s? k else if
st???e?? e??a? S?S , then
ACTIONx , ? ap?d??? else if
st???e?? e??a? ??? ,a then
ACTIONx,a ? ap??p???s? ??? for ???e n ?
NT if goto(Ix ,n) Ik then
GOTOx,n ? k
94
?a??de??µa a????s?? LR(1) ?V
95
S??????se?? e?e??e???
  • ?? ???eta? a? ? ?at?stas? s pe????e? ? ? ? a?
    , b ?a? ? ? ? , a
  • ?? p??t? st???e?? pa???e? ???s? ?a? t? de?te??
    ap??p???s?
  • ?e? µp????µe st? ACTIONs,a ?a s?µp????s??µe d??
    e????e?e?
  • S??????s? ???s?? ap??p???s?? (shift reduce
    conflict)
  • ?p????µe ? ?a a??????µe t? ??aµµat??? ?
  • a??a??eta ?a ep??????µe t?? e?t??es? ???s??, ??t?
    p?? ??e? ap?de???e? ?t? s?????? ap?d?de? t? s?st?
    s?µas?a (p.?. ???ί??µa µet????? else) ?
  • ?a ep??????µe ??p??a ???? a????s? LR
  • ?? ???eta? ?ta? ? ?at?stas? s pe????e? ? ? ? ,
    a ?a? ? ? ? , a
  • ???e st???e?? pa???e? ap??p???s?, a??? µe
    d?af??et??? ?a???a
  • ?e? µp????µe st? ACTIONs,a ?a s?µp????s??µe d??
    e????e?e?
  • S??????s? ap??p???s?? ap??p???s?? (reduce
    reduce conflict)
  • ??de??? ?????? st? ??aµµat???
  • ?a? st?? d?? pe??pt?se?? ??µe ?t? ? ??aµµat???
    de? e??a? LR(1)

96
?a?a??a??? a????s?? LR LR(0)
µetaί?se?? s?????? st???e??? LR(0)
??e?s?µ? s?????? st???e??? LR(0)
Goto( I, x ) new Ψ for ???e ? ? ?
x ? ? I new new ? ? ? ?x ?
return closure(new)
Closure( I ) while ( t? s????? I µe?a???e? )
for ???e st???e?? ? ? ? ?? ? I
for ???e pa?a???? ? ? ? ? P
if ? ? ? ? I then
p??s??ese t? ? ? ? st? I
  • ?as??? e??a? ?? ?d??? a??????µ?? ?p?? ?a? ??a
    t?? a????s? LR(1)
  • ? µ??? d?af??? e??a? ?t? sta st???e?a LR(0) de?
    ?p???e? s?µί??? e?s?d?? ?a? ??? a?t? de?
    pa?????ta? p???? st???e?a se ???e s?????
  • ? a????s? LR(0) pa???e? ????te?e? ?atast?se??
  • ?e? µp??e? ?a a?a?????se? ??e? t?? ??aµµat????
    p?? a?a??????e? ? LR(1)
  • ???a? p?? p??a?? ?a ?d???se? se s??????se??
    a????s??

?atas?e?? s?????? st???e??? LR(0)
I0 closure( S ? S ) C I0 while (
p??st??e?ta? st? C ??a s????a st???e???) for
???e Ii ? C ?a? ???e x ? ( T?NT )
Inew goto(Ii , x) if Inew ? C then
C C ? Inew ?at???a?e
t? µet?ίas? Ii ? Inew µe
a?a?????s? t?? x
97
?a?a??a??? a????s?? LR SLR(1)
  • ? a??????µ?? SLR(1) ??a ?a ?a????se? p?te ?a
    ???e? ap??p???s? ???s?µ?p??e? ?a? ta s????a
    FOLLOW
  • ?? a?a??t?? SLR(1) ????? ????te?e? ?atast?se??
    ap? ?t? ?? LR(1)

for ???e s????? st???e??? Ix ? C for ???e
st???e?? ? Ix if st???e?? e??a? ???
a? ?a? a ? T ?a? goto(Ix,a) Ik ,
then ACTIONx,a ? ???s? k else if
st???e?? e??a? S?S then
ACTIONx ,\0 ? ap?d??? else if
st???e?? e??a? ??? then for ???e a
? FOLLOW(?) then ACTIONx,a ?
ap??p???s? ??? for each n ? NT if
goto(Ix ,n) Ik then GOTOx,n ? k
98
?a?a??a??? a????s?? LR LALR(1)
  • ?as??? ?d?a s?????s? ?atast?se?? LR(1)
  • ??at?µe t?? p????a LR(0) t?? st???e??? LR(1)
    (a?????µe ta s?µί??a e?s?d??)
  • a? d?? s????a LR(1) ????? t?? ?d?? p????a, t?te
    ta s??e?????µe ?a? e??µe?????µe t??? p??a?e?
    ACTION ?a? GOTO
  • ?? a?a??t?? LALR(1) µp????? ?a ft?a?t??? µe d??
    t??p???
  • ?atas?e?? t?? s?????? st???e??? LR(1) ?a?
    s?????s?
  • ??????µe ta st???e?a µe te?e?a st?? a??? t??
    de???? µ????? ?a? ?atas?e?????µe p????e? s??????
    st???e??? LR(0). St? s????e?a ???s?µ?p????µe ??a?
    a??????µ? p?????s?? s?µί???? e?s?d?? ??a ?a
    ?p?????s??µe ta s?µί??a e?s?d??.
  • ? de?te?? p??s????s? e??a? p?? ap?d?t??? epe?d?
    ap?fe??e? t? d?µ??????a µe????? e?d??µes?? LR(1)
    p??????

99
?a?a??a??? a????s?? LR LALR(1)
  • ??a? a?a??t?? LALR(1) ??a µ?a ??aµµat??? G ??e?
    t?? ?d?? a???µ? ?atast?se?? µe t?? a?t?st????
    a?a??t? SLR(1)
  • ?? ??a? a?a??t?? LR(1) ??a µ?a ??aµµat??? G de?
    pa???s???e? s??????se?? ???s?? - ap??p???s??,
    t?te de? ?a ??e? s??????se?? ???s?? ap??p???s??
    ?a? ? a?a??t?? LALR(1)
  • ??a? a?a??t?? LALR(1) µp??e? ?a eµfa???e?
    s??????s? ap??p???s?? - ap??p???s?? ????? a?t? ?a
    s?µίa??e? ?a? st?? a?t?st???? LR(1)
  • ?? a?a??t?? LALR(1) e??a? p?? ?e????? ap? t???
    SLR(1) ?a? s???????? ????? t? ?d?? µ???? ????
    ?atast?se??
  • ?????s? LALR(1) pa?????? ?? ?e???t??e? yacc ?a?
    byacc

100
G??sse? ????? s?µf?a??µe?a ?
LR(k) ? LR(1)
? ?e?a???a ???ss?? ????? s?µf?a??µe?a
101
G??sse? ????? s?µf?a??µe?a ??
G??sse? ????? s?µf?a??µe?a
G??sse? ????? as?fe?e?
???te?a??t?ta? te?est??
?e?a???a ???ss?? ????? s?µf?a??µe?a
LR(k)
LR(1)
LL(k)
  • ?? ???sse? p??te?a??t?ta? te?est?? pe???aµί?????
    ?a? ??p??e? ???sse? µe as?fe?e?
  • LL(1) e??a? ?p?s????? t?? ??aµµat???? SLR(1)

LALR(1)
SLR(1)
LL(1)
LR(0)
102
??????? ?a??? ?
  • ??t?p?sµ?? ?????? ?s? t? d??at?? p?? ???a??a.
  • ?p????? ??s?? ap? ?p?? ?a s??e???eta? ? a????s?.
  • ?a e?t?p????ta? µ??? ?pa??t? ???? ?a? ?a µ??
    eµfa?????ta? d?ad?d?µe?a p?asµat??? ????.
  • ?a ap?fe??eta? ? µet?pt?s? t?? a?a??t? se
    at??µ??e? ί??????.
  • ?e?????? a??????? ?a???
  • a?????? pa?????
  • a?????? se ep?ped? f??s??
  • ?a???e? pa?a????? ??a ????
  • s??????? d?????s?

103
??????? ?a??? ??
  • ? a?????? pa????? st?? p??ί??p??sa a?ad??µ???
    ?at?ίas? ???p??e?ta? µe t?? ?a????sµ? µ???d??
    s???????sµ??.
  • ?ta? ? a?a??t?? ί?e? ?????, t?te p??spe??? t??
    ep?µe?e? µ???de? µ???? ?a e?t?p?se? µ?a µ???da
    s???????sµ?? ap? t?? ?p??a µp??e? ?a s??e??se?
    t?? a????s??. ???e µ? te?µat??? s?µί??? ??e? t??
    d???? t?? µ???de? s???????sµ??. ?? µ???de?
    s???????sµ?? ep??????ta? µ?sa ap? ta s????a
    FOLLOW.
  • St?? a????s? LL(1) ????µe e?t?p?sµ? ??????, ?ta?
    st?? ????f? t?? st??ίa? ί??s?eta? ??a µ?
    te?µat??? s?µί??? X, t?t??? ?ste t? t?????
    s?µί??? e?s?d?? ?a µ?? pe???aµί??eta? st? s?????
    FIRST(X) ?a? a? a?t? s?µίa??e? ?a pe????e? t? e,
    ??te st? s????? FOLLOW(X).

104
??????? pa????? st?? a????s? LL(1) I
  • ? a?????? pa????? µp??e? e????a ?a ???p????e?
    µe t?? p??sd????sµ? t?? ?at??????? e????e?a?, ??a
    ???e pe??pt?s? ?e??? ??s??, st?? p??a?a a????s??.
    ??a??????µe t?e?? p??a??? e????e?e? a???????
  • t?? afa??es? t?? s?µί???? ? ap? t? st??ίa (pop),
  • t? p??sp??asµa e??? a???µ?? s?µί???? e?s?d??,
    µ???? t?? e?t?p?sµ? µ???da?, p?? µp??e? ?a
    ???s?µ?p????e? ??a t?? epa?e?????s? t??
    d?ad??as?a? a????s?? (scan) ?a?
  • t?? ???s? st? st??ίa e??? ???? µ? te?µat????
    s?µί????.

105
??????? pa????? st?? a????s? LL(1) II
  • ? pop e?te?e?ta?, ?ta? ? t?????sa ?e???? µ???da
    e??a? ? ? ?ta? a?t? a???e? st? FOLLOW(X).
  • ? scan e?te?e?ta?, ?ta? ? t?????sa ?e???? µ???da
    de? e??a? ? ?a? de? a???e? st? .
  • ? push ep?st?ate?eta?, ?ta? s?µίe? ?a ??e?
    ade??se? ? st??ίa, e?? de? ??e? ?????????e? a??µ?
    ? a?????s? ???? t?? µ???d?? t?? s?µί???se????
    e?s?d??. ??te ??e?ta? st? st??ίa t? s?µί??? t??
    a???? t?? ??aµµat???? ?a? a??????ta? ??a p??? ??a
    ??a ta ep?µe?a s?µί??a e?s?d??, µ???? t??
    a?????s? s?µί????, p?? a???e? st? s????? FIRST
    t?? a????.

106
??????? pa????? st?? a????s? LL(1) III
  • ???????G?? (a?????? ?a??? st? ??aµµat???
    a???µ?t???? e?f??se??)

S ??f?as?. ??f?as? ???? ?p_????. ?p_????
???? ?p_???? - ???? ?p_????
e. ???? pa?????ta? ?p_pa?a?. ?p_pa?a?
pa?????ta? ?p_pa?a? / pa?????ta?
?p_pa?a? e. pa?????ta? (??f?as? )
a???µ??.
107
??????? pa????? st?? a????s? LL(1) IV
  • ??????S ?????S?S ?O??S ??????? ??TO?
  • ??????S ?????S?S ?? ??????? ??TO?

108
??????? pa????? st?? a????s? LL(1) V

109
??t?p?sµ?? ?????? st?? a????s? LR I
(1) ??f?as? ??f?as? ????. (2) ??f?as?
??f?as? - ????. (3) ??f?as? ????. (4) ????
???? pa?????ta?. (5) ???? ???? /
pa?????ta?. (6) ???? pa?????ta?. (7) pa?????ta?
( ??f?as? ). (8) pa?????ta? a???µ??.
110
??t?p?sµ?? ?????? st?? a????s? LR II
111
??t?p?sµ?? ?????? st?? a????s? LR III
112
??t?p?sµ?? ?????? st?? a????s? LR IV
  • ??a?????s? ?????? ???eta? ?ta? ? a??????µ??
    pe?????e? se ?at?stas?, p?? st?? p??a?a e?e??e???
    de? a?t?st???e? s???e???µ??? e????e?a ??a t?
    te?µat??? e?s?d??, p?? a??????e?.
  • ?? d?a???st??? µ???µa ?????? p?? p??pe? ?a
    t?p??e? µp??e? ?a ep??e?e? a? e?et?s??µe ta
    pe??e??µe?a t?? st??ίa?.

113
??t?p?sµ?? ?????? st?? a????s? LR V
  • ??????? pa?????
  • ?a?????eta? ??a s????? µ???d?? s???????sµ?? p??
    s?????? ap?te?e?ta? ap? d?a????st?? p?? d???????
    t???? e?t???? ? ????? d?µ?µ???? st???e??? t??
    ???ssa?
  • ?ta? e?t?p??eta? ?????, t?te s??e???eta? ?
    a?????s? t?? ?e????? µ???d?? e?s?d??, µ???? t??
    e?t?p?sµ? ??p??a? µ???da? s???????sµ??.
  • ???????e? ? stad?a?? afa??es? s?µί???? ap? t?
    st??ίa µ???? a?t? ?a pe?????e? se ?at?stas? ap?
    t?? ?p??a ????eta? s???e???µ??? e????e?a ??a t?
    s?µί??? s???????sµ?? p?? e?t?p?st??e.
  • ?et? t?? e?t??es? t?? e????e?a? a?t?? ? ??e????
    epa????eta? st?? a?a??t? ??a t? s?????s? t??
    d?ad??as?a?.

114
??t?p?sµ?? ?????? st?? a????s? LR V?
  • ??????? se ep?ped? f??s??
  • ???pe? ??? ap?? ?a e?t?p?s?e? t? ?????, a??? ?a
    ???e? ?a? a?a?????s? t?? ?????? p?? e?t?p?s???e.
  • ? a?????? ap?ί??pe? e?te st?? t??p?p???s? t??
    ????f?? t?? st??ίa?, e?te st?? t??p?p???s? t??
    s?µί???? e?s?d?? p?? p???????ta?, ??a t??
    ap??s??pt? s?????s? t?? a????s??.
  • ??a p??s????s? a?t?? t?? t?p?? ?a?a?t????eta? ap?
    t? ??s?? ?a pe?????e? ? a????s? se at??µ??a
    ί????.
  • S???st??ta? te??????
  • p?? e?????ta? t?? afa??es? ap? t? s?µί???se???
    e?s?d?? ? t?? ???s? st? st??ίa t??????st? µ?a?
    ?e????? µ???da?
  • e?????ta? t? ?de?asµa t?? st??ίa? µe t??
    ????????s? t?? a?????s?? t?? s?µί???se????
  • de? afa????? ap? t? st??ίa µ? te?µat??? s?µί??a
    ?a? t?? a?t?st???e? ?atast?se??, p?? ????? ?d?
    a?a?????s?e?

115
??t?p?sµ?? ?????? st?? a????s? LR V??
  • ??????? ?a??? se a?a??t?? t?? byacc
  • ???p?p????µe t? ??aµµat??? p??s??t??ta? ?a???e?
    pa?a????? ??a ????, t?? µ??f??
  • µ? te?µat??? error µ???de?_s???????sµ??
  • ?p?? error ? ?e?d?µ???da ?????? t?? byacc.
  • ?et? t?? e?t?p?sµ? ?????? (?e?? ??s? st?? p??a?a
    e?e??e???) t? byacc afa??e? ap? t? st??ίa ?sa
    s?µί??a ??e???eta?, ?ste a?t? ?a pe?????e? se
    ?at?stas?, p?? pe????e? ??a t??????st? st???e??
    p??e???µe?? ap? ?a???a ??????, µe t?? te?e?a
    t?p??et?µ??? sta a??ste?? t?? ?e?d?µ???da? error.
  • St? s????e?a ? a?a??t?? ??e? st? st??ίa t? µ???da
    error, ?? a? a?t? ?ta? µ?a t?p??? pe??pt?s?
    s?µί???? e?s?d??.
  • ?? st?? ?a???a ?????? de? ??e? d????e? ??p??a
    µ???da s???????sµ??, t?te ? a?a??t?? p??????e?
    ?µesa se ap??p???s? s?µf??a µe a?t?? ?a? e?te?e?
    t?? e????e?e? p?? t? s???de????.
  • ? d?ad??as?a s??e???e? a?????ta? ??a ?
    pe??ss?te?a s?µί??a e?s?d??, µ???? t?? e?t?p?sµ?
    e?e????, ??a t? ?p??? ? p??a?a? e?e??e??? ????e?
    t? ep?µe?? e????e?a t?? a????s??.

116
??t?p?sµ?? ?????? st?? a????s? LR V???
  • ???????G?? G????????? ???T?????O? ??F??S?O?
  • G??f??µe t?? te?e?ta?? ?a???a t?? ??aµµat??? µ?sa
    st? byacc ?? e???
  • paragontas ARITHMOS 1
  • ( ekfrasi ) 2
  • error 0

(1) ??f?as? ??f?as? ????. (2) ??f?as?
??f?as? - ????. (3) ??f?as? ????. (4) ????
???? pa?????ta?. (5) ???? ???? /
pa?????ta?. (6) ???? pa?????ta?. (7) pa?????ta?
( ??f?as? ). (8) pa?????ta? a???µ??.
117
??t?p?sµ?? ?????? st?? a????s? LR IX
  • ???????G?? G????????? ???T?????O? ??F??S?O?
    (s????e?a)
  • s?µe??s? st?? pa?ap??? a????s? ?? p??a?e? t??
    a????s?? e??a? ?? LALR(1) p??a?e? p?? pa???e? t?
    byacc ?a? ??? a?t?? p?? ???s?µ?p???saµe se
    p??????µe?a pa?ade??µata

118
??t?p?sµ?? ?????? st?? a????s? LR X
  • s?µa?t??? ?ept?µ??e?a
  • ?et? t?? e?t??es? ap??p???s?? s?µf??a µe ?a???a
    ?????? ? a?a??t?? de? e?t?p??e? ???? ?????
    (a???e? t? ?e?d?µ???da error) a? p??????µ???? de?
    ??e? e?te??se? t?e?? d?ad?????? e????e?e? ???s??
    se ?a?????? ?e?t?????a.
  • ??t? ???eta? ??a ?a ap?fe??eta? ? e?t?p?sµ??
    d?ad?d?µe??? (p?asµat????) ?a??? ?a? ??µe ?t?
    t?te ? a?a??t?? s??e???e? t? ?e?t?????a t?? se
    ?at?stas? ??????.
  • ???pe? ? d?a?e???s? ?a??? ?a ???eta? µe t?t???
    t??p? ?ste ? epa?af??? t?? µeta???tt?st? se
    ?a?????? ?e?t?????a ?a ???eta? µet? ap? a?????s?
    e??? e?????? a???µ?? s?µί???? ?a? ??? af?? ??e?
    d?aίas?e? ??a µe???? µ???? t?? p?????µµat?? ?????
    ??s?ast??? ? a?a??t?? ?a ??e? t? d??at?t?ta
    e?t?p?sµ?? ?a???.
  • ?ta? de? ?p???e? ???d???? e?t?p?sµ?? d?ad?d?µe???
    ?a??? µp??e?te ?a ???s?µ?p??e?te t? macro
    yyerrok, p?? epa?af??e? t?? a?a??t? se ?a??????
    ?e?t?????a ????? ?a ??e? p??????e? ? e?t??es?
    t???? e?e??e??? ???s??.

119
??t?p?sµ?? ?????? st?? a????s? LR X?
  • ???S???
  • ?? st? p??????µe?? pa??de??µa ???faµ
  • paragontas ARITHMOS 1
  • ( ekfrasi ) 2
  • error
  • yyerrok
  • 0
  • t?te ? a????s? t?? s?µί???se???? 27 8 ?d??e?ta?
    se ??a? at??µ??a ί???? e?t?p?s?? t?? µ???µat??
  • syntax error

120
??t?p?sµ?? ?????? st?? a????s? LR X
  • pe??pt?s? p?? ? ???s? t?? yyerrok e??a? ep?fe???
  • while_statement WHILE expr DO statement DONE
  • exec_do_while(2,4)
  • error DONE
  • yyerror(Bad WHILE syntax)
  • yyerrok
  • NULL
  • ???? d??at?t?ta ?a a?????e? t? s?µί??? e?s?d??,
    p?? p???a?e? t?? e?t?p?sµ? ?????? ?a? ?a
    s??e??s?e? ? a????s? µe t? s?µί??? p?? a?????e?.
    G?a ?a ???e? a?t? ???s?µ?p??e?te t? macro
    yyclearin

121
??t?p?sµ?? ?????? st?? a????s? LR XI
  • St? pa??de??µa t?? p??????µe??? d?af??e?a? ?
    ?a???a? ?????? s???de?eta? ap? µ???da
    s???????sµ??. ??? a?t?d?? ? a?a??t?? se µ?a
    t?t??a pe??pt?s?
  • ?? byacc a???e? ?sa s?µί??a e?s?d?? ??e???eta?,
    µ???? t?? e?t?p?sµ? ??p???? p?? e?te e??a? µ?a
    ap? t?? µ???de? s???????sµ??, e?te µp??e?
    d???t??? ?a ap??p????e? se ??p??? ap? a?t? (a?
    a?t? e??a? µ? te?µat???).
  • ??te t? s???e???µ??? s?µί??? ??e?ta? st? st??ίa,
    ?p?te ? a????s? µp??e? (se ??a ? pe??ss?te?a
    ί?µata) ?a e?te??se? ap??p???s? s?µf??a µe t??
    ?a???a t?? ?????? ?a? ?a s??e??se? t?? p??e?a
    t??.
Write a Comment
User Comments (0)
About PowerShow.com