Skip to content

🔪 OPG (Operator Precedence Grammar) Parser, in Coq.

License

Notifications You must be signed in to change notification settings

MisakaCenter/OPG_Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OPG_Parser

🔪 Operator Precedence Grammar Parser, in Coq.

Course Project for Compiler Principle (SJTU-CS308-2021)

Features

  • Grammar Parser (in Haskell)
  • Grammar Checker (in Coq)
  • Operator Precedence Analysis Table Generator (in Coq)
  • File IO and Pretty Printer (in Haskell)
  • Shell (in Haskell)

Demo

The file "in1.txt" contains an operator precedence grammar, shown as follows:

E -> E + T | T
T -> T * F | F
F -> ( E ) | i

The program can parse the grammar and output its analysis table:

2N1Y90.png

The file "in1.txt_output.md" contains the analysis table:

+ * ( ) i $
+ > < < > < >
* > > < > < >
( < < < = <
) > > > >
i > > > >
$ < < < < =

How to build

To build the program, you need to install Colourista via stack

  stack install colourista

Then you can use GHCi/GHC to run/compile the program

  stack runhaskell Main.hs

or

  stack ghc -- -O2 Main.hs

or

  make

Tests

Test 1:

E -> E + T | T
T -> T * F | F
F -> ( E ) | i

Test 2:

E -> E + E | E * E | ( E ) | id

Test 3:

E -> E + T | T
T -> T * F | F
F -> ( E E ) | i

Here is the result:

2N1t3V.png

License

MIT

Acknowledgements

About

🔪 OPG (Operator Precedence Grammar) Parser, in Coq.

Topics

Resources

License

Stars

Watchers

Forks