Giter VIP home page Giter VIP logo

glr-glalr-parser-generator's Introduction

GLR-GLALR-Parser-Generator

GLR(1) - GLALR(1) parser generator.

parser_generator_lib

  • analyze_lexical(lexical_fsm, keywords, code) -> tokens_and_lexemes
  • analyze_syntax(initial_nonterminal, lr_table, tokens_and_lexemes, tokens_to_skip) -> history
  • lr_tableebnf_to_lr_table = convert_to_bnf + construct_first_sets + construct_lr_closure_table + construct_lr_table

You can build lr table from the extended Backus-Naur form (ebnf_to_lr_table).

C90 parser example

C90 syntax is from Kernighan, Brian; Ritchie, Dennis M. (March 1988). The C Programming Language (2nd ed.). Englewood Cliffs, NJ: Prentice Hall. ISBN 0-13-110362-8.

python run_example.py

Or more customizable:

python c90_parser.py --paths c90_examples/not_exist.c c90_examples/normal.c c90_examples/lexical_error.c c90_examples/syntax_error.c --glalr -v

Output:

C:\Users\quint\PycharmProjects\GLR-GLALR-Parser-Generator\c90_examples\not_exist.c [Errno 2] No such file or directory: 'C:\\Users\\quint\\PycharmProjects\\GLR-GLALR-Parser-Generator\\c90_examples\\not_exist.c'
====================================================
===================== normal.c =====================
Lexical Analysis: Success
Syntax Analysis: Success

====================================================
================= lexical_error.c ==================
Lexical Analysis: [code_startswith: 'привет' | symbol: 'п' | line: 5]
====================== Error =======================
====================================================

====================================================
================== syntax_error.c ==================
Lexical Analysis: Success
Syntax Analysis: [message: "Unexpected lexeme }. Expected any of: {';', ':', ',', ')', ']'}" | position: '30:0']
====================== Error =======================
====================================================

usage: c90_parser [-h] -p PATHS [PATHS ...] (--glr | --glalr) [--l-history]
                  [--p-history] [-v] [--debug-args]

C90 Parser

options:
  -h, --help            show this help message and exit
  -p PATHS [PATHS ...], --paths PATHS [PATHS ...]
                        paths to dirs/files [example: `/path/to/dir /path/to/file`]
  --glr                 use GLR(1) parser generator
  --glalr               use GLALR(1) parser generator
  --l-history           show lexical history
  --p-history           show syntax parsing history
  -v, --verbose         verbose mode
  --debug-args          debug mode

glr-glalr-parser-generator's People

Contributors

quint-t avatar

Watchers

 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.