Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. mathewmoon created this gist Jul 26, 2019.
    273 changes: 273 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,273 @@
    Created by PLY version 3.11 (http://www.dabeaz.com/ply)

    Grammar

    Rule 0 S' -> expression
    Rule 1 expression -> STRING MATCH STRING
    Rule 2 expression -> NUMBER EQUALS NUMBER
    Rule 3 expression -> STRING EQUALS STRING
    Rule 4 expression -> STRING EQUALS NUMBER
    Rule 5 expression -> NUMBER EQUALS STRING
    Rule 6 expression -> NUMBER GT NUMBER
    Rule 7 expression -> NUMBER LT NUMBER
    Rule 8 expression -> NUMBER BETWEEN NUMBER NUMBER
    Rule 9 expression -> NUMBER LT_OR_EQ NUMBER
    Rule 10 expression -> NUMBER GT_OR_EQ NUMBER
    Rule 11 expression -> NUMBER NOT_EQUALS NUMBER
    Rule 12 expression -> STRING NOT_EQUALS NUMBER
    Rule 13 expression -> NUMBER NOT_EQUALS STRING

    Terminals, with rules where they appear

    BETWEEN : 8
    EQUALS : 2 3 4 5
    GT : 6
    GT_OR_EQ : 10
    LT : 7
    LT_OR_EQ : 9
    MATCH : 1
    NOT_EQUALS : 11 12 13
    NUMBER : 2 2 4 5 6 6 7 7 8 8 8 9 9 10 10 11 11 12 13
    STRING : 1 1 3 3 4 5 12 13
    error :

    Nonterminals, with rules where they appear

    expression : 0

    Parsing method: LALR

    state 0

    (0) S' -> . expression
    (1) expression -> . STRING MATCH STRING
    (2) expression -> . NUMBER EQUALS NUMBER
    (3) expression -> . STRING EQUALS STRING
    (4) expression -> . STRING EQUALS NUMBER
    (5) expression -> . NUMBER EQUALS STRING
    (6) expression -> . NUMBER GT NUMBER
    (7) expression -> . NUMBER LT NUMBER
    (8) expression -> . NUMBER BETWEEN NUMBER NUMBER
    (9) expression -> . NUMBER LT_OR_EQ NUMBER
    (10) expression -> . NUMBER GT_OR_EQ NUMBER
    (11) expression -> . NUMBER NOT_EQUALS NUMBER
    (12) expression -> . STRING NOT_EQUALS NUMBER
    (13) expression -> . NUMBER NOT_EQUALS STRING

    STRING shift and go to state 2
    NUMBER shift and go to state 3

    expression shift and go to state 1

    state 1

    (0) S' -> expression .



    state 2

    (1) expression -> STRING . MATCH STRING
    (3) expression -> STRING . EQUALS STRING
    (4) expression -> STRING . EQUALS NUMBER
    (12) expression -> STRING . NOT_EQUALS NUMBER

    MATCH shift and go to state 4
    EQUALS shift and go to state 5
    NOT_EQUALS shift and go to state 6


    state 3

    (2) expression -> NUMBER . EQUALS NUMBER
    (5) expression -> NUMBER . EQUALS STRING
    (6) expression -> NUMBER . GT NUMBER
    (7) expression -> NUMBER . LT NUMBER
    (8) expression -> NUMBER . BETWEEN NUMBER NUMBER
    (9) expression -> NUMBER . LT_OR_EQ NUMBER
    (10) expression -> NUMBER . GT_OR_EQ NUMBER
    (11) expression -> NUMBER . NOT_EQUALS NUMBER
    (13) expression -> NUMBER . NOT_EQUALS STRING

    EQUALS shift and go to state 7
    GT shift and go to state 8
    LT shift and go to state 9
    BETWEEN shift and go to state 10
    LT_OR_EQ shift and go to state 11
    GT_OR_EQ shift and go to state 12
    NOT_EQUALS shift and go to state 13


    state 4

    (1) expression -> STRING MATCH . STRING

    STRING shift and go to state 14


    state 5

    (3) expression -> STRING EQUALS . STRING
    (4) expression -> STRING EQUALS . NUMBER

    STRING shift and go to state 15
    NUMBER shift and go to state 16


    state 6

    (12) expression -> STRING NOT_EQUALS . NUMBER

    NUMBER shift and go to state 17


    state 7

    (2) expression -> NUMBER EQUALS . NUMBER
    (5) expression -> NUMBER EQUALS . STRING

    NUMBER shift and go to state 18
    STRING shift and go to state 19


    state 8

    (6) expression -> NUMBER GT . NUMBER

    NUMBER shift and go to state 20


    state 9

    (7) expression -> NUMBER LT . NUMBER

    NUMBER shift and go to state 21


    state 10

    (8) expression -> NUMBER BETWEEN . NUMBER NUMBER

    NUMBER shift and go to state 22


    state 11

    (9) expression -> NUMBER LT_OR_EQ . NUMBER

    NUMBER shift and go to state 23


    state 12

    (10) expression -> NUMBER GT_OR_EQ . NUMBER

    NUMBER shift and go to state 24


    state 13

    (11) expression -> NUMBER NOT_EQUALS . NUMBER
    (13) expression -> NUMBER NOT_EQUALS . STRING

    NUMBER shift and go to state 25
    STRING shift and go to state 26


    state 14

    (1) expression -> STRING MATCH STRING .

    $end reduce using rule 1 (expression -> STRING MATCH STRING .)


    state 15

    (3) expression -> STRING EQUALS STRING .

    $end reduce using rule 3 (expression -> STRING EQUALS STRING .)


    state 16

    (4) expression -> STRING EQUALS NUMBER .

    $end reduce using rule 4 (expression -> STRING EQUALS NUMBER .)


    state 17

    (12) expression -> STRING NOT_EQUALS NUMBER .

    $end reduce using rule 12 (expression -> STRING NOT_EQUALS NUMBER .)


    state 18

    (2) expression -> NUMBER EQUALS NUMBER .

    $end reduce using rule 2 (expression -> NUMBER EQUALS NUMBER .)


    state 19

    (5) expression -> NUMBER EQUALS STRING .

    $end reduce using rule 5 (expression -> NUMBER EQUALS STRING .)


    state 20

    (6) expression -> NUMBER GT NUMBER .

    $end reduce using rule 6 (expression -> NUMBER GT NUMBER .)


    state 21

    (7) expression -> NUMBER LT NUMBER .

    $end reduce using rule 7 (expression -> NUMBER LT NUMBER .)


    state 22

    (8) expression -> NUMBER BETWEEN NUMBER . NUMBER

    NUMBER shift and go to state 27


    state 23

    (9) expression -> NUMBER LT_OR_EQ NUMBER .

    $end reduce using rule 9 (expression -> NUMBER LT_OR_EQ NUMBER .)


    state 24

    (10) expression -> NUMBER GT_OR_EQ NUMBER .

    $end reduce using rule 10 (expression -> NUMBER GT_OR_EQ NUMBER .)


    state 25

    (11) expression -> NUMBER NOT_EQUALS NUMBER .

    $end reduce using rule 11 (expression -> NUMBER NOT_EQUALS NUMBER .)


    state 26

    (13) expression -> NUMBER NOT_EQUALS STRING .

    $end reduce using rule 13 (expression -> NUMBER NOT_EQUALS STRING .)


    state 27

    (8) expression -> NUMBER BETWEEN NUMBER NUMBER .

    $end reduce using rule 8 (expression -> NUMBER BETWEEN NUMBER NUMBER .)