![]() Example: int main() else S3 shift-reduce conflict A quick tutorial on yacc Int yyparse() Called once from main() Repeatedly calls yylex() until done: On syntax error, calls yyerror() Returns 0 if all of the input was processed Returns 1 if aborting due to syntax error. ![]() Using Yacc lexical rules grammar rules y.output flex yacc describes states, transitions of parser (useful for debugging) “yacc -v” “yacc -d” y.tab.h lex.yy.c y.tab.c yylex() yyparse() tokens parsed input input A quick tutorial on yacc Yacc determines integer representations for tokens: Communicated to scanner in file y.tab.h use “yacc -d” to produce y.tab.h Token encodings: “end of file” represented by ‘0’ a character literal: its ASCII value other tokens: assigned numbers 257. Scanner: return value indicates the type of token found other values communicated to the parser using yytext, yylval (see man pages). ![]() Parser assumes the existence of a function ‘int yylex()’ that implements the scanner. ![]() Output: C code implementing a parser: function: yyparse() file : y.tab.c Input: a set of grammar rules and actions yacc (or bison) A quick tutorial on yacc Yacc: Overview Parser generator: Takes a specification for a context-free grammar. 1 Saumya Debray The University of Arizona Tucson, AZ 85721Ī brief yacc tutorial Saumya Debray The University of Arizona Tucson, AZ 85721
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |