编译原理: 做一个LL(1)语法分析器

最终效果

输入

结果

实验语言

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>
            
  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值