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> (<ID>{,<ID>}); <block>{;<proc>}
<body>→begin <statement>{;<statement>}end
<statement>→<id>: = <exp>
|if <lexp> then <statement>[else <statement>]
|while <lexp> do <statement>
|call <id>[(<EXP>{,<EXP>})]
|<body>
|read (<ID>{,<ID>})
|write (<EXP>{,<EXP>})
<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)
<INTEGER>→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: