本文实现了简易LL1语法分析器
最终效果
实验语言
html、css、js
实验环境
Visual Studio Code、Google Chrome
设计概要
输入一组符合LL(1)文法的产生式,分析出其first集、follow集,并且构造其预测分析表,最后用此预测分析表判断某串是否符合此组产生式的规则。
补充
-
由于作业时间仓促,因此 此语法分析器还有
许多不足之处,例如:
- 1.没有分析输入文法是否是LL(1)文法、
- 2.没有做第四部分输入串的显示(只能在源代码里填写)
- 3.代码优化等
- 4.敬请大佬指正
代码
关于first集、follow集、预测分析表、串的分析匹配这四个模块的具体构建思路这里就不贴了,可移步其他博主的相关文章查看。如对本文代码有疑惑,欢迎评论、私信…
PS:本人不保证随时都在,但是看见必回。
代码1— index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
//样式部分
<style>
*{
padding: 0;
margin: 0 auto;
}
div{
width: 500px;
height: 1000px;
position: relative;
left: -165px;
}
.input_num{
display: block;
position: absolute;
z-index: 100;
width: 500px;
height: 50px;
line-height: 50px;
text-align: center;
left: 150px;
top: 7px;
}
.input_num input{
display: block;
width: 100px;
height: 30px;
border-radius: 17px;
outline: none;
border: 1px solid gray;
padding: 0 10px;
position: absolute;
left: 205px;
top: 7px;
text-align: center;
}
.text{
display: block;
width: 170px;
height: 30px;
line-height: 30px;
text-align: center;
position: absolute;
left: 40px;
top: 7px;
}
.submit{
display: block;
width: 50px;
height: 26px;
line-height: 26px;
text-align: center;
background-color: pink;
opacity: .7;
position: absolute;
left: 355px;
top: 9px;
border-radius: 15px;
font-size: .5em;
cursor: pointer;
}
.input_pro{
width: 500px;
height: auto;
position: absolute;
top: 80px;
left: 150px;
}
ul,li{
list-style: none;
}
ul{
width: 300px;
height: auto;
border: 3px solid gray;
border-radius: 20px;
font-size: 16px;
padding: 10px 20px 40px 20px;
display: none;
}
li{
width: 100%;
height: 40px;
}
.head{
height: 30px;
line-height: 30px;
}
ul li span{
display: block;
width: 150px;
height: 30px;
line-height: 30px;
text-align: center;
float: left;
}
ul li span input{
width: 90px;
height: 30px;
padding: 0 10px;
border: none;
border-bottom: 1px solid gray;
outline: none;
text-align: center;
}
.submit_pro{
display: block;
width: 50px;
height: 26px;
line-height: 26px;
text-align: center;
background-color: pink;
opacity: .7;
position: absolute;
left: 355px;
top: 367px;
border-radius: 15px;
font-size: .5em;
cursor: pointer;
}
</style>
</head>
<body>
<div>
<div class="input_num">
<span class="text">请输入产生式的个数:</span>
<input type="text" class="getNum">
<span class