Reading dragon Book compiling Principles of Grammar Analysis (15) ...

Source: Internet
Author: User

Here the lexical analysis module is nearing the end, the following analysis of the Word method is summarized:

Recursive descent is essentially a top-down analysis algorithm, suitable for manual coding, which is relatively more flexible, and can be more flexible for specific DSL processing optimization, but relatively slow. The auto generator is the opposite, followed by an instance of the LR (1) syntax generator-YACC.

First this is the structure of the source file required by YACC, by entering this file Yacc can generate the actual parser code for us ...

It can be seen from the figure that the file is divided into three parts, the following is the instance code:

1%{2#include <stdio.h>3#include <stdlib.h>4     intYylex ();5     voidYyerror (Char*err);6%}7 8%left'+'9 Ten%% One  A Lines:line -|line lines; -  theLine:exp'\ n'; - exp:n -| Exp'+'exp; -  +N:'1' -|'2' +|'3' A|'4' at|'5' -|'6' -|'7' -|'8' -|'9' -|'0' ; in  -%% to  + intYylex () { -     returnGetChar (); the } *  $ voidYyerror (Char*err) {Panax Notoginsengprintf"%s\n", err); - } the  + intMain (intargcChar*argv[]) { A yyparse (); the     return 0; +}

Here is the output structure:

[Wind @gcc~] $./a.out2+3+43+4  2+

That's about it.

Reading dragon Book compiling Principles of Grammar Analysis (15) ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.