![]() Input: ab output: input: aa output: syntax error input: ba output: 14 syntax errorģ5 How the parser works Yacc turns the specification file into a C program which parses the input according to the specifications given Start rule.Ĩ Yacc Format of a production rule: symbol: definition ![]() Variables (nonterminals): syntactical elements, 3. Terminals: tokens and literal characters, 2. Reads a specification file that codifies the grammar of a language and generates a parsing routineħ Yacc Yacc specification describes a Context Free Grammar (CFG), that can be used to generate a parser. Yacc stands for Yet Another Compiler to Compiler. – then x * / + 3 while x y z then The parser must distinguish between valid and invalid sequences of tokens We need context free grammars. Parser input (tokens) IF ID = ID THEN INT ELSE INT FI Parser output (tree) Slide credit: Wes Weimerĥ The Role of the Parser Not all sequences of tokens are programs Output: parse tree of the program Also called an abstract syntax tree Output: error if the input is not valid – e.g., “parse error on line 3" Slide credit: Wes WeimerĤ Example Cool program text if x = y then 1 else 2 fi Input: sequence of tokens from lexer – e.g., the lex files you will write in the 1st phase of your course project. ![]() Phase Input Output Lexer Sequence of characters Sequence of tokens Parser Parse tree Lex is a tool for writing lexical analyzers. Presentation on theme: "Yacc."- Presentation transcript:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |