Compiler Design A Compact Guide To Lex and Yacc编译器设计和的简明指南.pdfVIP

  • 14
  • 0
  • 约6.65万字
  • 约 39页
  • 2018-04-08 发布于四川
  • 举报

Compiler Design A Compact Guide To Lex and Yacc编译器设计和的简明指南.pdf

A COMPACT GUIDE TO LEX YACC by Thomas Niemann Contents Contents 2 Preface 3 Introduction 4 Lex 6 Theory 6 Practice 7 Yacc 11 Theory 11 Practice, Part I 12 Practice, Part II 15 Calculator 18 Description 18 Include File 21 Lex Input 22 Yacc Input 23 Interpreter 26 Compiler 27 Graph 29 More Lex 33 Strings 33 Reserved Words 34 Debugging Lex 34 More Yacc 35 Recursion 35 If-Else Ambiguity 35 Error Messages 36 Inherited Attributes 37 Embedded Actions 37 Debugging Yacc 38 Bibliography 39 2 Preface This document explains how to construct a compiler using lex and yacc. Lex and yacc are tools used to generate lexical analyzers and parsers. I assume you can program in C, and understand data structures such as linked-lists and trees. The introduction describes the basic building blocks of a compiler and explains the interaction between lex and yacc. The next two sections describe lex and yacc in more detail. With this background, we construct a sophisticated calculator. Conventional arithmetic operations and control statements, such as if-else and while, are implemented. With minor changes, we convert the calculator into a compiler for a stack-based machine. The remaining sections discuss issues that commonly arise in compiler writing. Source code for examples may be downloaded from the web site listed below. Permission to reproduce portions of this document is given provided the web site listed below is referenced, and no additional restrictions apply. Source code, when part of a software project, may be used freely without reference to the author. THOMAS NIEMANN Portland, Oregon web site:

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档