diff options
| -rw-r--r-- | elymas/lib/parser.ey | 35 | ||||
| -rw-r--r-- | elymas/loaded.ey | 1 | ||||
| -rw-r--r-- | elymas/shared.ey | 1 | ||||
| -rw-r--r-- | examples/working-loaded/parser.test | 26 |
4 files changed, 47 insertions, 16 deletions
diff --git a/elymas/lib/parser.ey b/elymas/lib/parser.ey index 1d9636e..0afceba 100644 --- a/elymas/lib/parser.ey +++ b/elymas/lib/parser.ey @@ -1,6 +1,14 @@ < - { =*body { 0 ==again { 1 =again } body again } { } loop } /redoing deffst - { =*wasNew ==m ==k k m .has not { 1 k m =[] wasNew } rep } /enlarge deffst + { =*body { 0 ==again { 1 =again } body again } { } loop } /redoing deffd + { =*wasNew ==m ==k k m .has not { 1 k m =[] wasNew } rep } /enlarge deffd + < + 0 10 range { ==i + { .states i { 0 -01* } rep 2 -01* } i txt .produce .u } + { defmd }' ; each + + { < ==states > } + > -- /children deffd + 0 10 range { _ { { 0 -01* } rep 2 -01* }_ -01 txt .produce .u deffd }' each { [ ] ==rules 0 ==nextNonTerminalName @@ -174,7 +182,7 @@ "n" nt cat ==label label outgoing .has { label outgoing * itemsetIndices * ==target - { ==states [ 0 states * target ] } + { [ target -1302 ] } } { |unexpectedNonterminal } ? * nt actions =[] } each } rep @@ -193,18 +201,19 @@ [ { "t" t cat outgoing .has } { "t" t cat outgoing * itemsetIndices * ==target - { [ -01 target ] 0 } t actions =[] + { [ target -1302 ] 0 } t actions =[] # 0 => lookahead consumed, quit statemachine loop } { itemset t canReduce } { ==rule 0 rule * .name ==nt 1 rule * len ==tokill - { ==states - # rule dump # DEBUG + 2 rule * =*reduceAction + { -- ==states # value dropped + states reduceAction ==value tokill { 0 states * =states }' rep states len 0 gt { nt 1 states * nonterminalActions * * =*action - states action =states + states value action =states # states len 0 gt { # DEBUG # 1 states * theItemSets * dumpItemSet @@ -221,21 +230,15 @@ < { - [ [ ] 0 ] ==states - { ==lookahead + [ [ ] 0 0 ] ==states + { ==lookahead ==value # 1 states * theItemSets * dumpItemSet # DEBUG # [ "received: " lookahead ] |cat fold dump # DEBUG - { states + { states value lookahead 1 states * terminalActions * * * -01 =states states len and } { } loop - - states len 0 eq { - lookahead "" eq { - # "parse done" dump # DEBUG - } { "parse failed" dump } ? * - } rep } } /run deffst > diff --git a/elymas/loaded.ey b/elymas/loaded.ey index b422637..0e8ef86 100644 --- a/elymas/loaded.ey +++ b/elymas/loaded.ey @@ -22,6 +22,7 @@ "lib/wrapper.ey" "lib/sort.ey" "lib/crypt.ey" + "lib/parser.ey" ] { _ dump include }' each { diff --git a/elymas/shared.ey b/elymas/shared.ey index 0770612..ab65273 100644 --- a/elymas/shared.ey +++ b/elymas/shared.ey @@ -23,6 +23,7 @@ "lib/wrapper.ey" "lib/sort.ey" "lib/crypt.ey" + "lib/parser.ey" ] { _ dump include }' each { diff --git a/examples/working-loaded/parser.test b/examples/working-loaded/parser.test new file mode 100644 index 0000000..8af1003 --- /dev/null +++ b/examples/working-loaded/parser.test @@ -0,0 +1,26 @@ +parser .lalr1 ":" via + +/S :nonterminal ==S +/expr :nonterminal ==expr +/num :nonterminal ==num + +999 ==result +S [ expr ] { :0 _ =result } :rule +expr [ num ] { :0 } :rule +expr [ expr "+" expr ] { ==s s :2 s :0 add } :rule +expr [ expr "-" expr ] { ==s s :2 s :0 sub } :rule +expr [ "(" expr ")" ] { ==s s :1 } :rule +num [ /0 ] { -- 0 } :rule +num [ /1 ] { -- 1 } :rule +num [ /2 ] { -- 2 } :rule + +S :automaton ==Sparser + +"generation done" dump + +100000 { + Sparser .run =*consume + [ "(" /2 "+" /1 "-" /1 ")" "+" /1 "" ] { _ consume } each +} rep + +result dump |
