Giter VIP home page Giter VIP logo

parser's Introduction

LALR Parser

项目结构

├─3rd // 空
│  
├─bin  // exe 文件
│  ├─Debug
│  └─Release
├─src
│  ├─cent.sln // 打开
│  ├─codes // 空
│  ├─log   // parsertest 输出的日志文件、分析表的 html 文件
│  ├─parser // 主项目
|  |  ├─parser.cpp 主程序
│  │  ├─include
│  │  └─src
│  └─parsertest // 单元测试
└─temp
    

使用的文法

P' -> Program
Program -> DeclarationList
DeclarationList -> DeclarationList Declaration | Declaration
Declaration -> VarDeclaration | FuncDeclaration

// support type
Type -> int | bool | double

// variable declaration
VarDeclaration -> Type IdList ;
IdList -> IdList VarInit | VarInit
VarInit -> VarId | VarId = SimpleExpr
VarId -> id | id [ const ]

// function declaration
FuncDeclaration -> Type id ( Params ) CompositeStmt
Params -> ParamList | ε
ParamList -> ParamList , P | P
P -> Type ParamId
ParamId -> id | id [ ]

// statements
CompositeStmt ->  { StmtList }
StmtList -> StmtList Stmt | ε
Stmt -> WhileStmt | Expr ; | IfStmt | CompositeStmt | VarDeclaration | ;
IfStmt -> if ( Expr ) Stmt ElseStmt
ElstStmt -> else Stmt | ε
WhileStmt -> while ( Expr ) Stmt

// Expressions
Expr -> Mutable = Expr | SimpleExpr
Mutable -> Mutable [ Expr ] | id
SimpleExpr -> SimpleExpr or AndExpr | AndExpr
AndExpr -> AndExpr and NotExpr | NotExpr
NotExpr -> not NotExpr | RelationExpr
RelationExpr -> SumExpr Relop SumExpr | SumExpr
SumExpr -> SumExpr Sumop MultiExpr | MultiExpr
MultiExpr -> MultiExpr Multiop UExpr | UExpr
UExpr -> Uop UExpr | Factor
Factor -> Immutable | Mutable
Immutable -> ( Expr ) | Call | const
Call -> id ( Args )
Args -> ArgList | ε
ArgList -> ArgList , Expr | Expr

// operators
Relop -> == | != | > | < | >= | <=
Sumop -> + | -
Multiop -> * | / | %
Uop -> * | -	

ToDo

  • 先序输出语法分析树
  • 错误处理
  • 界面
  • FOLLOW集 (?)

parser's People

Contributors

1170500503 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.