1 / 9

LL(1)-Parser

LL(1)-Parser. p rogram -> ’ program’ ’ ( ’ identT ’ ) ’ varlist ’ begin ’ stlist ’ end ’ v arlist ->     type identlist ’ ; ’ t ype ->         ’ float ’ | ’ int ’ i dentlist ->   i dentT identelmlist i dentelmlist -> ’ , ’ identT identelmlist | e

devlin
Download Presentation

LL(1)-Parser

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LL(1)-Parser program-> ’program’ ’(’identT ’)’ varlist ’begin’ stlist ’end’ varlist->     type identlist ’;’ type->         ’float’ | ’int’ identlist->   identT identelmlist identelmlist-> ’,’identT identelmlist | e stlist-> statement stlist | e statement->identT ’=’ exp ’;’ exp->identTbexp | ’(’ exp ’)’ bexp bexp-> ’+’ exp bexp | ’-’ exp bexp | e

  2. rpd.c #include <stdio.h> #include "rpd.h" #include "symtab.h" int nextT; void checkfor(int token) { if (token != nextT) { printf("Syntax Error \n "); exit(0); } else nextT = yylex(); }

  3. rpd.c void program() { checkfor(programT); checkfor('('); checkfor(identT); checkfor(')'); varlist(); checkfor(beginT); stlist(); checkfor(endT); printf("Compilering faerdig. Ingen fejl\n "); }

  4. LL(1)-Parser program-> ’program’ ’(’identT ’)’ varlist ’begin’ stlist ’end’ varlist->     type identlist ’;’ type->           ’float’ | ’int’ identlist->   identT identelmlist identelmlist-> ’,’identT identelmlist | e stlist-> statement stlist | e statement->identT ’=’ exp ’;’ exp->identTbexp | ’(’ exp ’)’ bexp bexp-> ’+’ exp bexp | ’-’ exp bexp | e

  5. rpd.c void type() { if (nextT == floatT) { checkfor(floatT); Ctype= floatT; } else { if (nextT == intT) { checkfor(intT); Ctype= intT; } else { printf("Syntax Error 'int' eller 'float' type forvendtet! \n "); exit(0); } } }

  6. LL(1)-Parser program-> ’program’ ’(’identT ’)’ varlist ’begin’ stlist ’end’ varlist->     type identlist ’;’ type->           ’float’ | ’int’ identlist->   identT identelmlist identelmlist-> ’,’identT identelmlist | e stlist-> statement stlist | e statement->identT ’=’ exp ’;’ exp->identTbexp | ’(’ exp ’)’ bexp bexp-> ’+’ exp bexp | ’-’ exp bexp | e

  7. rpd.c void identelmlist() { if (nextT == ',') { checkfor(','); checkfor(identT); identelmlist(); } }

  8. rpd.c int main() { init_sym(); nextT = yylex(); program(); }

  9. LL(1)-Parser statement->   identT '=' expA ';' expA->            term expBexpB->             termopr term expB | etermopr->   '+' | '-'term->             factor termBtermB->          factoropr factor termB | efactoropr-> '*' | '/'factor->          uopr expA |                       '(' expA ')' |                       realT |                        identTuopr->            '-' | e

More Related