Design and implementation of pl/0 language lexical and grammatical analysis system

Source: Internet
Author: User

Absrtact: This paper introduces the design and implementation of a pl/0 language lexical and grammatical analysis system.

Keywords: cyclic branching recursive descent pipeline output redirection

Now the compiler system is the IDE (integrated Development Environment) and the compiler independent implementation, they communicate through the pipeline, this system is also implemented by this method. I first give the grammar of the pl/0 language in this article:

BNF description of the pl/0 language (expanded Basque paradigm notation)<prog>→program <id>;<block>
<block>→[<condecl>][<vardecl>][<proc>]<body>
<condecl>→const <const>{,<const>}
<const>→<id>:=<integer>
<vardecl>→var <id>{,<id>}
<proc>→procedure <id> (&LT;ID&GT;{,&LT;ID&GT;}); <block>{;<proc>}
<body>→begin <statement>{;<statement>}end
<statement>→<id>: = <exp>
|if <lexp> then <statement>[else <statement>]
|while <lexp> do <statement>
|call <id>[(&LT;EXP&GT;{,&LT;EXP&GT;})]
|<body>
|read (&LT;ID&GT;{,&LT;ID&GT;})
|write (&LT;EXP&GT;{,&LT;EXP&GT;})
<lexp>→<exp> <lop> <exp>|odd <exp>
<exp>→[+|-]<term>{<aop><term>}
<term>→<factor>{<mop><factor>}
<factor>→<id>|<integer>| (<exp>)
<lop>→=|<>|<|<=|>|>=
<aop>→+|-
<mop>→*|/
<id>→l{l|d} (Note: l denotes letters)
&LT;INTEGER&GT;→D{D}

Comments:

<prog>:程序 ;<block>:块、程序体 ;<condecl>:常量说明 ;<const>:常量;
<vardecl>:变量说明 ;<proc>:分程序 ; <body>:复合语句 ;<statement>:语句;
<exp>:表达式 ;<lexp>:条件 ;<term>:项 ; <factor>:因子 ;<aop>:加法运算符;
<mop>:乘法运算符; <lop>:关系运算符
odd:判断表达式的奇偶性。

Here we first look at the lexical and grammatical analyzer design and implementation. The lexical analysis is implemented by the cyclic branching method, and the grammatical analysis is realized by recursive descent. Their program flowchart is as follows:

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: info-contact@alibabacloud.com 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.