From a7358863e27b6a35285af5cd0b9ab92e0255b496 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Fri, 26 Apr 2024 00:38:30 +0200 Subject: [PATCH 01/23] lifted versions of clojure and active-clojure in project.clj --- project.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index dc37e95..5288a34 100644 --- a/project.clj +++ b/project.clj @@ -3,6 +3,6 @@ :url "https://github.com/active-group/lawrence" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.8.0"] - [active-clojure "0.12.0" :exclusions [org.clojure/clojure]]] + :dependencies [[org.clojure/clojure "1.11.10"] + [de.active-group/active-clojure "0.42.2" :exclusions [org.clojure/clojure]]] :profiles {:dev {:dependencies [[org.clojure/tools.trace "0.7.9"]]}}) From 46fb437a0be12cd39844002b5200e1a58b2d4b6f Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Tue, 21 May 2024 09:28:45 +0200 Subject: [PATCH 02/23] initial commit to fork --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 2 + COPYING | 48 + README.md | 7 +- doc/.DS_Store | Bin 0 -> 6148 bytes doc/REFERENCE.md | 94 ++ doc/examples/.DS_Store | Bin 0 -> 6148 bytes doc/examples/essence/toy-grammars-test.scm | 41 + doc/examples/essence/toy-grammars.scm | 83 ++ doc/examples/essence/toy-inputs.scm | 75 ++ .../lawrence/ASS_370_grammar_test.clj | 90 ++ doc/examples/lawrence/Fortran77Lexer.g4 | 310 ++++++ doc/examples/lawrence/Fortran77Parser.g4 | 935 ++++++++++++++++++ doc/examples/lawrence/fortran77.scm | 13 + doc/examples/lawrence/toy-grammars-test.clj | 41 + doc/examples/lawrence/toy-grammars.scm | 83 ++ doc/examples/lawrence/toy-inputs.in | 75 ++ project.clj | 2 +- test/active/lawrence/grammar_test.clj | 12 +- 19 files changed, 1905 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 COPYING create mode 100644 doc/.DS_Store create mode 100644 doc/REFERENCE.md create mode 100644 doc/examples/.DS_Store create mode 100644 doc/examples/essence/toy-grammars-test.scm create mode 100644 doc/examples/essence/toy-grammars.scm create mode 100644 doc/examples/essence/toy-inputs.scm create mode 100644 doc/examples/lawrence/ASS_370_grammar_test.clj create mode 100644 doc/examples/lawrence/Fortran77Lexer.g4 create mode 100644 doc/examples/lawrence/Fortran77Parser.g4 create mode 100644 doc/examples/lawrence/fortran77.scm create mode 100644 doc/examples/lawrence/toy-grammars-test.clj create mode 100644 doc/examples/lawrence/toy-grammars.scm create mode 100644 doc/examples/lawrence/toy-inputs.in diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..58ba788dc668bcbf31febb2548c9d85ed185722b GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8O({YS3Oz1(E!f&pEM7vaFJMFuDm5`hgE3p0)Er77XMG``#OHBl zcLNr47O^w1`_1oe_JiyXV~o4Yu+Nyy7_*=ua#Sh=-Ibx5Nk-&2Mmi5-8G!W>%uVdC z1Acp*g-o)CApidTag=7g-Y2is8#}vAt7)~ZJMT&6Ugl@Z)b$rPXkAJf2c_-@SJ5n= z+WTiR$^0mpEmT1i&LHLXI!Z#ByKEyt+l0AbZyn|v^^Xe^eT z!~iky&lup1i8pa!QRZy@u{=C$1+;r;D418E0s{KRB>)WEM>;B~;{tWaa|{+5aTN5c QazMHWC_<S5Z<-bZYe?!3Oz1(E!f&pEM7vbFJMFuDm5WNgK4%jtrbckXMG``#OHBl zcLSE@;7P>Jz~-BspWU4gvOkP5K9~n>#_EhQ0S%F(QXpt9bnVz+M6Sn}u$YA`^%v=+ zV4%Nf!nF%n^DFb%n0;HnA1fbxAO0kc(pjtZ$#+WS-Mxyah?=-}pVY#gd9!&s@TRxe zyHYClbKUc=qi`{*ADpXX=0!<3)d^7$Lde}slmu!qQ1c{6b*^h1qAIGRdSkil^xI9@ z>7A~ca@jv=HD$NgU9GC(@aXvLa`YUJ6ZK}u $1 $3 + ``` +#### The structure of a rule \ No newline at end of file diff --git a/doc/examples/.DS_Store b/doc/examples/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bc571e39fb845b6e89048d99eb7ade559792a60c GIT binary patch literal 6148 zcmeHK%}N6?5T3NvrWBzE1&;x*1zTH0@v>BX0ax^(Qg`j5i|eNJ$32w7p7n)%5}(JJ zBny`I;7P>JK=MuIC)xR6^8)~)HyyMA8UP@%5eiaP2$@&9N-mgCm^mUy;Q^vB8xL1Z z^cPL^?Gh3QAcGNn`~EP|A^JYTVG@rgt=6X~l`9*YRaupFdFMar%%234>9`k+ZfJC= zbrKeO5MISm)^BW|>U0vsX*4nk@gTyG+v_+T=&Yxw>0oSfed~}lS?f1;XS2?6yQw;d zNAsqd9Uruss(aX-&uemLZ~x??|D3#}`puFlkar_n4hwikWvQ-Lf0QOVeMDc8SHv?i z1Iz$3zznPp1MUov_4O&4D`f_lfgdtJ`-8$p=sCK)o%<5=YCLDxkk$Yx<8CYbXY=;dx z|IhK4S^3CcOyLnTzzqB|21Mn|KkH#p?rdEukIq_!?H(Hm#pR@+puTVkzya+eyT)n# bigb+g9Of2j7P6akM7{_ZLbziFeu05677$GH literal 0 HcmV?d00001 diff --git a/doc/examples/essence/toy-grammars-test.scm b/doc/examples/essence/toy-grammars-test.scm new file mode 100644 index 0000000..9fba94e --- /dev/null +++ b/doc/examples/essence/toy-grammars-test.scm @@ -0,0 +1,41 @@ +; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. + +;; Rudimentary test suite + +(define-test-suite toy-grammars-tests) + +(define-test-case g08 toy-grammars-tests + (check (parse g08 1 'lr 0 i08-1) => #f) + (check (parse g08 1 'slr 0 i08-1) => #f) + (check-exception (parse g08 1 'lr 0 i08-2)) + (check-exception (parse g08 1 'slr 0 i08-2)) + (check-exception (parse g08 1 'lr 0 i08-3)) + (check-exception (parse g08 1 'slr 0 i08-3))) + +(define-test-case g10 toy-grammars-tests + (check (parse g10 1 'lr 0 i10-1) => 147) + (check (parse g10 1 'slr 0 i10-1) => 147) + (check-exception (parse g10 1 'lr 0 i10-2)) + (check-exception (parse g10 1 'slr 0 i10-2)) + (check-exception (parse g10 1 'lr 0 i10-3)) + (check-exception (parse g10 1 'slr 0 i10-3))) + +(define-test-case g10-k=2 toy-grammars-tests + (check (parse g10 2 'lr 0 i10-1) => 147) + (check (parse g10 2 'slr 0 i10-1) => 147) + (check-exception (parse g10 2 'lr 0 i10-2)) + (check-exception (parse g10 2 'slr 0 i10-2)) + (check-exception (parse g10 2 'lr 0 i10-3)) + (check-exception (parse g10 2 'slr 0 i10-3))) + +(define-test-case g10-error toy-grammars-tests + (check (parse g10-error 1 'lr 0 i10e-1) => 147) + (check (parse g10-error 1 'slr 0 i10e-1) => 147) + (check (parse g10-error 1 'lr 0 i10e-2) => 28) + (check (parse g10-error 1 'slr 0 i10e-2) => 28) + (check-exception (parse g10-error 1 'lr 0 i10e-3)) + (check-exception (parse g10-error 1 'slr 0 i10e-3))) + +(define-test-case g14 toy-grammars-tests + (check (parse g14 1 'lr 0 i14-1) => #f) + (check (parse g14 1 'slr 0 i14-1) => #f)) diff --git a/doc/examples/essence/toy-grammars.scm b/doc/examples/essence/toy-grammars.scm new file mode 100644 index 0000000..821f971 --- /dev/null +++ b/doc/examples/essence/toy-grammars.scm @@ -0,0 +1,83 @@ +; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. + +; Balanced parentheses + +(define-grammar g00 g00-symbol + (l) + S + ((S ((l) $1)))) + +(define-grammar g08 g08-symbol + (l r) + S + ((S ((S T) $1) + ((T) $1)) + (T ((l S r) $1) + ((l r) $1)))) + +; Constant arithmetic expressions + +(define-grammar g10 g10-symbol + (+ - * / l r n) + E + ((E ((T) $1) + ((T + E) (+ $1 $3)) + ((T - E) (- $1 $3))) + (T ((P) $1) + ((P * T) (* $1 $3)) + ((P / T) (/ $1 $3))) + (P ((n) $1) + ((l E r) $2)))) + +(define-grammar g10-error g10-error-symbol + (+ - * / l r n) + E + ((E ((T) $1) + (($error) 0) + ((T + E) (+ $1 $3)) + ((T - E) (- $1 $3))) + (T ((P) $1) + ((P * T) (* $1 $3)) + ((P / T) (/ $1 $3))) + (P ((n) $1) + ((l E r) $2) + ((l $error r) 0)))) + +(define-grammar g13 g13-symbol + (comma blah dot) + S + ((SLK (() $1) + ((NESLK) $1)) + (NESLK ((N) $1) + ((NESLK K N) $1)) + (SLD (() $1) + ((NESLD) $1)) + (NESLD ((N) $1) + ((NESLD P N) $1)) + (S ((SLK) $1) + ((SLD) $1)) + (K ((comma) $1)) + (P ((dot) $1)) + (N ((blah) $1)))) + +;; javascript example expanded + +(define-grammar g14 g14-symbol + (const comma colon lcurly rcurly lbracket rbracket) + S + ((S ((E) $1)) + (E ((const) $1) + ((lcurly OL rcurly) $1) + ((lbracket AL rbracket) $1)) + (C ((comma) $1)) + (A ((const colon E) $1)) + (OL (() $1) + ((ON) $1)) + (ON ((A) $1) + ((ON C A) $1)) + (AL (() $1) + ((AN) $1)) + (AN ((E) $1) + ((AN C E) $1)))) + + diff --git a/doc/examples/essence/toy-inputs.scm b/doc/examples/essence/toy-inputs.scm new file mode 100644 index 0000000..b266a9d --- /dev/null +++ b/doc/examples/essence/toy-inputs.scm @@ -0,0 +1,75 @@ +; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. + +(define i08-1 (list (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol r) #f))) + +(define i08-2 (list (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol r) #f))) + +(define i08-3 (list (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol l) #f))) + +(define i10-1 (list (cons (enum g10-symbol l) #f) + (cons (enum g10-symbol n) 4) + (cons (enum g10-symbol +) #f) + (cons (enum g10-symbol n) 17) + (cons (enum g10-symbol r) #f) + (cons (enum g10-symbol *) #f) + (cons (enum g10-symbol n) 7))) + +(define i10-2 (list (cons (enum g10-symbol l) #f) + (cons (enum g10-symbol n) 4) + (cons (enum g10-symbol +) #f) + (cons (enum g10-symbol n) 15) + (cons (enum g10-symbol n) 17) + (cons (enum g10-symbol r) #f) + (cons (enum g10-symbol *) #f) + (cons (enum g10-symbol n) 7))) + +(define i10-3 (list (cons (enum g10-symbol l) #f) + (cons (enum g10-symbol n) 4) + (cons (enum g10-symbol +) #f) + (cons (enum g10-symbol n) 17) + (cons (enum g10-symbol *) #f) + (cons (enum g10-symbol n) 7))) + +(define i10e-1 (list (cons (enum g10-error-symbol l) #f) + (cons (enum g10-error-symbol n) 4) + (cons (enum g10-error-symbol +) #f) + (cons (enum g10-error-symbol n) 17) + (cons (enum g10-error-symbol r) #f) + (cons (enum g10-error-symbol *) #f) + (cons (enum g10-error-symbol n) 7))) + +(define i10e-2 (list (cons (enum g10-error-symbol l) #f) + (cons (enum g10-error-symbol n) 4) + (cons (enum g10-error-symbol +) #f) + (cons (enum g10-error-symbol n) 15) + (cons (enum g10-error-symbol n) 17) + (cons (enum g10-error-symbol r) #f) + (cons (enum g10-error-symbol *) #f) + (cons (enum g10-error-symbol n) 7))) + +(define i10e-3 (list (cons (enum g10-error-symbol l) #f) + (cons (enum g10-error-symbol n) 4) + (cons (enum g10-error-symbol +) #f) + (cons (enum g10-error-symbol n) 17) + (cons (enum g10-error-symbol *) #f) + (cons (enum g10-error-symbol n) 7))) + +(define i14-1 (list (cons (enum g14-symbol lbracket) #f) + (cons (enum g14-symbol const) #f) + (cons (enum g14-symbol rbracket) #f))) diff --git a/doc/examples/lawrence/ASS_370_grammar_test.clj b/doc/examples/lawrence/ASS_370_grammar_test.clj new file mode 100644 index 0000000..6d47e30 --- /dev/null +++ b/doc/examples/lawrence/ASS_370_grammar_test.clj @@ -0,0 +1,90 @@ +(ns active.lawrence.ASS_370_grammar_test + (:require [active.lawrence.grammar :refer :all])) + +(define-grammar RR + (:op :r1 :r2) + S + ((S ((:op) $1) + (:r1) $2 + (:r2) $3))) + +(define-grammar g08 + (:l :r) + S + ((S ((S T) $1) + ((T) $1)) + (T ((:l S :r) $1) + ((:l :r) $1)))) + +; Constant arithmetic expressions + +(define-grammar g10 + (:+ :- :* :/ :l :r :n) + E + ((E ((T) $1) + ((T :+ E) (+ $1 $3)) + ((T :- E) (- $1 $3))) + (T ((P) $1) + ((P :* T) (* $1 $3)) + ((P :/ T) (/ $1 $3))) + (P ((:n) $1) + ((:l E :r) $2)))) + +(define-grammar g10-error + (:+ :- :* :/ :l :r :n) + E + ((E ((T) $1) + ((:$error) 0) + ((T :+ E) (+ $1 $3)) + ((T :- E) (- $1 $3))) + (T ((P) $1) + ((P :* T) (* $1 $3)) + ((P :/ T) (/ $1 $3))) + (P ((:n) $1) + ((:l E :r) $2) + ((:l :$error :r) 0)))) + +(define-grammar g13 + (:comma :blah :dot) + S + ((SLK (() nil) + ((NESLK) $1)) + (NESLK ((N) $1) + ((NESLK K N) $1)) + (SLD (() nil) + ((NESLD) $1)) + (NESLD ((N) $1) + ((NESLD P N) $1)) + (S ((SLK) $1) + ((SLD) $1)) + (K ((:comma) $1)) + (P ((:dot) $1)) + (N ((:blah) $1)))) + +;; javascript example expanded + +(define-grammar g14 + (:const :comma :colon :lcurly :rcurly :lbracket :rbracket) + S + ((S ((E) $1)) + (E ((:const) $1) + ((:lcurly OL :rcurly) $1) + ((:lbracket AL :rbracket) $1)) + (C ((:comma) $1)) + (A ((:const :colon E) $1)) + (OL (() nil) + ((ON) $1)) + (ON ((A) $1) + ((ON C A) $1)) + (AL (() nil) + ((AN) $1)) + (AN ((E) $1) + ((AN C E) $1)))) + +(define-grammar goptional + (:foo :bar) + S + ((S ((:bar O) $2)) + (O ((:foo) :present) + (() :absent)))) + diff --git a/doc/examples/lawrence/Fortran77Lexer.g4 b/doc/examples/lawrence/Fortran77Lexer.g4 new file mode 100644 index 0000000..91e9acc --- /dev/null +++ b/doc/examples/lawrence/Fortran77Lexer.g4 @@ -0,0 +1,310 @@ +/* + * Fortran 77 grammar for ANTLR 2.7.5 + * Adadpted from Fortran 77 PCCTS grammar by Olivier Dragon + * Original PCCTS grammar by Terence Parr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + */ + +/** + * ported to Antlr4 by Tom Everett + */ + +/* + * Updated by Tom Everett, 2018 + */ + +// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false +// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine +// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true + +lexer grammar Fortran77Lexer; + +options { + superClass = Fortran77LexerBase; +} + +// Insert here @header for C++ lexer. + +PROGRAM: 'program' | 'PROGRAM'; + +ENTRY: 'entry' | 'ENTRY'; + +FUNCTION: 'function' | 'FUNCTION'; + +BLOCK: 'block' | 'BLOCK'; + +SUBROUTINE: 'subroutine' | 'SUBROUTINE'; + +END: 'END' | 'end'; + +DIMENSION: 'dimension' | 'DIMENSION'; + +REAL: 'REAL' | 'real'; + +EQUIVALENCE: 'EQUIVALENCE' | 'equivalence'; + +COMMON: 'common' | 'COMMON'; + +POINTER: 'pointer' | 'POINTER'; + +IMPLICIT: 'implicit' | 'IMPLICIT'; + +NONE: 'none' | 'NONE'; + +CHARACTER: 'character' | 'CHARACTER'; + +PARAMETER: 'parameter' | 'PARAMETER'; + +EXTERNAL: 'external' | 'EXTERNAL'; + +INTRINSIC: 'intrinsic' | 'INTRINSIC'; + +SAVE: 'save' | 'SAVE'; + +DATA: 'data' | 'DATA'; + +GO: 'GO' | 'go'; + +GOTO: 'GOTO' | 'goto'; + +IF: 'IF' | 'if'; + +THEN: 'THEN' | 'then'; + +ELSE: 'ELSE' | 'else'; + +ENDIF: 'ENDIF' | 'endif'; + +ELSEIF: 'ELSEIF' | 'elseif'; + +DO: 'DO' | 'do'; + +CONTINUE: 'CONTINUE' | 'continue'; + +STOP: 'STOP' | 'stop'; + +ENDDO: 'ENDDO' | 'enddo'; + +PAUSE: 'pause' | 'PAUSE'; + +WRITE: 'WRITE' | 'write'; + +READ: 'READ' | 'read'; + +PRINT: 'PRINT' | 'print'; + +OPEN: 'OPEN' | 'open'; + +FMT: 'FMT' | 'fmt'; + +UNIT: 'UNIT' | 'unit'; + +ERR: 'err' | 'ERR'; + +IOSTAT: 'IOSTAT' | 'iostat'; + +FORMAT: 'FORMAT' | 'format'; + +LET: 'LET' | 'let'; + +CALL: 'CALL' | 'call'; + +RETURN: 'RETURN' | 'return'; + +CLOSE: 'CLOSE' | 'close'; + +DOUBLE: 'DOUBLE' | 'double'; + +IOSTART: 'IOSTART' | 'iostart'; + +SEQUENTIAL: 'SEQUENTIAL' | 'sequential'; + +LABEL: 'LABEL' | 'label'; + +FILE: 'file' | 'FILE'; + +STATUS: 'STATUS' | 'status'; + +ACCESS: 'ACCESS' | 'access'; + +POSITION: 'POSITION' | 'position'; + +FORM: 'FORM' | 'form'; + +RECL: 'RECL' | 'recl'; + +BLANK: 'BLANK' | 'blank'; + +EXIST: 'EXIST' | 'exist'; + +OPENED: 'OPENED' | 'opened'; + +NUMBER: 'NUMBER' | 'number'; + +NAMED: 'NAMED' | 'named'; + +NAME_: 'NAME' | 'name'; + +FORMATTED: 'FORMATTED' | 'formatted'; + +UNFORMATTED: 'UNFORMATTED' | 'unformatted'; + +NEXTREC: 'NEXTREC' | 'nextrec'; + +INQUIRE: 'INQUIRE' | 'inquire'; + +BACKSPACE: 'BACKSPACE' | 'backspace'; + +ENDFILE: 'ENDFILE' | 'endfile'; + +REWIND: 'REWIND' | 'rewind'; + +DOLLAR: '$'; + +COMMA: ','; + +LPAREN: '('; + +RPAREN: ')'; + +COLON: ':'; + +ASSIGN: '='; + +MINUS: '-'; + +PLUS: '+'; + +DIV: '/'; + +fragment STARCHAR: '*'; + +POWER: '**'; + +LNOT: '.not.' | '.NOT.'; + +LAND: '.and.' | '.AND.'; + +LOR: '.or.' | '.OR.'; + +EQV: '.eqv.' | '.EQV.'; + +NEQV: '.neqv.' | '.NEQV.'; + +XOR: '.xor.' | '.XOR.'; + +EOR: '.eor.' | '.EOR.'; + +LT: '.lt.' | '.LT.'; + +LE: '.le.' | '.LE.'; + +GT: '.gt.' | '.GT.'; + +GE: '.ge.' | '.GE.'; + +NE: '.ne.' | '.NE.'; + +EQ: '.eq.' | '.EQ.'; + +TRUE: '.true.' | '.TRUE.'; + +FALSE: '.false.' | '.FALSE.'; + +XCON: 'XCON'; + +PCON: 'PCON'; + +FCON: 'FCON'; + +CCON: 'CCON'; + +HOLLERITH: 'HOLLERITH'; + +CONCATOP: 'CONCATOP'; + +CTRLDIRECT: 'CTRLDIRECT'; + +CTRLREC: 'CTRLREC'; + +TO: 'TO' | 'to'; + +SUBPROGRAMBLOCK: 'SUBPROGRAMBLOCK'; + +DOBLOCK: 'DOBLOCK'; + +AIF: 'AIF'; + +THENBLOCK: 'THENBLOCK'; + +ELSEBLOCK: 'ELSEBLOCK'; + +CODEROOT: 'CODEROOT'; + +COMPLEX: 'COMPLEX' | 'complex'; + +PRECISION: 'PRECISION' | 'precision'; + +INTEGER: 'INTEGER' | 'integer'; + +LOGICAL: 'LOGICAL' | 'logical'; + +fragment CONTINUATION: ~ ('0' | ' '); + +fragment ALNUM: (ALPHA | NUM); + +fragment HEX: (NUM | 'a' .. 'f'); + +fragment SIGN: ('+' | '-'); + +fragment FDESC: ('i' | 'f' | 'd') (NUM)+ '.' (NUM)+ | ('e' | 'g') (NUM)+ '.' (NUM)+ ('e' (NUM)+)?; + +fragment EXPON: ('e' | 'E' | 'd' | 'D') (SIGN)? (NUM)+; + +fragment ALPHA: ('a' .. 'z') | ('A' .. 'Z'); + +fragment NUM: ('0' .. '9'); + +// '' is used to drop the charater when forming the lexical token +// Strings are assumed to start with a single quote (') and two +// single quotes is meant as a literal single quote + +SCON: + '\'' ( + '\'' '\'' + | ~ ('\'' | '\n' | '\r') + | (('\n' | '\r' ('\n')?) ' ' CONTINUATION) ('\n' | '\r' ('\n')?) ' ' CONTINUATION + )* '\'' +; + +RCON: NUM+ '.' NUM* EXPON?; + +ICON: NUM+; + +NAME: (('i' | 'f' | 'd' | 'g' | 'e') (NUM)+ '.') FDESC | (ALNUM+) (ALNUM)*; + +COMMENT: {this.IsColumnZero()}? ('c' | STARCHAR) (~ [\r\n])* EOL -> channel(HIDDEN); + +STAR: STARCHAR; + +STRINGLITERAL: '"' ~ ["\r\n]* '"'; + +EOL: [\r\n]+; + +LINECONT: ((EOL ' $') | (EOL ' +')) -> skip; + +WS: [\t ]+ -> skip; \ No newline at end of file diff --git a/doc/examples/lawrence/Fortran77Parser.g4 b/doc/examples/lawrence/Fortran77Parser.g4 new file mode 100644 index 0000000..cd3b66f --- /dev/null +++ b/doc/examples/lawrence/Fortran77Parser.g4 @@ -0,0 +1,935 @@ +/* + * Fortran 77 grammar for ANTLR 2.7.5 + * Adadpted from Fortran 77 PCCTS grammar by Olivier Dragon + * Original PCCTS grammar by Terence Parr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + */ + +/** + * ported to Antlr4 by Tom Everett + */ + +/* + * Updated by Tom Everett, 2018 + */ + +// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false +// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging + +parser grammar Fortran77Parser; + +options + { + tokenVocab = Fortran77Lexer; +} + +program + : executableUnit+ EOL* EOF + ; + +executableUnit + : functionSubprogram + | mainProgram + | subroutineSubprogram + | blockdataSubprogram + ; + +mainProgram + : (programStatement)? subprogramBody + ; + +functionSubprogram + : functionStatement subprogramBody + ; + +subroutineSubprogram + : subroutineStatement subprogramBody + ; + +blockdataSubprogram + : blockdataStatement subprogramBody + ; + +otherSpecificationStatement + : dimensionStatement + | equivalenceStatement + | intrinsicStatement + | saveStatement + ; + +executableStatement + : ( + assignmentStatement + | gotoStatement + | ifStatement + | doStatement + | continueStatement + | stopStatement + | pauseStatement + | readStatement + | writeStatement + | printStatement + | rewindStatement + | backspaceStatement + | openStatement + | closeStatement + | endfileStatement + | inquireStatement + | callStatement + | returnStatement + ) + ; + +programStatement + : PROGRAM NAME EOL + ; + +entryStatement + : ENTRY NAME (LPAREN namelist RPAREN)? + ; + +functionStatement + : type_? FUNCTION NAME LPAREN namelist? RPAREN EOL? + ; + +blockdataStatement + : BLOCK NAME + ; + +subroutineStatement + : SUBROUTINE NAME (LPAREN namelist? RPAREN)? EOL? + ; + +namelist + : identifier (COMMA identifier)* + ; + +statement + : entryStatement + | implicitStatement + | parameterStatement + | typeStatement + | commonStatement + | pointerStatement + | externalStatement + | otherSpecificationStatement + | dataStatement + | (statementFunctionStatement) statementFunctionStatement + | executableStatement + ; + +subprogramBody + : wholeStatement+ endStatement + ; + +wholeStatement + : LABEL? statement EOL + ; + +endStatement + : LABEL? END + ; + +dimensionStatement + : DIMENSION arrayDeclarators + ; + +arrayDeclarator + : (NAME | REAL) LPAREN arrayDeclaratorExtents RPAREN + ; + +arrayDeclarators + : arrayDeclarator (COMMA arrayDeclarator)* + ; + +arrayDeclaratorExtents + : arrayDeclaratorExtent (COMMA arrayDeclaratorExtent)* + ; + +arrayDeclaratorExtent + : iexprCode (COLON (iexprCode | STAR))? + | STAR + ; + +equivalenceStatement + : EQUIVALENCE equivEntityGroup (COMMA equivEntityGroup)* + ; + +equivEntityGroup + : LPAREN equivEntity (COMMA equivEntity)* RPAREN + ; + +equivEntity + : varRef + ; + +commonStatement + : COMMON (commonBlock (COMMA commonBlock)* | commonItems) + ; + +commonName + : DIV (NAME DIV | DIV) + ; + +commonItem + : NAME + | arrayDeclarator + ; + +commonItems + : commonItem (COMMA commonItem)* + ; + +commonBlock + : commonName commonItems + ; + +typeStatement + : typename_ typeStatementNameList + | characterWithLen typeStatementNameCharList + ; + +typeStatementNameList + : typeStatementName (COMMA typeStatementName)* + ; + +typeStatementName + : NAME + | arrayDeclarator + ; + +typeStatementNameCharList + : typeStatementNameChar (COMMA typeStatementNameChar)* + ; + +typeStatementNameChar + : typeStatementName (typeStatementLenSpec)? + ; + +typeStatementLenSpec + : STAR lenSpecification + ; + +typename_ + : ( + REAL + | COMPLEX (STAR ICON?)? + | DOUBLE COMPLEX + | DOUBLE PRECISION + | INTEGER + | LOGICAL + | CHARACTER + ) + ; + +type_ + : typename_ + | characterWithLen + ; + +typenameLen + : STAR ICON + ; + +pointerStatement + : POINTER pointerDecl (COMMA pointerDecl)* + ; + +pointerDecl + : LPAREN NAME COMMA NAME RPAREN + ; + +implicitStatement + : IMPLICIT (implicitNone | implicitSpecs) + ; + +implicitSpec + : type_ LPAREN implicitLetters RPAREN + ; + +implicitSpecs + : implicitSpec (COMMA implicitSpec)* + ; + +implicitNone + : NONE + ; + +implicitLetter + : NAME + ; + +implicitRange + : implicitLetter (MINUS implicitLetter)? + ; + +implicitLetters + : implicitRange (COMMA implicitRange)* + ; + +lenSpecification + : (LPAREN STAR RPAREN) LPAREN STAR RPAREN + | ICON + | LPAREN intConstantExpr RPAREN + ; + +characterWithLen + : characterExpression (cwlLen)? + ; + +cwlLen + : STAR lenSpecification + ; + +parameterStatement + : PARAMETER LPAREN paramlist RPAREN + ; + +paramlist + : paramassign (COMMA paramassign)* + ; + +paramassign + : NAME ASSIGN constantExpr + ; + +externalStatement + : EXTERNAL namelist + ; + +intrinsicStatement + : INTRINSIC namelist + ; + +saveStatement + : SAVE (saveEntity (COMMA saveEntity)*)? + ; + +saveEntity + : (NAME | DIV NAME DIV) + ; + +dataStatement + : DATA dataStatementEntity ((COMMA)? dataStatementEntity)* + ; + +dataStatementItem + : varRef + | dataImpliedDo + ; + +dataStatementMultiple + : ((ICON | NAME) STAR)? (constant | NAME) + ; + +dataStatementEntity + : dse1 dse2 + ; + +dse1 + : dataStatementItem (COMMA dataStatementItem)* DIV + ; + +dse2 + : dataStatementMultiple (COMMA dataStatementMultiple)* DIV + ; + +dataImpliedDo + : LPAREN dataImpliedDoList COMMA dataImpliedDoRange RPAREN + ; + +dataImpliedDoRange + : NAME ASSIGN intConstantExpr COMMA intConstantExpr (COMMA intConstantExpr)? + ; + +dataImpliedDoList + : dataImpliedDoListWhat + | COMMA dataImpliedDoList + ; + +dataImpliedDoListWhat + : (varRef | dataImpliedDo) + ; + +gotoStatement + : (GO TO | GOTO) (unconditionalGoto | computedGoto | assignedGoto) + ; + +unconditionalGoto + : lblRef + ; + +computedGoto + : LPAREN labelList RPAREN (COMMA)? integerExpr + ; + +lblRef + : ICON + ; + +labelList + : lblRef (COMMA lblRef)* + ; + +assignedGoto + : NAME ((COMMA)? LPAREN labelList RPAREN)? + ; + +ifStatement + : IF LPAREN logicalExpression RPAREN ( + blockIfStatement + | logicalIfStatement + | arithmeticIfStatement + ) + ; + +arithmeticIfStatement + : lblRef COMMA lblRef COMMA lblRef + ; + +logicalIfStatement + : executableStatement + ; + +blockIfStatement + : firstIfBlock elseIfStatement* elseStatement? endIfStatement + ; + +firstIfBlock + : THEN EOL? wholeStatement+ + ; + +elseIfStatement + : (ELSEIF | (ELSE IF)) LPAREN logicalExpression RPAREN THEN EOL? wholeStatement+ + ; + +elseStatement + : ELSE EOL? wholeStatement+ + ; + +endIfStatement + : (ENDIF | END IF) + ; + +doStatement + : DO (doWithLabel | doWithEndDo) + ; + +doVarArgs + : variableName ASSIGN intRealDpExpr COMMA intRealDpExpr (COMMA intRealDpExpr)? + ; + +doWithLabel + : lblRef COMMA? doVarArgs EOL? doBody EOL? continueStatement + ; + +doBody + : (wholeStatement)+ + ; + +doWithEndDo + : doVarArgs EOL? doBody EOL? enddoStatement + ; + +enddoStatement + : (ENDDO | (END DO)) + ; + +continueStatement + : lblRef? CONTINUE + ; + +stopStatement + : STOP (ICON | HOLLERITH)? + ; + +pauseStatement + : PAUSE (ICON | HOLLERITH) + ; + +writeStatement + : WRITE LPAREN controlInfoList RPAREN ((COMMA? ioList)+)? + ; + +readStatement + : READ (formatIdentifier ((COMMA ioList)+)?) + ; + +printStatement + : PRINT (formatIdentifier ((COMMA ioList)+)?) + ; + +assignmentStatement + : varRef ASSIGN expression + ; + +controlInfoList + : controlInfoListItem (COMMA controlInfoListItem)* + ; + +controlErrSpec + : controlErr ASSIGN (lblRef | NAME) + ; + +controlInfoListItem + : unitIdentifier + | (HOLLERITH | SCON) + | controlFmt ASSIGN formatIdentifier + | controlUnit ASSIGN unitIdentifier + | controlRec ASSIGN integerExpr + | controlEnd ASSIGN lblRef + | controlErrSpec + | controlIostat ASSIGN varRef + ; + +ioList + : (ioListItem COMMA NAME ASSIGN) ioListItem + | (ioListItem COMMA ioListItem) ioListItem COMMA ioList + | ioListItem + ; + +ioListItem + : (LPAREN ioList COMMA NAME ASSIGN) ioImpliedDoList + | expression + ; + +ioImpliedDoList + : LPAREN ioList COMMA NAME ASSIGN intRealDpExpr COMMA intRealDpExpr (COMMA intRealDpExpr)? RPAREN + ; + +openStatement + : OPEN LPAREN openControl (COMMA openControl)* RPAREN + ; + +openControl + : unitIdentifier + | controlUnit ASSIGN unitIdentifier + | controlErrSpec + | controlFile ASSIGN characterExpression + | controlStatus ASSIGN characterExpression + | (controlAccess | controlPosition) ASSIGN characterExpression + | controlForm ASSIGN characterExpression + | controlRecl ASSIGN integerExpr + | controlBlank ASSIGN characterExpression + | controlIostat ASSIGN varRef + ; + +controlFmt + : FMT + ; + +controlUnit + : UNIT + ; + +controlRec + : NAME + ; + +controlEnd + : END + ; + +controlErr + : ERR + ; + +controlIostat + : IOSTART + ; + +controlFile + : FILE + ; + +controlStatus + : STATUS + ; + +controlAccess + : ACCESS + ; + +controlPosition + : POSITION + ; + +controlForm + : FORM + ; + +controlRecl + : RECL + ; + +controlBlank + : BLANK + ; + +controlExist + : EXIST + ; + +controlOpened + : OPENED + ; + +controlNumber + : NUMBER + ; + +controlNamed + : NAMED + ; + +controlName + : NAME + ; + +controlSequential + : SEQUENTIAL + ; + +controlDirect + : NAME + ; + +controlFormatted + : FORMATTED + ; + +controlUnformatted + : UNFORMATTED + ; + +controlNextrec + : NEXTREC + ; + +closeStatement + : CLOSE LPAREN closeControl (COMMA closeControl)* RPAREN + ; + +closeControl + : unitIdentifier + | controlUnit ASSIGN unitIdentifier + | controlErrSpec + | controlStatus ASSIGN characterExpression + | controlIostat ASSIGN varRef + ; + +inquireStatement + : INQUIRE LPAREN inquireControl (COMMA inquireControl)* RPAREN + ; + +inquireControl + : controlUnit ASSIGN unitIdentifier + | controlFile ASSIGN characterExpression + | controlErrSpec + | ( + controlIostat + | controlExist + | controlOpened + | controlNumber + | controlNamed + | controlName + | controlAccess + | controlSequential + | controlDirect + | controlForm + | controlFormatted + | controlUnformatted + | controlRecl + | controlNextrec + | controlBlank + ) ASSIGN varRef + | unitIdentifier + ; + +backspaceStatement + : BACKSPACE berFinish + ; + +endfileStatement + : ENDFILE berFinish + ; + +rewindStatement + : REWIND berFinish + ; + +berFinish + : (unitIdentifier (unitIdentifier) | LPAREN berFinishItem (COMMA berFinishItem)* RPAREN) + ; + +berFinishItem + : unitIdentifier + | controlUnit ASSIGN unitIdentifier + | controlErrSpec + | controlIostat ASSIGN varRef + ; + +unitIdentifier + : iexpr + | STAR + ; + +formatIdentifier + : (SCON | HOLLERITH) + | iexpr + | STAR + ; + +formatStatement + : FORMAT LPAREN fmtSpec RPAREN + ; + +fmtSpec + : (formatedit | formatsep (formatedit)?) ( + formatsep (formatedit)? + | COMMA (formatedit | formatsep (formatedit)?) + )* + ; + +formatsep + : DIV + | COLON + | DOLLAR + ; + +formatedit + : XCON + | editElement + | ICON editElement + | (PLUS | MINUS)? PCON ((ICON)? editElement)? + ; + +editElement + : (FCON | SCON | HOLLERITH | NAME) + | LPAREN fmtSpec RPAREN + ; + +statementFunctionStatement + : LET sfArgs ASSIGN expression + ; + +sfArgs + : NAME LPAREN namelist RPAREN + ; + +callStatement + : CALL subroutineCall + ; + +subroutineCall + : NAME (LPAREN (callArgumentList)? RPAREN)? + ; + +callArgumentList + : callArgument (COMMA callArgument)* + ; + +callArgument + : expression + | STAR lblRef + ; + +returnStatement + : RETURN (integerExpr)? + ; + +expression + : ncExpr (COLON ncExpr)? + ; + +ncExpr + : lexpr0 (concatOp lexpr0)* + ; + +lexpr0 + : lexpr1 ((NEQV | EQV) lexpr1)* + ; + +lexpr1 + : lexpr2 (LOR lexpr2)* + ; + +lexpr2 + : lexpr3 (LAND lexpr3)* + ; + +lexpr3 + : LNOT lexpr3 + | lexpr4 + ; + +lexpr4 + : aexpr0 ((LT | LE | EQ | NE | GT | GE) aexpr0)? + ; + +aexpr0 + : aexpr1 ((PLUS | MINUS) aexpr1)* + ; + +aexpr1 + : aexpr2 ((STAR | DIV) aexpr2)* + ; + +aexpr2 + : (PLUS | MINUS)* aexpr3 + ; + +aexpr3 + : aexpr4 (POWER aexpr4)* + ; + +aexpr4 + : unsignedArithmeticConstant + | (HOLLERITH | SCON) + | logicalConstant + | varRef + | LPAREN expression RPAREN + ; + +iexpr + : iexpr1 ((PLUS | MINUS) iexpr1)* + ; + +iexprCode + : iexpr1 ((PLUS | MINUS) iexpr1)* + ; + +iexpr1 + : iexpr2 ((STAR | DIV) iexpr2)* + ; + +iexpr2 + : (PLUS | MINUS)* iexpr3 + ; + +iexpr3 + : iexpr4 (POWER iexpr3)? + ; + +iexpr4 + : ICON + | varRefCode + | LPAREN iexprCode RPAREN + ; + +constantExpr + : expression + ; + +arithmeticExpression + : expression + ; + +integerExpr + : iexpr + ; + +intRealDpExpr + : expression + ; + +arithmeticConstExpr + : expression + ; + +intConstantExpr + : expression + ; + +characterExpression + : expression + ; + +concatOp + : DIV DIV + ; + +logicalExpression + : expression + ; + +logicalConstExpr + : expression + ; + +arrayElementName + : NAME LPAREN integerExpr (COMMA integerExpr)* RPAREN + ; + +subscripts + : LPAREN (expression (COMMA expression)*)? RPAREN + ; + +varRef + : (NAME | REAL) (subscripts (substringApp)?)? + ; + +varRefCode + : NAME (subscripts (substringApp)?)? + ; + +substringApp + : LPAREN (ncExpr)? COLON (ncExpr)? RPAREN + ; + +variableName + : NAME + ; + +arrayName + : NAME + ; + +subroutineName + : NAME + ; + +functionName + : NAME + ; + +constant + : ((PLUS | MINUS))? unsignedArithmeticConstant + | (SCON | HOLLERITH) + | logicalConstant + ; + +unsignedArithmeticConstant + : (ICON | RCON) + | complexConstant + ; + +complexConstant + : LPAREN ((PLUS | MINUS))? (ICON | RCON) COMMA ((PLUS | MINUS))? (ICON | RCON) RPAREN + ; + +logicalConstant + : (TRUE | FALSE) + ; + +// needed because Fortran doesn't have reserved keywords. Putting the rule +// 'keyword" instead of a few select keywords breaks the parser with harmful +// non-determinisms +identifier + : NAME + | REAL + ; \ No newline at end of file diff --git a/doc/examples/lawrence/fortran77.scm b/doc/examples/lawrence/fortran77.scm new file mode 100644 index 0000000..dd2b647 --- /dev/null +++ b/doc/examples/lawrence/fortran77.scm @@ -0,0 +1,13 @@ +(define-grammar fortran77 fortran77-symbol + (:executableUnit) + program + ((program ((executableUnit) $1) + (((functionSubprogram) $2) + ((mainProgram) $2) + ((subroutineSubprogram) $2) + ((blockdataSubprogram)))) + (((mainProgram) $3) + ((programStatement) subprogramBody) + ((subProgramBody) $4) + )) + ) \ No newline at end of file diff --git a/doc/examples/lawrence/toy-grammars-test.clj b/doc/examples/lawrence/toy-grammars-test.clj new file mode 100644 index 0000000..9fba94e --- /dev/null +++ b/doc/examples/lawrence/toy-grammars-test.clj @@ -0,0 +1,41 @@ +; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. + +;; Rudimentary test suite + +(define-test-suite toy-grammars-tests) + +(define-test-case g08 toy-grammars-tests + (check (parse g08 1 'lr 0 i08-1) => #f) + (check (parse g08 1 'slr 0 i08-1) => #f) + (check-exception (parse g08 1 'lr 0 i08-2)) + (check-exception (parse g08 1 'slr 0 i08-2)) + (check-exception (parse g08 1 'lr 0 i08-3)) + (check-exception (parse g08 1 'slr 0 i08-3))) + +(define-test-case g10 toy-grammars-tests + (check (parse g10 1 'lr 0 i10-1) => 147) + (check (parse g10 1 'slr 0 i10-1) => 147) + (check-exception (parse g10 1 'lr 0 i10-2)) + (check-exception (parse g10 1 'slr 0 i10-2)) + (check-exception (parse g10 1 'lr 0 i10-3)) + (check-exception (parse g10 1 'slr 0 i10-3))) + +(define-test-case g10-k=2 toy-grammars-tests + (check (parse g10 2 'lr 0 i10-1) => 147) + (check (parse g10 2 'slr 0 i10-1) => 147) + (check-exception (parse g10 2 'lr 0 i10-2)) + (check-exception (parse g10 2 'slr 0 i10-2)) + (check-exception (parse g10 2 'lr 0 i10-3)) + (check-exception (parse g10 2 'slr 0 i10-3))) + +(define-test-case g10-error toy-grammars-tests + (check (parse g10-error 1 'lr 0 i10e-1) => 147) + (check (parse g10-error 1 'slr 0 i10e-1) => 147) + (check (parse g10-error 1 'lr 0 i10e-2) => 28) + (check (parse g10-error 1 'slr 0 i10e-2) => 28) + (check-exception (parse g10-error 1 'lr 0 i10e-3)) + (check-exception (parse g10-error 1 'slr 0 i10e-3))) + +(define-test-case g14 toy-grammars-tests + (check (parse g14 1 'lr 0 i14-1) => #f) + (check (parse g14 1 'slr 0 i14-1) => #f)) diff --git a/doc/examples/lawrence/toy-grammars.scm b/doc/examples/lawrence/toy-grammars.scm new file mode 100644 index 0000000..afd4859 --- /dev/null +++ b/doc/examples/lawrence/toy-grammars.scm @@ -0,0 +1,83 @@ +; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. + +; Balanced parentheses + +(define-grammar g00 g00-symbol + (:l) + S + ((S ((l) $1)))) + +(define-grammar g08 g08-symbol + (:l :r) + S + ((S ((S T) $1) + ((T) $1)) + (T ((l S r) $1) + ((l r) $1)))) + +; Constant arithmetic expressions + +(define-grammar g10 g10-symbol + (;+ :- :* :/ :l :r :n) + E + ((E ((T) $1) + ((T + E) (+ $1 $3)) + ((T - E) (- $1 $3))) + (T ((P) $1) + ((P * T) (* $1 $3)) + ((P / T) (/ $1 $3))) + (P ((n) $1) + ((l E r) $2)))) + +(define-grammar g10-error g10-error-symbol + (:+ :- :* :/ ;l :r :n) + E + ((E ((T) $1) + (($error) 0) + ((T + E) (+ $1 $3)) + ((T - E) (- $1 $3))) + (T ((P) $1) + ((P * T) (* $1 $3)) + ((P / T) (/ $1 $3))) + (P ((n) $1) + ((l E r) $2) + ((l $error r) 0)))) + +(define-grammar g13 g13-symbol + (:comma :blah :dot) + S + ((SLK (() $1) + ((NESLK) $1)) + (NESLK ((N) $1) + ((NESLK K N) $1)) + (SLD (() $1) + ((NESLD) $1)) + (NESLD ((N) $1) + ((NESLD P N) $1)) + (S ((SLK) $1) + ((SLD) $1)) + (K ((comma) $1)) + (P ((dot) $1)) + (N ((blah) $1)))) + +;; javascript example expanded + +(define-grammar g14 g14-symbol + (:const :comma :colon :lcurly :rcurly :lbracket :rbracket) + S + ((S ((E) $1)) + (E ((const) $1) + ((lcurly OL rcurly) $1) + ((lbracket AL rbracket) $1)) + (C ((comma) $1)) + (A ((const colon E) $1)) + (OL (() $1) + ((ON) $1)) + (ON ((A) $1) + ((ON C A) $1)) + (AL (() $1) + ((AN) $1)) + (AN ((E) $1) + ((AN C E) $1)))) + + diff --git a/doc/examples/lawrence/toy-inputs.in b/doc/examples/lawrence/toy-inputs.in new file mode 100644 index 0000000..b266a9d --- /dev/null +++ b/doc/examples/lawrence/toy-inputs.in @@ -0,0 +1,75 @@ +; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. + +(define i08-1 (list (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol r) #f))) + +(define i08-2 (list (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol r) #f))) + +(define i08-3 (list (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol l) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol r) #f) + (cons (enum g08-symbol l) #f))) + +(define i10-1 (list (cons (enum g10-symbol l) #f) + (cons (enum g10-symbol n) 4) + (cons (enum g10-symbol +) #f) + (cons (enum g10-symbol n) 17) + (cons (enum g10-symbol r) #f) + (cons (enum g10-symbol *) #f) + (cons (enum g10-symbol n) 7))) + +(define i10-2 (list (cons (enum g10-symbol l) #f) + (cons (enum g10-symbol n) 4) + (cons (enum g10-symbol +) #f) + (cons (enum g10-symbol n) 15) + (cons (enum g10-symbol n) 17) + (cons (enum g10-symbol r) #f) + (cons (enum g10-symbol *) #f) + (cons (enum g10-symbol n) 7))) + +(define i10-3 (list (cons (enum g10-symbol l) #f) + (cons (enum g10-symbol n) 4) + (cons (enum g10-symbol +) #f) + (cons (enum g10-symbol n) 17) + (cons (enum g10-symbol *) #f) + (cons (enum g10-symbol n) 7))) + +(define i10e-1 (list (cons (enum g10-error-symbol l) #f) + (cons (enum g10-error-symbol n) 4) + (cons (enum g10-error-symbol +) #f) + (cons (enum g10-error-symbol n) 17) + (cons (enum g10-error-symbol r) #f) + (cons (enum g10-error-symbol *) #f) + (cons (enum g10-error-symbol n) 7))) + +(define i10e-2 (list (cons (enum g10-error-symbol l) #f) + (cons (enum g10-error-symbol n) 4) + (cons (enum g10-error-symbol +) #f) + (cons (enum g10-error-symbol n) 15) + (cons (enum g10-error-symbol n) 17) + (cons (enum g10-error-symbol r) #f) + (cons (enum g10-error-symbol *) #f) + (cons (enum g10-error-symbol n) 7))) + +(define i10e-3 (list (cons (enum g10-error-symbol l) #f) + (cons (enum g10-error-symbol n) 4) + (cons (enum g10-error-symbol +) #f) + (cons (enum g10-error-symbol n) 17) + (cons (enum g10-error-symbol *) #f) + (cons (enum g10-error-symbol n) 7))) + +(define i14-1 (list (cons (enum g14-symbol lbracket) #f) + (cons (enum g14-symbol const) #f) + (cons (enum g14-symbol rbracket) #f))) diff --git a/project.clj b/project.clj index 5288a34..5741f83 100644 --- a/project.clj +++ b/project.clj @@ -3,6 +3,6 @@ :url "https://github.com/active-group/lawrence" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.11.10"] + :dependencies [[org.clojure/clojure "1.0.0"] [de.active-group/active-clojure "0.42.2" :exclusions [org.clojure/clojure]]] :profiles {:dev {:dependencies [[org.clojure/tools.trace "0.7.9"]]}}) diff --git a/test/active/lawrence/grammar_test.clj b/test/active/lawrence/grammar_test.clj index 571d304..daff9dd 100644 --- a/test/active/lawrence/grammar_test.clj +++ b/test/active/lawrence/grammar_test.clj @@ -1,11 +1,17 @@ (ns active.lawrence.grammar-test - (:require [active.lawrence.grammar :refer :all])) + (:require [active.lawrence.grammar :refer :all] + [clojure.test :as t] + [core :as sut])) +(t/deftest grammar-g00 + (t/testing "little grammar test" (define-grammar g00 (:l) S ((S ((:l) $1)))) - +)) +(t/deftest grammar-g00 + (t/testing "little grammar test" (define-grammar g08 (:l :r) S @@ -14,6 +20,8 @@ (T ((:l S :r) $1) ((:l :r) $1)))) + )) +(run-tests) ; Constant arithmetic expressions (define-grammar g10 From ecce12cac6aa06502aed4f21885bf09da4d2f24f Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Tue, 4 Jun 2024 18:42:07 +0200 Subject: [PATCH 03/23] reformatted a bit and added start of the reference as well as a test and a test.clj (run-all-tests) --- doc/REFERENCE.md | 5 +- project.clj | 11 ++- src/active/lawrence/grammar.clj | 30 +++--- test/active/lawrence/functional_test.clj | 114 +++++++++++++++++++++++ test/active/lawrence/generate_test.clj | 5 +- test/active/lawrence/test.clj | 4 + 6 files changed, 150 insertions(+), 19 deletions(-) create mode 100644 test/active/lawrence/functional_test.clj create mode 100644 test/active/lawrence/test.clj diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index 07f6f85..ba9ebf9 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -91,4 +91,7 @@ Lawrence (example above but as infix) (:+ $1 $3)) ;; here a addition is defined (infix) code: 5 + 3 - so the first and the third ;; placements defines variables -> $1 $3 ``` -#### The structure of a rule \ No newline at end of file +#### The structure of a rule + + +### Some code examples how to call lawrence and test it direct or generate a specialized parser diff --git a/project.clj b/project.clj index 5741f83..886906a 100644 --- a/project.clj +++ b/project.clj @@ -1,8 +1,11 @@ -(defproject lawrence "0.12.0-SNAPSHOT" +(defproject de.active-group/lawrence-parse-gen "0.12.0-SNAPSHOT" :description "Lawrence: LR parser generator" :url "https://github.com/active-group/lawrence" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.0.0"] - [de.active-group/active-clojure "0.42.2" :exclusions [org.clojure/clojure]]] - :profiles {:dev {:dependencies [[org.clojure/tools.trace "0.7.9"]]}}) + :dependencies [[org.clojure/clojure "1.10.1"] + [de.active-group/active-clojure "0.42.2"] + [de.active-group/ephemerol-brain-scan "0.6.0-SNAPSHOT"]] + :profiles {:dev {:dependencies [[org.clojure/tools.trace "0.7.9"]]}} + ) + diff --git a/src/active/lawrence/grammar.clj b/src/active/lawrence/grammar.clj index 1d99d88..a84e527 100644 --- a/src/active/lawrence/grammar.clj +++ b/src/active/lawrence/grammar.clj @@ -12,7 +12,7 @@ ; - the nonterminals come before the terminals ; - the start production is first -(define-record-type Grammar +(define-record-type grammer (really-make-grammar name nonterminals terminals @@ -61,15 +61,17 @@ number-of-symbols (+ number-of-terminals number-of-nonterminals)] (really-make-grammar name - nonterminals terminals - number-of-terminals - number-of-symbols - error start - productions-by-lhs - symbol->name-procedure - name->symbol-procedure - terminal-attribution - (atom {})))) + nonterminals + terminals + number-of-terminals + number-of-symbols + error + start + productions-by-lhs + symbol->name-procedure + name->symbol-procedure + terminal-attribution + (atom {})))) (defn grammar-fetch-property [grammar name proc] @@ -105,8 +107,10 @@ (- lhs (grammar-nonterminal-offset grammar)))) (defn grammar-start-production - [grammar] - (first (grammar-productions-with-lhs (grammar-start grammar) grammar))) + [in-grammar] + ;;(println (grammar-start grammar)) + (println in-grammar) + (first (grammar-productions-with-lhs (grammar-start in-grammar) in-grammar))) (defn grammar-for-each-production [proc grammar] @@ -119,7 +123,7 @@ (proc prod)) (recur (+ 1 i)))))) -(define-record-type Production +(define-record-type production (make-production readable lhs rhs attribution) production? [readable production-readable diff --git a/test/active/lawrence/functional_test.clj b/test/active/lawrence/functional_test.clj new file mode 100644 index 0000000..880b6db --- /dev/null +++ b/test/active/lawrence/functional_test.clj @@ -0,0 +1,114 @@ +(ns active.lawrence.functional-test + (:require [clojure.test :refer :all] + [active.ephemerol.char-set :refer :all] + [active.lawrence.grammar :as gr] + [active.lawrence.direct-lr :as direct] + [active.ephemerol.regexp :refer :all] + [active.ephemerol.scanner :refer :all] + [active.ephemerol.scanner-run :refer :all])) + +(defn eval-scanner + [scanner sym-name-space] + (binding [*ns* (find-ns sym-name-space)] + (eval (scanner->expression scanner)))) +(def method-lr :lr) +(def method-slr :slr) +(defn parse + [g m vs] + (direct/parse g 1 m vs)) + +(defn def-complete-scan [sym-name-space this-scanner-spec + input] + + (let [scanner (compute-scanner this-scanner-spec) + scan-one (make-scan-one (eval-scanner scanner + sym-name-space)) + + scan-result + (scan-to-list + scan-one + (string->list input) + (make-position 1 0))] + (println "Scan Result: ") + (println scan-result) + scan-result) ) + + +(defn execute-direct [sym-name-space this-scanner-spec + yacc-result input method] + + + (let [scan-result (def-complete-scan sym-name-space + this-scanner-spec + input)] + + + (println "Scan Result: ") + (println scan-result) + (parse yacc-result method (first scan-result) ) + ) + ) + + +(def lang-scan (scanner-spec + ((+ char-set:digit) + (fn [lexeme position input input-position] + (make-scan-result [:decimal-symbol (Integer/parseInt lexeme)] + input input-position))) + (char-set:whitespace + (fn [lexeme position input input-position] + (make-scan-result :whitespace + input input-position))) + ("*" + (fn [lexeme position input input-position] + (make-scan-result [:mul nil] + input input-position))) + ("/" + (fn [lexeme position input input-position] + (make-scan-result [:div nil] + input input-position))) + ("-" + (fn [lexeme position input input-position] + (make-scan-result [:minus nil] + input input-position))) + ("+" + (fn [lexeme position input input-position] + (make-scan-result [:plus nil] + input input-position))) + ("**" + (fn [lexeme position input input-position] + (make-scan-result [:power nil] + input input-position))) + ("(" + (fn [lexeme position input input-position] + (make-scan-result [:lparen nil] + input input-position))) + (")" + (fn [lexeme position input input-position] + (make-scan-result [:rparen nil] + input input-position))) + ("^" + (fn [lexeme position input input-position] + (make-scan-result [:not nil] + input input-position))))) + (def lang-grammar (gr/define-grammar + calculator + (list :plus :minus :mul :div :lparen :rparen + :not :decimal-symbol :power :whitespace) + expression + ((expression ((term) $1) + ((term :plus expression) (+ $1 $3)) + ((term :power expression) (+ $1 $3)) + ((term :minus expression) (- $1 $3))) + (term ((product) $1) + ((term :mul term) (* $1 $3)) + ((product :div term) (/ $1 $3))) + (product ((:not) $1) + ((:decimal-symbol) $1) + ((:lparen + expression :rparen) $2)) + + ))) + (execute-direct 'active.lawrence.functional-test + lang-scan calculator + "(9 * 5)" method-slr) diff --git a/test/active/lawrence/generate_test.clj b/test/active/lawrence/generate_test.clj index 2440dbe..482a1e9 100644 --- a/test/active/lawrence/generate_test.clj +++ b/test/active/lawrence/generate_test.clj @@ -2,9 +2,12 @@ (:require [active.lawrence.grammar-test :refer :all] [active.lawrence.lr :as lr])) + (defn generate [grammar name method] (lr/write-ds-parse-ns grammar 1 method (symbol (str "active.lawrence." name "-parser")) '([active.lawrence.parser-runtime :refer :all]) - (str "test/active/lawrence/" name "_parser.clj"))) + (str "./test/active/lawrence/" name "_parser.clj"))) + +(generate g14 "calc-it" :slr) \ No newline at end of file diff --git a/test/active/lawrence/test.clj b/test/active/lawrence/test.clj new file mode 100644 index 0000000..99a2939 --- /dev/null +++ b/test/active/lawrence/test.clj @@ -0,0 +1,4 @@ +(ns active.lawrence.test + (:require [clojure.test :refer :all])) + +(run-all-tests) From 16f6440227cff85db9cef0744f3f1b294952c17c Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Mon, 17 Jun 2024 11:37:39 +0200 Subject: [PATCH 04/23] saving work --- test/active/lawrence/direct_lr_test.clj | 1 + test/active/lawrence/functional_test.clj | 169 +++++++------------ test/active/lawrence/generate_test.clj | 6 +- test/active/lawrence/grammar_test.clj | 16 +- test/active/lawrence/process_test.clj | 85 ++++++++++ test/active/lawrence/util/parse_lex_util.clj | 84 +++++++++ 6 files changed, 246 insertions(+), 115 deletions(-) create mode 100644 test/active/lawrence/process_test.clj create mode 100644 test/active/lawrence/util/parse_lex_util.clj diff --git a/test/active/lawrence/direct_lr_test.clj b/test/active/lawrence/direct_lr_test.clj index 3dba170..4d53cb2 100644 --- a/test/active/lawrence/direct_lr_test.clj +++ b/test/active/lawrence/direct_lr_test.clj @@ -53,3 +53,4 @@ ;;(should-accept goptional (list [:bar]) :absent) (should-accept goptional (list [:bar] [:foo]) :present)) +(run-all-tests) \ No newline at end of file diff --git a/test/active/lawrence/functional_test.clj b/test/active/lawrence/functional_test.clj index 880b6db..c81d785 100644 --- a/test/active/lawrence/functional_test.clj +++ b/test/active/lawrence/functional_test.clj @@ -1,114 +1,75 @@ (ns active.lawrence.functional-test (:require [clojure.test :refer :all] + [active.lawrence.util.parse-lex-util :refer :all] [active.ephemerol.char-set :refer :all] - [active.lawrence.grammar :as gr] - [active.lawrence.direct-lr :as direct] - [active.ephemerol.regexp :refer :all] - [active.ephemerol.scanner :refer :all] + [active.lawrence.grammar :as gr] + [active.ephemerol.regexp :refer :all] + [active.ephemerol.scanner :refer :all] [active.ephemerol.scanner-run :refer :all])) -(defn eval-scanner - [scanner sym-name-space] - (binding [*ns* (find-ns sym-name-space)] - (eval (scanner->expression scanner)))) -(def method-lr :lr) -(def method-slr :slr) -(defn parse - [g m vs] - (direct/parse g 1 m vs)) - -(defn def-complete-scan [sym-name-space this-scanner-spec - input] - - (let [scanner (compute-scanner this-scanner-spec) - scan-one (make-scan-one (eval-scanner scanner - sym-name-space)) - - scan-result - (scan-to-list - scan-one - (string->list input) - (make-position 1 0))] - (println "Scan Result: ") - (println scan-result) - scan-result) ) - - -(defn execute-direct [sym-name-space this-scanner-spec - yacc-result input method] - - - (let [scan-result (def-complete-scan sym-name-space - this-scanner-spec - input)] - - - (println "Scan Result: ") - (println scan-result) - (parse yacc-result method (first scan-result) ) - ) - ) - (def lang-scan (scanner-spec - ((+ char-set:digit) + ((+ char-set:digit) + (fn [lexeme position input input-position] + ( (make-scan-result + [(Integer/parseInt lexeme) :decimal-symbol] + input input-position))) + (char-set:whitespace + (fn [lexeme position input input-position] + (make-scan-result [lexeme :whitespace] + input input-position))) + ("*" + (fn [lexeme position input input-position] + (make-scan-result [lexeme :mul] + input input-position))) + ("/" + (fn [lexeme position input input-position] + (make-scan-result [lexeme :div] + input input-position))) + ("-" + (fn [lexeme position input input-position] + (make-scan-result [lexeme :minus] + input input-position))) + ("+" + (fn [lexeme position input input-position] + (make-scan-result () [lexeme :plus] + input input-position))) + ("**" (fn [lexeme position input input-position] - (make-scan-result [:decimal-symbol (Integer/parseInt lexeme)] + (make-scan-result [lexeme :power] input input-position))) - (char-set:whitespace - (fn [lexeme position input input-position] - (make-scan-result :whitespace - input input-position))) - ("*" - (fn [lexeme position input input-position] - (make-scan-result [:mul nil] - input input-position))) - ("/" - (fn [lexeme position input input-position] - (make-scan-result [:div nil] - input input-position))) - ("-" - (fn [lexeme position input input-position] - (make-scan-result [:minus nil] - input input-position))) - ("+" - (fn [lexeme position input input-position] - (make-scan-result [:plus nil] - input input-position))) - ("**" - (fn [lexeme position input input-position] - (make-scan-result [:power nil] - input input-position))) - ("(" - (fn [lexeme position input input-position] - (make-scan-result [:lparen nil] - input input-position))) - (")" - (fn [lexeme position input input-position] - (make-scan-result [:rparen nil] - input input-position))) - ("^" - (fn [lexeme position input input-position] - (make-scan-result [:not nil] - input input-position))))) - (def lang-grammar (gr/define-grammar - calculator - (list :plus :minus :mul :div :lparen :rparen - :not :decimal-symbol :power :whitespace) - expression - ((expression ((term) $1) - ((term :plus expression) (+ $1 $3)) - ((term :power expression) (+ $1 $3)) - ((term :minus expression) (- $1 $3))) - (term ((product) $1) - ((term :mul term) (* $1 $3)) - ((product :div term) (/ $1 $3))) - (product ((:not) $1) - ((:decimal-symbol) $1) - ((:lparen - expression :rparen) $2)) + ("(" + (fn [lexeme position input input-position] + (make-scan-result [lexeme :lparen] + input input-position))) + (")" + (fn [lexeme position input input-position] + (make-scan-result [lexeme :rparen] + input input-position))) + ("^" + (fn [lexeme position input input-position] + (make-scan-result [lexeme :not] + input input-position))))) +(def lang-grammar (gr/define-grammar + calculator + (list :plus :minus :mul :div :lparen :rparen + :not :decimal-symbol :power :whitespace) + expression + ((expression ((expression term) $1 $2) + ((term :plus expression) (+ $1 $3)) + ((term :power expression) (+ $1 $3)) + ((term :minus expression) (- $1 $3))) + (term ((product) $1) + ((term :mul term) (* $1 $3)) + ((product :div term) (/ $1 $3))) + (product ((:not) $1) + ((:decimal-symbol) $1) + ((:lparen + expression :rparen) $2)) + + ))) +(execute-direct 'active.lawrence.functional-test + lang-scan calculator + "(9 * 5)" method-slr) +;;(parse calculator :lr input) - ))) - (execute-direct 'active.lawrence.functional-test - lang-scan calculator - "(9 * 5)" method-slr) diff --git a/test/active/lawrence/generate_test.clj b/test/active/lawrence/generate_test.clj index 482a1e9..2071176 100644 --- a/test/active/lawrence/generate_test.clj +++ b/test/active/lawrence/generate_test.clj @@ -1,13 +1,13 @@ (ns active.lawrence.generate-test - (:require [active.lawrence.grammar-test :refer :all] + (:require [active.lawrence.process-test :refer :all] [active.lawrence.lr :as lr])) (defn generate [grammar name method] (lr/write-ds-parse-ns grammar 1 method - (symbol (str "active.lawrence." name "-parser")) + (symbol (str "active.lawrence.generate-test." name "-parser")) '([active.lawrence.parser-runtime :refer :all]) (str "./test/active/lawrence/" name "_parser.clj"))) -(generate g14 "calc-it" :slr) \ No newline at end of file +(generate toys-are-us "calc-it" :slr) \ No newline at end of file diff --git a/test/active/lawrence/grammar_test.clj b/test/active/lawrence/grammar_test.clj index daff9dd..d3a7724 100644 --- a/test/active/lawrence/grammar_test.clj +++ b/test/active/lawrence/grammar_test.clj @@ -1,17 +1,17 @@ (ns active.lawrence.grammar-test (:require [active.lawrence.grammar :refer :all] - [clojure.test :as t] - [core :as sut])) + [clojure.test :refer :all] + )) -(t/deftest grammar-g00 - (t/testing "little grammar test" +(deftest grammar-g00 + (testing "little grammar test" (define-grammar g00 (:l) S ((S ((:l) $1)))) )) -(t/deftest grammar-g00 - (t/testing "little grammar test" +(deftest grammar-g00 + (testing "little grammar test" (define-grammar g08 (:l :r) S @@ -21,7 +21,7 @@ ((:l :r) $1)))) )) -(run-tests) + ; Constant arithmetic expressions (define-grammar g10 @@ -93,4 +93,4 @@ ((S ((:bar O) $2)) (O ((:foo) :present) (() :absent)))) - +(run-all-tests) diff --git a/test/active/lawrence/process_test.clj b/test/active/lawrence/process_test.clj new file mode 100644 index 0000000..1d0a409 --- /dev/null +++ b/test/active/lawrence/process_test.clj @@ -0,0 +1,85 @@ +(ns active.lawrence.process-test + (:require [clojure.test :refer :all] + [active.lawrence.util.parse-lex-util :refer :all] + [active.ephemerol.char-set :refer :all] + [active.lawrence.grammar :as gr] + [active.ephemerol.regexp :refer :all] + [active.ephemerol.scanner :refer :all] + [active.ephemerol.scanner-run :refer :all])) + +(def toys-scan (scanner-spec + ((+ char-set:digit) + (fn [lexeme position input input-position] + (make-scan-result + [:decimal-symbol (Integer/parseInt lexeme) ] + input input-position))) + (char-set:whitespace + (fn [lexeme position input input-position] + (make-scan-result [:whitespace nil] + input input-position))) + ("+" + (fn [lexeme position input input-position] + (make-scan-result [:+ nil] + input input-position))) + ("-" + (fn [lexeme position input input-position] + (make-scan-result [:- nil] + input input-position))) + ("*" + (fn [lexeme position input input-position] + (make-scan-result [:* nil] + input input-position))) + ("/" + (fn [lexeme position input input-position] + (make-scan-result [:/ nil] + input input-position))) + ("(" + (fn [lexeme position input input-position] + (make-scan-result [:l nil] + input input-position))) + (")" + (fn [lexeme position input input-position] + (make-scan-result [:r nil] + input input-position))) + ("not" + (fn [lexeme position input input-position] + (make-scan-result [:n nil] + input input-position))) + )) + +(gr/define-grammar toys-are-us + (:+ :- :* :/ :l :r :n) + E + ((E ((T) $1) + ((:$error) 0) + ((T :+ E) (+ $1 $3)) + ((T :- E) (- $1 $3))) + (T ((P) $1) + ((P :* T) (* $1 $3)) + ((P :/ T) (/ $1 $3))) + (P ((:n) $1) + ((:l E :r) $2) + ((:l :$error :r) 0)))) +(gr/define-grammar toys-are-us-ext + (:+ :- :* :/ :l :r :n :decimal-symbol) + E + ((E ((T) $1) + ((:$error) 0) + ((T :+ E) (+ $1 $3)) + ((T :- E) (- $1 $3))) + (T ((P) $1) + ((P :* T) (* $1 $3)) + ((P :/ T) (/ $1 $3))) + (P ((:n) $1) + ((:l E :r) $2) + ((:l :$error :r) 0)))) + +(deftest use-parse + (let [expr (list [:l] [:+] [:r])] + (println expr) +(parse-with-mpair toys-are-us :lr expr))) + +(deftest process-rest + (execute-direct 'active.lawrence.process-test + toys-scan toys-are-us-ext + "(9*5)" method-lr)) diff --git a/test/active/lawrence/util/parse_lex_util.clj b/test/active/lawrence/util/parse_lex_util.clj new file mode 100644 index 0000000..5e41769 --- /dev/null +++ b/test/active/lawrence/util/parse_lex_util.clj @@ -0,0 +1,84 @@ +(ns active.lawrence.util.parse-lex-util + (:require [active.ephemerol.char-set :refer :all] + [active.lawrence.grammar :as gr] + [active.lawrence.runtime :as rt] + [active.lawrence.direct-lr :as direct] + [active.ephemerol.regexp :refer :all] + [active.ephemerol.scanner :refer :all] + [active.ephemerol.scanner-run :refer :all])) +(defn input + "Convert list of [token attribute-value] vectors to input." + [g vs] + (map (fn [[t av]] + ;;(rt/make-pair (gr/grammar-name->symbol t g) + ;; av + (gr/grammar-name->symbol t g) + ) + vs)) + +(defn input-with-mpair + "Convert list of [token attribute-value] vectors to input." + [g vs] + (map (fn [[t av]] + (rt/make-pair (gr/grammar-name->symbol t g) + av + + )) + vs)) + + +(defn eval-scanner + [scanner sym-name-space] + (binding [*ns* (find-ns sym-name-space)] + (eval (scanner->expression scanner)))) + +(def method-lr :lr) +(def method-slr :slr) + +(defn parse + [g m vs] + (let [cooked-input (input g vs)] + (println cooked-input) + (direct/parse g 1 m cooked-input))) + +(defn parse-with-mpair + [g m vs] + (let [cooked-input (input-with-mpair g vs)] + (println cooked-input) + (direct/parse g 1 m cooked-input))) + +(defn def-complete-scan [sym-name-space this-scanner-spec + input] + + (let [scanner (compute-scanner this-scanner-spec) + scan-one (make-scan-one (eval-scanner scanner + sym-name-space)) + + + scan-result + + (scan-to-list + scan-one + (string->list input) + (make-position 1 0)) + ] + (println "Scan Result output: ") + (println (first scan-result)) + (first scan-result)) ) + + +(defn execute-direct [sym-name-space this-scanner-spec + yacc-result input method] + + + (let [output (def-complete-scan sym-name-space + this-scanner-spec + input)] + + + + (println "Scan Result: ") + (println output) + (parse yacc-result method output ;;(first scan-result) + )) + ) From 2e998bad01062f692d6840800547811b559facd4 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Tue, 18 Jun 2024 20:05:05 +0200 Subject: [PATCH 05/23] saving work --- doc/examples/essence/toy-grammars-test.scm | 41 - doc/examples/essence/toy-grammars.scm | 83 -- doc/examples/essence/toy-inputs.scm | 75 -- .../lawrence/ASS_370_grammar_test.clj | 90 -- doc/examples/lawrence/Fortran77Lexer.g4 | 310 ------ doc/examples/lawrence/Fortran77Parser.g4 | 935 ------------------ doc/examples/lawrence/fortran77.scm | 13 - doc/examples/lawrence/toy-grammars-test.clj | 41 - doc/examples/lawrence/toy-grammars.scm | 83 -- doc/examples/lawrence/toy-inputs.in | 75 -- project.clj | 4 +- test/active/lawrence/functional_test.clj | 45 +- test/active/lawrence/generate_test.clj | 11 +- test/active/lawrence/process_test.clj | 29 +- test/active/lawrence/util/parse_lex_util.clj | 24 +- 15 files changed, 47 insertions(+), 1812 deletions(-) delete mode 100644 doc/examples/essence/toy-grammars-test.scm delete mode 100644 doc/examples/essence/toy-grammars.scm delete mode 100644 doc/examples/essence/toy-inputs.scm delete mode 100644 doc/examples/lawrence/ASS_370_grammar_test.clj delete mode 100644 doc/examples/lawrence/Fortran77Lexer.g4 delete mode 100644 doc/examples/lawrence/Fortran77Parser.g4 delete mode 100644 doc/examples/lawrence/fortran77.scm delete mode 100644 doc/examples/lawrence/toy-grammars-test.clj delete mode 100644 doc/examples/lawrence/toy-grammars.scm delete mode 100644 doc/examples/lawrence/toy-inputs.in diff --git a/doc/examples/essence/toy-grammars-test.scm b/doc/examples/essence/toy-grammars-test.scm deleted file mode 100644 index 9fba94e..0000000 --- a/doc/examples/essence/toy-grammars-test.scm +++ /dev/null @@ -1,41 +0,0 @@ -; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. - -;; Rudimentary test suite - -(define-test-suite toy-grammars-tests) - -(define-test-case g08 toy-grammars-tests - (check (parse g08 1 'lr 0 i08-1) => #f) - (check (parse g08 1 'slr 0 i08-1) => #f) - (check-exception (parse g08 1 'lr 0 i08-2)) - (check-exception (parse g08 1 'slr 0 i08-2)) - (check-exception (parse g08 1 'lr 0 i08-3)) - (check-exception (parse g08 1 'slr 0 i08-3))) - -(define-test-case g10 toy-grammars-tests - (check (parse g10 1 'lr 0 i10-1) => 147) - (check (parse g10 1 'slr 0 i10-1) => 147) - (check-exception (parse g10 1 'lr 0 i10-2)) - (check-exception (parse g10 1 'slr 0 i10-2)) - (check-exception (parse g10 1 'lr 0 i10-3)) - (check-exception (parse g10 1 'slr 0 i10-3))) - -(define-test-case g10-k=2 toy-grammars-tests - (check (parse g10 2 'lr 0 i10-1) => 147) - (check (parse g10 2 'slr 0 i10-1) => 147) - (check-exception (parse g10 2 'lr 0 i10-2)) - (check-exception (parse g10 2 'slr 0 i10-2)) - (check-exception (parse g10 2 'lr 0 i10-3)) - (check-exception (parse g10 2 'slr 0 i10-3))) - -(define-test-case g10-error toy-grammars-tests - (check (parse g10-error 1 'lr 0 i10e-1) => 147) - (check (parse g10-error 1 'slr 0 i10e-1) => 147) - (check (parse g10-error 1 'lr 0 i10e-2) => 28) - (check (parse g10-error 1 'slr 0 i10e-2) => 28) - (check-exception (parse g10-error 1 'lr 0 i10e-3)) - (check-exception (parse g10-error 1 'slr 0 i10e-3))) - -(define-test-case g14 toy-grammars-tests - (check (parse g14 1 'lr 0 i14-1) => #f) - (check (parse g14 1 'slr 0 i14-1) => #f)) diff --git a/doc/examples/essence/toy-grammars.scm b/doc/examples/essence/toy-grammars.scm deleted file mode 100644 index 821f971..0000000 --- a/doc/examples/essence/toy-grammars.scm +++ /dev/null @@ -1,83 +0,0 @@ -; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. - -; Balanced parentheses - -(define-grammar g00 g00-symbol - (l) - S - ((S ((l) $1)))) - -(define-grammar g08 g08-symbol - (l r) - S - ((S ((S T) $1) - ((T) $1)) - (T ((l S r) $1) - ((l r) $1)))) - -; Constant arithmetic expressions - -(define-grammar g10 g10-symbol - (+ - * / l r n) - E - ((E ((T) $1) - ((T + E) (+ $1 $3)) - ((T - E) (- $1 $3))) - (T ((P) $1) - ((P * T) (* $1 $3)) - ((P / T) (/ $1 $3))) - (P ((n) $1) - ((l E r) $2)))) - -(define-grammar g10-error g10-error-symbol - (+ - * / l r n) - E - ((E ((T) $1) - (($error) 0) - ((T + E) (+ $1 $3)) - ((T - E) (- $1 $3))) - (T ((P) $1) - ((P * T) (* $1 $3)) - ((P / T) (/ $1 $3))) - (P ((n) $1) - ((l E r) $2) - ((l $error r) 0)))) - -(define-grammar g13 g13-symbol - (comma blah dot) - S - ((SLK (() $1) - ((NESLK) $1)) - (NESLK ((N) $1) - ((NESLK K N) $1)) - (SLD (() $1) - ((NESLD) $1)) - (NESLD ((N) $1) - ((NESLD P N) $1)) - (S ((SLK) $1) - ((SLD) $1)) - (K ((comma) $1)) - (P ((dot) $1)) - (N ((blah) $1)))) - -;; javascript example expanded - -(define-grammar g14 g14-symbol - (const comma colon lcurly rcurly lbracket rbracket) - S - ((S ((E) $1)) - (E ((const) $1) - ((lcurly OL rcurly) $1) - ((lbracket AL rbracket) $1)) - (C ((comma) $1)) - (A ((const colon E) $1)) - (OL (() $1) - ((ON) $1)) - (ON ((A) $1) - ((ON C A) $1)) - (AL (() $1) - ((AN) $1)) - (AN ((E) $1) - ((AN C E) $1)))) - - diff --git a/doc/examples/essence/toy-inputs.scm b/doc/examples/essence/toy-inputs.scm deleted file mode 100644 index b266a9d..0000000 --- a/doc/examples/essence/toy-inputs.scm +++ /dev/null @@ -1,75 +0,0 @@ -; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. - -(define i08-1 (list (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol r) #f))) - -(define i08-2 (list (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol r) #f))) - -(define i08-3 (list (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol l) #f))) - -(define i10-1 (list (cons (enum g10-symbol l) #f) - (cons (enum g10-symbol n) 4) - (cons (enum g10-symbol +) #f) - (cons (enum g10-symbol n) 17) - (cons (enum g10-symbol r) #f) - (cons (enum g10-symbol *) #f) - (cons (enum g10-symbol n) 7))) - -(define i10-2 (list (cons (enum g10-symbol l) #f) - (cons (enum g10-symbol n) 4) - (cons (enum g10-symbol +) #f) - (cons (enum g10-symbol n) 15) - (cons (enum g10-symbol n) 17) - (cons (enum g10-symbol r) #f) - (cons (enum g10-symbol *) #f) - (cons (enum g10-symbol n) 7))) - -(define i10-3 (list (cons (enum g10-symbol l) #f) - (cons (enum g10-symbol n) 4) - (cons (enum g10-symbol +) #f) - (cons (enum g10-symbol n) 17) - (cons (enum g10-symbol *) #f) - (cons (enum g10-symbol n) 7))) - -(define i10e-1 (list (cons (enum g10-error-symbol l) #f) - (cons (enum g10-error-symbol n) 4) - (cons (enum g10-error-symbol +) #f) - (cons (enum g10-error-symbol n) 17) - (cons (enum g10-error-symbol r) #f) - (cons (enum g10-error-symbol *) #f) - (cons (enum g10-error-symbol n) 7))) - -(define i10e-2 (list (cons (enum g10-error-symbol l) #f) - (cons (enum g10-error-symbol n) 4) - (cons (enum g10-error-symbol +) #f) - (cons (enum g10-error-symbol n) 15) - (cons (enum g10-error-symbol n) 17) - (cons (enum g10-error-symbol r) #f) - (cons (enum g10-error-symbol *) #f) - (cons (enum g10-error-symbol n) 7))) - -(define i10e-3 (list (cons (enum g10-error-symbol l) #f) - (cons (enum g10-error-symbol n) 4) - (cons (enum g10-error-symbol +) #f) - (cons (enum g10-error-symbol n) 17) - (cons (enum g10-error-symbol *) #f) - (cons (enum g10-error-symbol n) 7))) - -(define i14-1 (list (cons (enum g14-symbol lbracket) #f) - (cons (enum g14-symbol const) #f) - (cons (enum g14-symbol rbracket) #f))) diff --git a/doc/examples/lawrence/ASS_370_grammar_test.clj b/doc/examples/lawrence/ASS_370_grammar_test.clj deleted file mode 100644 index 6d47e30..0000000 --- a/doc/examples/lawrence/ASS_370_grammar_test.clj +++ /dev/null @@ -1,90 +0,0 @@ -(ns active.lawrence.ASS_370_grammar_test - (:require [active.lawrence.grammar :refer :all])) - -(define-grammar RR - (:op :r1 :r2) - S - ((S ((:op) $1) - (:r1) $2 - (:r2) $3))) - -(define-grammar g08 - (:l :r) - S - ((S ((S T) $1) - ((T) $1)) - (T ((:l S :r) $1) - ((:l :r) $1)))) - -; Constant arithmetic expressions - -(define-grammar g10 - (:+ :- :* :/ :l :r :n) - E - ((E ((T) $1) - ((T :+ E) (+ $1 $3)) - ((T :- E) (- $1 $3))) - (T ((P) $1) - ((P :* T) (* $1 $3)) - ((P :/ T) (/ $1 $3))) - (P ((:n) $1) - ((:l E :r) $2)))) - -(define-grammar g10-error - (:+ :- :* :/ :l :r :n) - E - ((E ((T) $1) - ((:$error) 0) - ((T :+ E) (+ $1 $3)) - ((T :- E) (- $1 $3))) - (T ((P) $1) - ((P :* T) (* $1 $3)) - ((P :/ T) (/ $1 $3))) - (P ((:n) $1) - ((:l E :r) $2) - ((:l :$error :r) 0)))) - -(define-grammar g13 - (:comma :blah :dot) - S - ((SLK (() nil) - ((NESLK) $1)) - (NESLK ((N) $1) - ((NESLK K N) $1)) - (SLD (() nil) - ((NESLD) $1)) - (NESLD ((N) $1) - ((NESLD P N) $1)) - (S ((SLK) $1) - ((SLD) $1)) - (K ((:comma) $1)) - (P ((:dot) $1)) - (N ((:blah) $1)))) - -;; javascript example expanded - -(define-grammar g14 - (:const :comma :colon :lcurly :rcurly :lbracket :rbracket) - S - ((S ((E) $1)) - (E ((:const) $1) - ((:lcurly OL :rcurly) $1) - ((:lbracket AL :rbracket) $1)) - (C ((:comma) $1)) - (A ((:const :colon E) $1)) - (OL (() nil) - ((ON) $1)) - (ON ((A) $1) - ((ON C A) $1)) - (AL (() nil) - ((AN) $1)) - (AN ((E) $1) - ((AN C E) $1)))) - -(define-grammar goptional - (:foo :bar) - S - ((S ((:bar O) $2)) - (O ((:foo) :present) - (() :absent)))) - diff --git a/doc/examples/lawrence/Fortran77Lexer.g4 b/doc/examples/lawrence/Fortran77Lexer.g4 deleted file mode 100644 index 91e9acc..0000000 --- a/doc/examples/lawrence/Fortran77Lexer.g4 +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Fortran 77 grammar for ANTLR 2.7.5 - * Adadpted from Fortran 77 PCCTS grammar by Olivier Dragon - * Original PCCTS grammar by Terence Parr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - */ - -/** - * ported to Antlr4 by Tom Everett - */ - -/* - * Updated by Tom Everett, 2018 - */ - -// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false -// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine -// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true - -lexer grammar Fortran77Lexer; - -options { - superClass = Fortran77LexerBase; -} - -// Insert here @header for C++ lexer. - -PROGRAM: 'program' | 'PROGRAM'; - -ENTRY: 'entry' | 'ENTRY'; - -FUNCTION: 'function' | 'FUNCTION'; - -BLOCK: 'block' | 'BLOCK'; - -SUBROUTINE: 'subroutine' | 'SUBROUTINE'; - -END: 'END' | 'end'; - -DIMENSION: 'dimension' | 'DIMENSION'; - -REAL: 'REAL' | 'real'; - -EQUIVALENCE: 'EQUIVALENCE' | 'equivalence'; - -COMMON: 'common' | 'COMMON'; - -POINTER: 'pointer' | 'POINTER'; - -IMPLICIT: 'implicit' | 'IMPLICIT'; - -NONE: 'none' | 'NONE'; - -CHARACTER: 'character' | 'CHARACTER'; - -PARAMETER: 'parameter' | 'PARAMETER'; - -EXTERNAL: 'external' | 'EXTERNAL'; - -INTRINSIC: 'intrinsic' | 'INTRINSIC'; - -SAVE: 'save' | 'SAVE'; - -DATA: 'data' | 'DATA'; - -GO: 'GO' | 'go'; - -GOTO: 'GOTO' | 'goto'; - -IF: 'IF' | 'if'; - -THEN: 'THEN' | 'then'; - -ELSE: 'ELSE' | 'else'; - -ENDIF: 'ENDIF' | 'endif'; - -ELSEIF: 'ELSEIF' | 'elseif'; - -DO: 'DO' | 'do'; - -CONTINUE: 'CONTINUE' | 'continue'; - -STOP: 'STOP' | 'stop'; - -ENDDO: 'ENDDO' | 'enddo'; - -PAUSE: 'pause' | 'PAUSE'; - -WRITE: 'WRITE' | 'write'; - -READ: 'READ' | 'read'; - -PRINT: 'PRINT' | 'print'; - -OPEN: 'OPEN' | 'open'; - -FMT: 'FMT' | 'fmt'; - -UNIT: 'UNIT' | 'unit'; - -ERR: 'err' | 'ERR'; - -IOSTAT: 'IOSTAT' | 'iostat'; - -FORMAT: 'FORMAT' | 'format'; - -LET: 'LET' | 'let'; - -CALL: 'CALL' | 'call'; - -RETURN: 'RETURN' | 'return'; - -CLOSE: 'CLOSE' | 'close'; - -DOUBLE: 'DOUBLE' | 'double'; - -IOSTART: 'IOSTART' | 'iostart'; - -SEQUENTIAL: 'SEQUENTIAL' | 'sequential'; - -LABEL: 'LABEL' | 'label'; - -FILE: 'file' | 'FILE'; - -STATUS: 'STATUS' | 'status'; - -ACCESS: 'ACCESS' | 'access'; - -POSITION: 'POSITION' | 'position'; - -FORM: 'FORM' | 'form'; - -RECL: 'RECL' | 'recl'; - -BLANK: 'BLANK' | 'blank'; - -EXIST: 'EXIST' | 'exist'; - -OPENED: 'OPENED' | 'opened'; - -NUMBER: 'NUMBER' | 'number'; - -NAMED: 'NAMED' | 'named'; - -NAME_: 'NAME' | 'name'; - -FORMATTED: 'FORMATTED' | 'formatted'; - -UNFORMATTED: 'UNFORMATTED' | 'unformatted'; - -NEXTREC: 'NEXTREC' | 'nextrec'; - -INQUIRE: 'INQUIRE' | 'inquire'; - -BACKSPACE: 'BACKSPACE' | 'backspace'; - -ENDFILE: 'ENDFILE' | 'endfile'; - -REWIND: 'REWIND' | 'rewind'; - -DOLLAR: '$'; - -COMMA: ','; - -LPAREN: '('; - -RPAREN: ')'; - -COLON: ':'; - -ASSIGN: '='; - -MINUS: '-'; - -PLUS: '+'; - -DIV: '/'; - -fragment STARCHAR: '*'; - -POWER: '**'; - -LNOT: '.not.' | '.NOT.'; - -LAND: '.and.' | '.AND.'; - -LOR: '.or.' | '.OR.'; - -EQV: '.eqv.' | '.EQV.'; - -NEQV: '.neqv.' | '.NEQV.'; - -XOR: '.xor.' | '.XOR.'; - -EOR: '.eor.' | '.EOR.'; - -LT: '.lt.' | '.LT.'; - -LE: '.le.' | '.LE.'; - -GT: '.gt.' | '.GT.'; - -GE: '.ge.' | '.GE.'; - -NE: '.ne.' | '.NE.'; - -EQ: '.eq.' | '.EQ.'; - -TRUE: '.true.' | '.TRUE.'; - -FALSE: '.false.' | '.FALSE.'; - -XCON: 'XCON'; - -PCON: 'PCON'; - -FCON: 'FCON'; - -CCON: 'CCON'; - -HOLLERITH: 'HOLLERITH'; - -CONCATOP: 'CONCATOP'; - -CTRLDIRECT: 'CTRLDIRECT'; - -CTRLREC: 'CTRLREC'; - -TO: 'TO' | 'to'; - -SUBPROGRAMBLOCK: 'SUBPROGRAMBLOCK'; - -DOBLOCK: 'DOBLOCK'; - -AIF: 'AIF'; - -THENBLOCK: 'THENBLOCK'; - -ELSEBLOCK: 'ELSEBLOCK'; - -CODEROOT: 'CODEROOT'; - -COMPLEX: 'COMPLEX' | 'complex'; - -PRECISION: 'PRECISION' | 'precision'; - -INTEGER: 'INTEGER' | 'integer'; - -LOGICAL: 'LOGICAL' | 'logical'; - -fragment CONTINUATION: ~ ('0' | ' '); - -fragment ALNUM: (ALPHA | NUM); - -fragment HEX: (NUM | 'a' .. 'f'); - -fragment SIGN: ('+' | '-'); - -fragment FDESC: ('i' | 'f' | 'd') (NUM)+ '.' (NUM)+ | ('e' | 'g') (NUM)+ '.' (NUM)+ ('e' (NUM)+)?; - -fragment EXPON: ('e' | 'E' | 'd' | 'D') (SIGN)? (NUM)+; - -fragment ALPHA: ('a' .. 'z') | ('A' .. 'Z'); - -fragment NUM: ('0' .. '9'); - -// '' is used to drop the charater when forming the lexical token -// Strings are assumed to start with a single quote (') and two -// single quotes is meant as a literal single quote - -SCON: - '\'' ( - '\'' '\'' - | ~ ('\'' | '\n' | '\r') - | (('\n' | '\r' ('\n')?) ' ' CONTINUATION) ('\n' | '\r' ('\n')?) ' ' CONTINUATION - )* '\'' -; - -RCON: NUM+ '.' NUM* EXPON?; - -ICON: NUM+; - -NAME: (('i' | 'f' | 'd' | 'g' | 'e') (NUM)+ '.') FDESC | (ALNUM+) (ALNUM)*; - -COMMENT: {this.IsColumnZero()}? ('c' | STARCHAR) (~ [\r\n])* EOL -> channel(HIDDEN); - -STAR: STARCHAR; - -STRINGLITERAL: '"' ~ ["\r\n]* '"'; - -EOL: [\r\n]+; - -LINECONT: ((EOL ' $') | (EOL ' +')) -> skip; - -WS: [\t ]+ -> skip; \ No newline at end of file diff --git a/doc/examples/lawrence/Fortran77Parser.g4 b/doc/examples/lawrence/Fortran77Parser.g4 deleted file mode 100644 index cd3b66f..0000000 --- a/doc/examples/lawrence/Fortran77Parser.g4 +++ /dev/null @@ -1,935 +0,0 @@ -/* - * Fortran 77 grammar for ANTLR 2.7.5 - * Adadpted from Fortran 77 PCCTS grammar by Olivier Dragon - * Original PCCTS grammar by Terence Parr - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - */ - -/** - * ported to Antlr4 by Tom Everett - */ - -/* - * Updated by Tom Everett, 2018 - */ - -// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false -// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging - -parser grammar Fortran77Parser; - -options - { - tokenVocab = Fortran77Lexer; -} - -program - : executableUnit+ EOL* EOF - ; - -executableUnit - : functionSubprogram - | mainProgram - | subroutineSubprogram - | blockdataSubprogram - ; - -mainProgram - : (programStatement)? subprogramBody - ; - -functionSubprogram - : functionStatement subprogramBody - ; - -subroutineSubprogram - : subroutineStatement subprogramBody - ; - -blockdataSubprogram - : blockdataStatement subprogramBody - ; - -otherSpecificationStatement - : dimensionStatement - | equivalenceStatement - | intrinsicStatement - | saveStatement - ; - -executableStatement - : ( - assignmentStatement - | gotoStatement - | ifStatement - | doStatement - | continueStatement - | stopStatement - | pauseStatement - | readStatement - | writeStatement - | printStatement - | rewindStatement - | backspaceStatement - | openStatement - | closeStatement - | endfileStatement - | inquireStatement - | callStatement - | returnStatement - ) - ; - -programStatement - : PROGRAM NAME EOL - ; - -entryStatement - : ENTRY NAME (LPAREN namelist RPAREN)? - ; - -functionStatement - : type_? FUNCTION NAME LPAREN namelist? RPAREN EOL? - ; - -blockdataStatement - : BLOCK NAME - ; - -subroutineStatement - : SUBROUTINE NAME (LPAREN namelist? RPAREN)? EOL? - ; - -namelist - : identifier (COMMA identifier)* - ; - -statement - : entryStatement - | implicitStatement - | parameterStatement - | typeStatement - | commonStatement - | pointerStatement - | externalStatement - | otherSpecificationStatement - | dataStatement - | (statementFunctionStatement) statementFunctionStatement - | executableStatement - ; - -subprogramBody - : wholeStatement+ endStatement - ; - -wholeStatement - : LABEL? statement EOL - ; - -endStatement - : LABEL? END - ; - -dimensionStatement - : DIMENSION arrayDeclarators - ; - -arrayDeclarator - : (NAME | REAL) LPAREN arrayDeclaratorExtents RPAREN - ; - -arrayDeclarators - : arrayDeclarator (COMMA arrayDeclarator)* - ; - -arrayDeclaratorExtents - : arrayDeclaratorExtent (COMMA arrayDeclaratorExtent)* - ; - -arrayDeclaratorExtent - : iexprCode (COLON (iexprCode | STAR))? - | STAR - ; - -equivalenceStatement - : EQUIVALENCE equivEntityGroup (COMMA equivEntityGroup)* - ; - -equivEntityGroup - : LPAREN equivEntity (COMMA equivEntity)* RPAREN - ; - -equivEntity - : varRef - ; - -commonStatement - : COMMON (commonBlock (COMMA commonBlock)* | commonItems) - ; - -commonName - : DIV (NAME DIV | DIV) - ; - -commonItem - : NAME - | arrayDeclarator - ; - -commonItems - : commonItem (COMMA commonItem)* - ; - -commonBlock - : commonName commonItems - ; - -typeStatement - : typename_ typeStatementNameList - | characterWithLen typeStatementNameCharList - ; - -typeStatementNameList - : typeStatementName (COMMA typeStatementName)* - ; - -typeStatementName - : NAME - | arrayDeclarator - ; - -typeStatementNameCharList - : typeStatementNameChar (COMMA typeStatementNameChar)* - ; - -typeStatementNameChar - : typeStatementName (typeStatementLenSpec)? - ; - -typeStatementLenSpec - : STAR lenSpecification - ; - -typename_ - : ( - REAL - | COMPLEX (STAR ICON?)? - | DOUBLE COMPLEX - | DOUBLE PRECISION - | INTEGER - | LOGICAL - | CHARACTER - ) - ; - -type_ - : typename_ - | characterWithLen - ; - -typenameLen - : STAR ICON - ; - -pointerStatement - : POINTER pointerDecl (COMMA pointerDecl)* - ; - -pointerDecl - : LPAREN NAME COMMA NAME RPAREN - ; - -implicitStatement - : IMPLICIT (implicitNone | implicitSpecs) - ; - -implicitSpec - : type_ LPAREN implicitLetters RPAREN - ; - -implicitSpecs - : implicitSpec (COMMA implicitSpec)* - ; - -implicitNone - : NONE - ; - -implicitLetter - : NAME - ; - -implicitRange - : implicitLetter (MINUS implicitLetter)? - ; - -implicitLetters - : implicitRange (COMMA implicitRange)* - ; - -lenSpecification - : (LPAREN STAR RPAREN) LPAREN STAR RPAREN - | ICON - | LPAREN intConstantExpr RPAREN - ; - -characterWithLen - : characterExpression (cwlLen)? - ; - -cwlLen - : STAR lenSpecification - ; - -parameterStatement - : PARAMETER LPAREN paramlist RPAREN - ; - -paramlist - : paramassign (COMMA paramassign)* - ; - -paramassign - : NAME ASSIGN constantExpr - ; - -externalStatement - : EXTERNAL namelist - ; - -intrinsicStatement - : INTRINSIC namelist - ; - -saveStatement - : SAVE (saveEntity (COMMA saveEntity)*)? - ; - -saveEntity - : (NAME | DIV NAME DIV) - ; - -dataStatement - : DATA dataStatementEntity ((COMMA)? dataStatementEntity)* - ; - -dataStatementItem - : varRef - | dataImpliedDo - ; - -dataStatementMultiple - : ((ICON | NAME) STAR)? (constant | NAME) - ; - -dataStatementEntity - : dse1 dse2 - ; - -dse1 - : dataStatementItem (COMMA dataStatementItem)* DIV - ; - -dse2 - : dataStatementMultiple (COMMA dataStatementMultiple)* DIV - ; - -dataImpliedDo - : LPAREN dataImpliedDoList COMMA dataImpliedDoRange RPAREN - ; - -dataImpliedDoRange - : NAME ASSIGN intConstantExpr COMMA intConstantExpr (COMMA intConstantExpr)? - ; - -dataImpliedDoList - : dataImpliedDoListWhat - | COMMA dataImpliedDoList - ; - -dataImpliedDoListWhat - : (varRef | dataImpliedDo) - ; - -gotoStatement - : (GO TO | GOTO) (unconditionalGoto | computedGoto | assignedGoto) - ; - -unconditionalGoto - : lblRef - ; - -computedGoto - : LPAREN labelList RPAREN (COMMA)? integerExpr - ; - -lblRef - : ICON - ; - -labelList - : lblRef (COMMA lblRef)* - ; - -assignedGoto - : NAME ((COMMA)? LPAREN labelList RPAREN)? - ; - -ifStatement - : IF LPAREN logicalExpression RPAREN ( - blockIfStatement - | logicalIfStatement - | arithmeticIfStatement - ) - ; - -arithmeticIfStatement - : lblRef COMMA lblRef COMMA lblRef - ; - -logicalIfStatement - : executableStatement - ; - -blockIfStatement - : firstIfBlock elseIfStatement* elseStatement? endIfStatement - ; - -firstIfBlock - : THEN EOL? wholeStatement+ - ; - -elseIfStatement - : (ELSEIF | (ELSE IF)) LPAREN logicalExpression RPAREN THEN EOL? wholeStatement+ - ; - -elseStatement - : ELSE EOL? wholeStatement+ - ; - -endIfStatement - : (ENDIF | END IF) - ; - -doStatement - : DO (doWithLabel | doWithEndDo) - ; - -doVarArgs - : variableName ASSIGN intRealDpExpr COMMA intRealDpExpr (COMMA intRealDpExpr)? - ; - -doWithLabel - : lblRef COMMA? doVarArgs EOL? doBody EOL? continueStatement - ; - -doBody - : (wholeStatement)+ - ; - -doWithEndDo - : doVarArgs EOL? doBody EOL? enddoStatement - ; - -enddoStatement - : (ENDDO | (END DO)) - ; - -continueStatement - : lblRef? CONTINUE - ; - -stopStatement - : STOP (ICON | HOLLERITH)? - ; - -pauseStatement - : PAUSE (ICON | HOLLERITH) - ; - -writeStatement - : WRITE LPAREN controlInfoList RPAREN ((COMMA? ioList)+)? - ; - -readStatement - : READ (formatIdentifier ((COMMA ioList)+)?) - ; - -printStatement - : PRINT (formatIdentifier ((COMMA ioList)+)?) - ; - -assignmentStatement - : varRef ASSIGN expression - ; - -controlInfoList - : controlInfoListItem (COMMA controlInfoListItem)* - ; - -controlErrSpec - : controlErr ASSIGN (lblRef | NAME) - ; - -controlInfoListItem - : unitIdentifier - | (HOLLERITH | SCON) - | controlFmt ASSIGN formatIdentifier - | controlUnit ASSIGN unitIdentifier - | controlRec ASSIGN integerExpr - | controlEnd ASSIGN lblRef - | controlErrSpec - | controlIostat ASSIGN varRef - ; - -ioList - : (ioListItem COMMA NAME ASSIGN) ioListItem - | (ioListItem COMMA ioListItem) ioListItem COMMA ioList - | ioListItem - ; - -ioListItem - : (LPAREN ioList COMMA NAME ASSIGN) ioImpliedDoList - | expression - ; - -ioImpliedDoList - : LPAREN ioList COMMA NAME ASSIGN intRealDpExpr COMMA intRealDpExpr (COMMA intRealDpExpr)? RPAREN - ; - -openStatement - : OPEN LPAREN openControl (COMMA openControl)* RPAREN - ; - -openControl - : unitIdentifier - | controlUnit ASSIGN unitIdentifier - | controlErrSpec - | controlFile ASSIGN characterExpression - | controlStatus ASSIGN characterExpression - | (controlAccess | controlPosition) ASSIGN characterExpression - | controlForm ASSIGN characterExpression - | controlRecl ASSIGN integerExpr - | controlBlank ASSIGN characterExpression - | controlIostat ASSIGN varRef - ; - -controlFmt - : FMT - ; - -controlUnit - : UNIT - ; - -controlRec - : NAME - ; - -controlEnd - : END - ; - -controlErr - : ERR - ; - -controlIostat - : IOSTART - ; - -controlFile - : FILE - ; - -controlStatus - : STATUS - ; - -controlAccess - : ACCESS - ; - -controlPosition - : POSITION - ; - -controlForm - : FORM - ; - -controlRecl - : RECL - ; - -controlBlank - : BLANK - ; - -controlExist - : EXIST - ; - -controlOpened - : OPENED - ; - -controlNumber - : NUMBER - ; - -controlNamed - : NAMED - ; - -controlName - : NAME - ; - -controlSequential - : SEQUENTIAL - ; - -controlDirect - : NAME - ; - -controlFormatted - : FORMATTED - ; - -controlUnformatted - : UNFORMATTED - ; - -controlNextrec - : NEXTREC - ; - -closeStatement - : CLOSE LPAREN closeControl (COMMA closeControl)* RPAREN - ; - -closeControl - : unitIdentifier - | controlUnit ASSIGN unitIdentifier - | controlErrSpec - | controlStatus ASSIGN characterExpression - | controlIostat ASSIGN varRef - ; - -inquireStatement - : INQUIRE LPAREN inquireControl (COMMA inquireControl)* RPAREN - ; - -inquireControl - : controlUnit ASSIGN unitIdentifier - | controlFile ASSIGN characterExpression - | controlErrSpec - | ( - controlIostat - | controlExist - | controlOpened - | controlNumber - | controlNamed - | controlName - | controlAccess - | controlSequential - | controlDirect - | controlForm - | controlFormatted - | controlUnformatted - | controlRecl - | controlNextrec - | controlBlank - ) ASSIGN varRef - | unitIdentifier - ; - -backspaceStatement - : BACKSPACE berFinish - ; - -endfileStatement - : ENDFILE berFinish - ; - -rewindStatement - : REWIND berFinish - ; - -berFinish - : (unitIdentifier (unitIdentifier) | LPAREN berFinishItem (COMMA berFinishItem)* RPAREN) - ; - -berFinishItem - : unitIdentifier - | controlUnit ASSIGN unitIdentifier - | controlErrSpec - | controlIostat ASSIGN varRef - ; - -unitIdentifier - : iexpr - | STAR - ; - -formatIdentifier - : (SCON | HOLLERITH) - | iexpr - | STAR - ; - -formatStatement - : FORMAT LPAREN fmtSpec RPAREN - ; - -fmtSpec - : (formatedit | formatsep (formatedit)?) ( - formatsep (formatedit)? - | COMMA (formatedit | formatsep (formatedit)?) - )* - ; - -formatsep - : DIV - | COLON - | DOLLAR - ; - -formatedit - : XCON - | editElement - | ICON editElement - | (PLUS | MINUS)? PCON ((ICON)? editElement)? - ; - -editElement - : (FCON | SCON | HOLLERITH | NAME) - | LPAREN fmtSpec RPAREN - ; - -statementFunctionStatement - : LET sfArgs ASSIGN expression - ; - -sfArgs - : NAME LPAREN namelist RPAREN - ; - -callStatement - : CALL subroutineCall - ; - -subroutineCall - : NAME (LPAREN (callArgumentList)? RPAREN)? - ; - -callArgumentList - : callArgument (COMMA callArgument)* - ; - -callArgument - : expression - | STAR lblRef - ; - -returnStatement - : RETURN (integerExpr)? - ; - -expression - : ncExpr (COLON ncExpr)? - ; - -ncExpr - : lexpr0 (concatOp lexpr0)* - ; - -lexpr0 - : lexpr1 ((NEQV | EQV) lexpr1)* - ; - -lexpr1 - : lexpr2 (LOR lexpr2)* - ; - -lexpr2 - : lexpr3 (LAND lexpr3)* - ; - -lexpr3 - : LNOT lexpr3 - | lexpr4 - ; - -lexpr4 - : aexpr0 ((LT | LE | EQ | NE | GT | GE) aexpr0)? - ; - -aexpr0 - : aexpr1 ((PLUS | MINUS) aexpr1)* - ; - -aexpr1 - : aexpr2 ((STAR | DIV) aexpr2)* - ; - -aexpr2 - : (PLUS | MINUS)* aexpr3 - ; - -aexpr3 - : aexpr4 (POWER aexpr4)* - ; - -aexpr4 - : unsignedArithmeticConstant - | (HOLLERITH | SCON) - | logicalConstant - | varRef - | LPAREN expression RPAREN - ; - -iexpr - : iexpr1 ((PLUS | MINUS) iexpr1)* - ; - -iexprCode - : iexpr1 ((PLUS | MINUS) iexpr1)* - ; - -iexpr1 - : iexpr2 ((STAR | DIV) iexpr2)* - ; - -iexpr2 - : (PLUS | MINUS)* iexpr3 - ; - -iexpr3 - : iexpr4 (POWER iexpr3)? - ; - -iexpr4 - : ICON - | varRefCode - | LPAREN iexprCode RPAREN - ; - -constantExpr - : expression - ; - -arithmeticExpression - : expression - ; - -integerExpr - : iexpr - ; - -intRealDpExpr - : expression - ; - -arithmeticConstExpr - : expression - ; - -intConstantExpr - : expression - ; - -characterExpression - : expression - ; - -concatOp - : DIV DIV - ; - -logicalExpression - : expression - ; - -logicalConstExpr - : expression - ; - -arrayElementName - : NAME LPAREN integerExpr (COMMA integerExpr)* RPAREN - ; - -subscripts - : LPAREN (expression (COMMA expression)*)? RPAREN - ; - -varRef - : (NAME | REAL) (subscripts (substringApp)?)? - ; - -varRefCode - : NAME (subscripts (substringApp)?)? - ; - -substringApp - : LPAREN (ncExpr)? COLON (ncExpr)? RPAREN - ; - -variableName - : NAME - ; - -arrayName - : NAME - ; - -subroutineName - : NAME - ; - -functionName - : NAME - ; - -constant - : ((PLUS | MINUS))? unsignedArithmeticConstant - | (SCON | HOLLERITH) - | logicalConstant - ; - -unsignedArithmeticConstant - : (ICON | RCON) - | complexConstant - ; - -complexConstant - : LPAREN ((PLUS | MINUS))? (ICON | RCON) COMMA ((PLUS | MINUS))? (ICON | RCON) RPAREN - ; - -logicalConstant - : (TRUE | FALSE) - ; - -// needed because Fortran doesn't have reserved keywords. Putting the rule -// 'keyword" instead of a few select keywords breaks the parser with harmful -// non-determinisms -identifier - : NAME - | REAL - ; \ No newline at end of file diff --git a/doc/examples/lawrence/fortran77.scm b/doc/examples/lawrence/fortran77.scm deleted file mode 100644 index dd2b647..0000000 --- a/doc/examples/lawrence/fortran77.scm +++ /dev/null @@ -1,13 +0,0 @@ -(define-grammar fortran77 fortran77-symbol - (:executableUnit) - program - ((program ((executableUnit) $1) - (((functionSubprogram) $2) - ((mainProgram) $2) - ((subroutineSubprogram) $2) - ((blockdataSubprogram)))) - (((mainProgram) $3) - ((programStatement) subprogramBody) - ((subProgramBody) $4) - )) - ) \ No newline at end of file diff --git a/doc/examples/lawrence/toy-grammars-test.clj b/doc/examples/lawrence/toy-grammars-test.clj deleted file mode 100644 index 9fba94e..0000000 --- a/doc/examples/lawrence/toy-grammars-test.clj +++ /dev/null @@ -1,41 +0,0 @@ -; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. - -;; Rudimentary test suite - -(define-test-suite toy-grammars-tests) - -(define-test-case g08 toy-grammars-tests - (check (parse g08 1 'lr 0 i08-1) => #f) - (check (parse g08 1 'slr 0 i08-1) => #f) - (check-exception (parse g08 1 'lr 0 i08-2)) - (check-exception (parse g08 1 'slr 0 i08-2)) - (check-exception (parse g08 1 'lr 0 i08-3)) - (check-exception (parse g08 1 'slr 0 i08-3))) - -(define-test-case g10 toy-grammars-tests - (check (parse g10 1 'lr 0 i10-1) => 147) - (check (parse g10 1 'slr 0 i10-1) => 147) - (check-exception (parse g10 1 'lr 0 i10-2)) - (check-exception (parse g10 1 'slr 0 i10-2)) - (check-exception (parse g10 1 'lr 0 i10-3)) - (check-exception (parse g10 1 'slr 0 i10-3))) - -(define-test-case g10-k=2 toy-grammars-tests - (check (parse g10 2 'lr 0 i10-1) => 147) - (check (parse g10 2 'slr 0 i10-1) => 147) - (check-exception (parse g10 2 'lr 0 i10-2)) - (check-exception (parse g10 2 'slr 0 i10-2)) - (check-exception (parse g10 2 'lr 0 i10-3)) - (check-exception (parse g10 2 'slr 0 i10-3))) - -(define-test-case g10-error toy-grammars-tests - (check (parse g10-error 1 'lr 0 i10e-1) => 147) - (check (parse g10-error 1 'slr 0 i10e-1) => 147) - (check (parse g10-error 1 'lr 0 i10e-2) => 28) - (check (parse g10-error 1 'slr 0 i10e-2) => 28) - (check-exception (parse g10-error 1 'lr 0 i10e-3)) - (check-exception (parse g10-error 1 'slr 0 i10e-3))) - -(define-test-case g14 toy-grammars-tests - (check (parse g14 1 'lr 0 i14-1) => #f) - (check (parse g14 1 'slr 0 i14-1) => #f)) diff --git a/doc/examples/lawrence/toy-grammars.scm b/doc/examples/lawrence/toy-grammars.scm deleted file mode 100644 index afd4859..0000000 --- a/doc/examples/lawrence/toy-grammars.scm +++ /dev/null @@ -1,83 +0,0 @@ -; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. - -; Balanced parentheses - -(define-grammar g00 g00-symbol - (:l) - S - ((S ((l) $1)))) - -(define-grammar g08 g08-symbol - (:l :r) - S - ((S ((S T) $1) - ((T) $1)) - (T ((l S r) $1) - ((l r) $1)))) - -; Constant arithmetic expressions - -(define-grammar g10 g10-symbol - (;+ :- :* :/ :l :r :n) - E - ((E ((T) $1) - ((T + E) (+ $1 $3)) - ((T - E) (- $1 $3))) - (T ((P) $1) - ((P * T) (* $1 $3)) - ((P / T) (/ $1 $3))) - (P ((n) $1) - ((l E r) $2)))) - -(define-grammar g10-error g10-error-symbol - (:+ :- :* :/ ;l :r :n) - E - ((E ((T) $1) - (($error) 0) - ((T + E) (+ $1 $3)) - ((T - E) (- $1 $3))) - (T ((P) $1) - ((P * T) (* $1 $3)) - ((P / T) (/ $1 $3))) - (P ((n) $1) - ((l E r) $2) - ((l $error r) 0)))) - -(define-grammar g13 g13-symbol - (:comma :blah :dot) - S - ((SLK (() $1) - ((NESLK) $1)) - (NESLK ((N) $1) - ((NESLK K N) $1)) - (SLD (() $1) - ((NESLD) $1)) - (NESLD ((N) $1) - ((NESLD P N) $1)) - (S ((SLK) $1) - ((SLD) $1)) - (K ((comma) $1)) - (P ((dot) $1)) - (N ((blah) $1)))) - -;; javascript example expanded - -(define-grammar g14 g14-symbol - (:const :comma :colon :lcurly :rcurly :lbracket :rbracket) - S - ((S ((E) $1)) - (E ((const) $1) - ((lcurly OL rcurly) $1) - ((lbracket AL rbracket) $1)) - (C ((comma) $1)) - (A ((const colon E) $1)) - (OL (() $1) - ((ON) $1)) - (ON ((A) $1) - ((ON C A) $1)) - (AL (() $1) - ((AN) $1)) - (AN ((E) $1) - ((AN C E) $1)))) - - diff --git a/doc/examples/lawrence/toy-inputs.in b/doc/examples/lawrence/toy-inputs.in deleted file mode 100644 index b266a9d..0000000 --- a/doc/examples/lawrence/toy-inputs.in +++ /dev/null @@ -1,75 +0,0 @@ -; Copyright (c) 2000-2008 by Michael Sperber and Peter Thiemann. See file COPYING. - -(define i08-1 (list (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol r) #f))) - -(define i08-2 (list (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol r) #f))) - -(define i08-3 (list (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol l) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol r) #f) - (cons (enum g08-symbol l) #f))) - -(define i10-1 (list (cons (enum g10-symbol l) #f) - (cons (enum g10-symbol n) 4) - (cons (enum g10-symbol +) #f) - (cons (enum g10-symbol n) 17) - (cons (enum g10-symbol r) #f) - (cons (enum g10-symbol *) #f) - (cons (enum g10-symbol n) 7))) - -(define i10-2 (list (cons (enum g10-symbol l) #f) - (cons (enum g10-symbol n) 4) - (cons (enum g10-symbol +) #f) - (cons (enum g10-symbol n) 15) - (cons (enum g10-symbol n) 17) - (cons (enum g10-symbol r) #f) - (cons (enum g10-symbol *) #f) - (cons (enum g10-symbol n) 7))) - -(define i10-3 (list (cons (enum g10-symbol l) #f) - (cons (enum g10-symbol n) 4) - (cons (enum g10-symbol +) #f) - (cons (enum g10-symbol n) 17) - (cons (enum g10-symbol *) #f) - (cons (enum g10-symbol n) 7))) - -(define i10e-1 (list (cons (enum g10-error-symbol l) #f) - (cons (enum g10-error-symbol n) 4) - (cons (enum g10-error-symbol +) #f) - (cons (enum g10-error-symbol n) 17) - (cons (enum g10-error-symbol r) #f) - (cons (enum g10-error-symbol *) #f) - (cons (enum g10-error-symbol n) 7))) - -(define i10e-2 (list (cons (enum g10-error-symbol l) #f) - (cons (enum g10-error-symbol n) 4) - (cons (enum g10-error-symbol +) #f) - (cons (enum g10-error-symbol n) 15) - (cons (enum g10-error-symbol n) 17) - (cons (enum g10-error-symbol r) #f) - (cons (enum g10-error-symbol *) #f) - (cons (enum g10-error-symbol n) 7))) - -(define i10e-3 (list (cons (enum g10-error-symbol l) #f) - (cons (enum g10-error-symbol n) 4) - (cons (enum g10-error-symbol +) #f) - (cons (enum g10-error-symbol n) 17) - (cons (enum g10-error-symbol *) #f) - (cons (enum g10-error-symbol n) 7))) - -(define i14-1 (list (cons (enum g14-symbol lbracket) #f) - (cons (enum g14-symbol const) #f) - (cons (enum g14-symbol rbracket) #f))) diff --git a/project.clj b/project.clj index 886906a..9d83cda 100644 --- a/project.clj +++ b/project.clj @@ -1,11 +1,11 @@ -(defproject de.active-group/lawrence-parse-gen "0.12.0-SNAPSHOT" +(defproject de.active-group/lawrence "0.12.0-SNAPSHOT" :description "Lawrence: LR parser generator" :url "https://github.com/active-group/lawrence" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.10.1"] [de.active-group/active-clojure "0.42.2"] - [de.active-group/ephemerol-brain-scan "0.6.0-SNAPSHOT"]] + [de.active-group/ephemerol "0.6.0-SNAPSHOT"]] :profiles {:dev {:dependencies [[org.clojure/tools.trace "0.7.9"]]}} ) diff --git a/test/active/lawrence/functional_test.clj b/test/active/lawrence/functional_test.clj index c81d785..1b48dd9 100644 --- a/test/active/lawrence/functional_test.clj +++ b/test/active/lawrence/functional_test.clj @@ -11,65 +11,62 @@ (def lang-scan (scanner-spec ((+ char-set:digit) (fn [lexeme position input input-position] - ( (make-scan-result - [(Integer/parseInt lexeme) :decimal-symbol] + (make-scan-result + [:decimal-symbol (Integer/parseInt lexeme)] input input-position))) (char-set:whitespace (fn [lexeme position input input-position] - (make-scan-result [lexeme :whitespace] + (make-scan-result [:whitespace] input input-position))) ("*" (fn [lexeme position input input-position] - (make-scan-result [lexeme :mul] + (make-scan-result [:mul] input input-position))) ("/" (fn [lexeme position input input-position] - (make-scan-result [lexeme :div] + (make-scan-result [:div] input input-position))) ("-" (fn [lexeme position input input-position] - (make-scan-result [lexeme :minus] + (make-scan-result [:minus] input input-position))) ("+" (fn [lexeme position input input-position] - (make-scan-result () [lexeme :plus] + (make-scan-result [:plus] input input-position))) ("**" (fn [lexeme position input input-position] - (make-scan-result [lexeme :power] + (make-scan-result [:power] input input-position))) ("(" (fn [lexeme position input input-position] - (make-scan-result [lexeme :lparen] + (make-scan-result [:lparen] input input-position))) (")" (fn [lexeme position input input-position] - (make-scan-result [lexeme :rparen] + (make-scan-result [:rparen] input input-position))) - ("^" - (fn [lexeme position input input-position] - (make-scan-result [lexeme :not] - input input-position))))) -(def lang-grammar (gr/define-grammar + )) +(gr/define-grammar calculator - (list :plus :minus :mul :div :lparen :rparen + (:plus :minus :mul :div :lparen :rparen :not :decimal-symbol :power :whitespace) expression - ((expression ((expression term) $1 $2) + ((expression ((expression) $1) + ((:$error) 0) ((term :plus expression) (+ $1 $3)) - ((term :power expression) (+ $1 $3)) ((term :minus expression) (- $1 $3))) (term ((product) $1) - ((term :mul term) (* $1 $3)) + ((product :mul term) (* $1 $3)) ((product :div term) (/ $1 $3))) - (product ((:not) $1) - ((:decimal-symbol) $1) + (product ((:decimal-symbol) $1) ((:lparen - expression :rparen) $2)) + expression :rparen) $2) + ((:lparen :$error :rparen) 0)) - ))) + )) (execute-direct 'active.lawrence.functional-test lang-scan calculator - "(9 * 5)" method-slr) + "(9 * 5)" method-lr) ;;(parse calculator :lr input) diff --git a/test/active/lawrence/generate_test.clj b/test/active/lawrence/generate_test.clj index 2071176..7a20c74 100644 --- a/test/active/lawrence/generate_test.clj +++ b/test/active/lawrence/generate_test.clj @@ -1,13 +1,14 @@ (ns active.lawrence.generate-test - (:require [active.lawrence.process-test :refer :all] - [active.lawrence.lr :as lr])) + (:require [active.lawrence.lr :as lr] + [active.lawrence.process-test :refer :all] + [clojure.test :refer :all])) (defn generate [grammar name method] (lr/write-ds-parse-ns grammar 1 method - (symbol (str "active.lawrence.generate-test." name "-parser")) + (symbol (str "active.lawrence." name "-parser")) '([active.lawrence.parser-runtime :refer :all]) - (str "./test/active/lawrence/" name "_parser.clj"))) + (str "./" name "_parser.clj"))) -(generate toys-are-us "calc-it" :slr) \ No newline at end of file +(generate toys-are-us "calc_it" :slr) \ No newline at end of file diff --git a/test/active/lawrence/process_test.clj b/test/active/lawrence/process_test.clj index 1d0a409..5e0967f 100644 --- a/test/active/lawrence/process_test.clj +++ b/test/active/lawrence/process_test.clj @@ -11,40 +11,37 @@ ((+ char-set:digit) (fn [lexeme position input input-position] (make-scan-result - [:decimal-symbol (Integer/parseInt lexeme) ] + [:n (Integer/parseInt lexeme) ] input input-position))) (char-set:whitespace (fn [lexeme position input input-position] - (make-scan-result [:whitespace nil] + (make-scan-result [:ws] input input-position))) ("+" (fn [lexeme position input input-position] - (make-scan-result [:+ nil] + (make-scan-result [:+] input input-position))) ("-" (fn [lexeme position input input-position] - (make-scan-result [:- nil] + (make-scan-result [:-] input input-position))) ("*" (fn [lexeme position input input-position] - (make-scan-result [:* nil] + (make-scan-result [:*] input input-position))) ("/" (fn [lexeme position input input-position] - (make-scan-result [:/ nil] + (make-scan-result [:/] input input-position))) ("(" (fn [lexeme position input input-position] - (make-scan-result [:l nil] + (make-scan-result [:l] input input-position))) (")" (fn [lexeme position input input-position] - (make-scan-result [:r nil] - input input-position))) - ("not" - (fn [lexeme position input input-position] - (make-scan-result [:n nil] + (make-scan-result [:r] input input-position))) + )) (gr/define-grammar toys-are-us @@ -61,7 +58,7 @@ ((:l E :r) $2) ((:l :$error :r) 0)))) (gr/define-grammar toys-are-us-ext - (:+ :- :* :/ :l :r :n :decimal-symbol) + (:+ :- :* :/ :l :r :n :ws) E ((E ((T) $1) ((:$error) 0) @@ -75,11 +72,11 @@ ((:l :$error :r) 0)))) (deftest use-parse - (let [expr (list [:l] [:+] [:r])] + (let [expr (list [:l] [:n 5] [:+] [:n 9] [:r])] (println expr) -(parse-with-mpair toys-are-us :lr expr))) +(parse toys-are-us :lr expr))) (deftest process-rest (execute-direct 'active.lawrence.process-test toys-scan toys-are-us-ext - "(9*5)" method-lr)) + "(9*5+10(7/8))" method-lr)) diff --git a/test/active/lawrence/util/parse_lex_util.clj b/test/active/lawrence/util/parse_lex_util.clj index 5e41769..4c41a72 100644 --- a/test/active/lawrence/util/parse_lex_util.clj +++ b/test/active/lawrence/util/parse_lex_util.clj @@ -12,18 +12,8 @@ (map (fn [[t av]] ;;(rt/make-pair (gr/grammar-name->symbol t g) ;; av - (gr/grammar-name->symbol t g) - ) - vs)) - -(defn input-with-mpair - "Convert list of [token attribute-value] vectors to input." - [g vs] - (map (fn [[t av]] - (rt/make-pair (gr/grammar-name->symbol t g) - av - - )) + (rt/make-pair (gr/grammar-name->symbol t g) + av)) vs)) @@ -41,11 +31,7 @@ (println cooked-input) (direct/parse g 1 m cooked-input))) -(defn parse-with-mpair - [g m vs] - (let [cooked-input (input-with-mpair g vs)] - (println cooked-input) - (direct/parse g 1 m cooked-input))) + (defn def-complete-scan [sym-name-space this-scanner-spec input] @@ -71,9 +57,9 @@ yacc-result input method] - (let [output (def-complete-scan sym-name-space + (let [output (apply list (def-complete-scan sym-name-space this-scanner-spec - input)] + input))] From e685f90b3c13453cc4dc48fe1c70a8d40c7b2fcb Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Tue, 18 Jun 2024 22:40:54 +0200 Subject: [PATCH 06/23] definition of more tests and added some documentation which is up to now not complete. --- doc/REFERENCE.md | 122 +++++++++---------- test/active/lawrence/functional_test.clj | 24 +++- test/active/lawrence/process_test.clj | 18 ++- test/active/lawrence/util/parse_lex_util.clj | 11 +- 4 files changed, 95 insertions(+), 80 deletions(-) diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index ba9ebf9..fa1a40f 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -1,85 +1,52 @@ ## The parser and his functionality - - Remark if you like further explanation look at + - Remark if you like further explanation about left-to-right (shift - reduce parsers) look at the documentation of Essence: [S48 Essence LR Parrser Generator Documentation](https://www.s48.org/essence/doc/html/essence.html) - - - in that document there is also an general explanation about the way LR parser generators work. -- ### Parser and history -The parser is a kind of implementation of an -LR parser generator derived by idea from the -essence parser generator written for Scheme48. +Lawrence is a implementation of an +LR / SLR parser generator derived from the +Essence parser generator written in Scheme-48. ### Definition of a context free grammer -define-grammar in essence - -```scheme -(define-grammar calc calculator -(+ - * / ** lparen rparen DIVISION - PRODUCT SUBTRACT ADD POWER NEG) -expression -((expression ((NUMBER) $1) - ((expression expressionn ADD) - (+ $1 $2)) - ((expression expression SUBTRACT) - (- $1 $2)) - ((expression expreession PRODUCT) - (* $1 $2)) - ((expression expreession DIVISION) - (/ $1 $2)) - ((expression expression POWER) - (** $1 $2)) - ((expression NEG) - (- $1)) - ((lparen exp rparen) $2) - ))) -``` the same grammar in lawrence ```scheme -(define-grammar calculator - (:+ :- :* :/ :** :lparent :rparent :DIVISION - :PRODUCT :SUBTRACT :ADD :POWER :NEG) +(define-grammar + calculator + (:plus :minus :mul :div :lparen :rparen + :not :decimal-symbol :power :whitespace) expression - ((expression ((NUMBER) $1) - ((expression expressionn ADD) - (:+ $1 $2)) - ((expression expression SUBTRACT) - (:- $1 $2)) - ((expression expreession PRODUCT) - (:* $1 $2)) - ((expression expreession DIVISION) - (:/ $1 $2)) - ((expression expression POWER) - (:** $1 $2)) - ((expression NEG) - (:- $1)) - ((:lparen exp :rparen) $2) - ))) -``` + ((expression ((term) $1) + ((:$error) 0) + ((term :plus expression) (+ $1 $3)) + ((term :minus expression) (- $1 $3))) + (term ((product) $1) + ((product :mul term) (* $1 $3)) + ((product :div term) (/ $1 $3))) + (product ((:decimal-symbol) $1) + ((:lparen + expression :rparen) $2) + ((:lparen :$error :rparen) 0)) -as you see in the examples the one -definition is very similar -to the other. + )) +``` ### The explanation of the grammars above The expressions: -```scheme -(+ - * / **) -``` -Essence (S48) + +- define terminals ```scheme (:+ :- :* :/ :**) ``` -Lawrence (Clojure) -define terminals + - The 'expression' in the line below the terminals -is the start symbol. +is the start symbol. Thjis symbol is needed by the generator to determine the start of the grammar - After that the rules for parsing follow: #### Something about placeholders (variables) @@ -87,11 +54,42 @@ is the start symbol. - Example: Lawrence (example above but as infix) ```scheme - ((expression ADD expression) - (:+ $1 $3)) ;; here a addition is defined (infix) code: 5 + 3 - so the first and the third - ;; placements defines variables -> $1 $3 + ((term :plus expression) (+ $1 $3)) + ``` +here a addition is defined (infix) code: 5 + 3 - so the first and the third placements defines variables -> $1 $3 +#### The structure of a rule + +```scheme +1. ((expression ((term) $1) +2. ((:$error) 0).....)) +``` +- 1: here the **_rule_** for building a **expression** out of a given **term** which is defined later +- 2: here the **_rule_** what happens in case of a parser error is defined the **_rule_** tells us that we simply go on in case of a error + + + ```scheme + 3. ((term :plus expression) (+ $1 $3)) ``` -#### The structure of a rule +- 3: and now after we defined a **expression** by a term we define that a **term** and a **terminal** +```scheme + (term ((product) $1)... ) +``` + +- 4: with this **_rule_** we define a **term** in final as a result of the definition of **product** +```scheme + (product ((:decimal-symbol) $1)...) +``` + +- 5: what we need now is that we define the **product** by using the smallest unit +(in our case the **number**) to be sure that +any rule we defined ends in a defined **_terminal/ token_**. ### Some code examples how to call lawrence and test it direct or generate a specialized parser +[Code to call lawrence parse](../test/active/lawrence/util/parse_lex_util.clj) + +#### **Remark :** +The definition of the terminals for this example is done in a scanner specification +written with macros from ephemerol. See the `**_de.active-group/ephemerol_**` project +on GitHub: [**_Ephemerol_**](https://github.com/active-group/ephemerol) + diff --git a/test/active/lawrence/functional_test.clj b/test/active/lawrence/functional_test.clj index 1b48dd9..c4330e4 100644 --- a/test/active/lawrence/functional_test.clj +++ b/test/active/lawrence/functional_test.clj @@ -50,9 +50,9 @@ (gr/define-grammar calculator (:plus :minus :mul :div :lparen :rparen - :not :decimal-symbol :power :whitespace) + :not :decimal-symbol) expression - ((expression ((expression) $1) + ((expression ((term) $1) ((:$error) 0) ((term :plus expression) (+ $1 $3)) ((term :minus expression) (- $1 $3))) @@ -65,8 +65,20 @@ ((:lparen :$error :rparen) 0)) )) -(execute-direct 'active.lawrence.functional-test - lang-scan calculator - "(9 * 5)" method-lr) -;;(parse calculator :lr input) + +(defn should-accept-string-data + [pkg-sym scan-spec grammar data res] + (is (= res (execute-direct pkg-sym + scan-spec grammar + data :lr))) + (is (= res (execute-direct pkg-sym + scan-spec grammar + data :slr)))) +(deftest do-direct + (should-accept-string-data 'active.lawrence.functional-test + lang-scan calculator + "(9*5)" 45) + +) +(run-tests 'active.lawrence.functional-test) diff --git a/test/active/lawrence/process_test.clj b/test/active/lawrence/process_test.clj index 5e0967f..5e37eae 100644 --- a/test/active/lawrence/process_test.clj +++ b/test/active/lawrence/process_test.clj @@ -70,13 +70,25 @@ (P ((:n) $1) ((:l E :r) $2) ((:l :$error :r) 0)))) +(defn should-accept-list-data + [g vs res] + (is (= res (parse g :lr vs))) + (is (= res (parse g :slr vs)))) +(defn should-accept-string-data + [pkg-sym scan-spec grammar data res] + (is (= res (execute-direct pkg-sym + scan-spec grammar + data :lr))) + (is (= res (execute-direct pkg-sym + scan-spec grammar + data :slr)))) (deftest use-parse (let [expr (list [:l] [:n 5] [:+] [:n 9] [:r])] (println expr) -(parse toys-are-us :lr expr))) +(should-accept-list-data toys-are-us expr 14))) (deftest process-rest - (execute-direct 'active.lawrence.process-test + (should-accept-string-data 'active.lawrence.process-test toys-scan toys-are-us-ext - "(9*5+10(7/8))" method-lr)) + "(9*5+10+(3-1))" 57)) diff --git a/test/active/lawrence/util/parse_lex_util.clj b/test/active/lawrence/util/parse_lex_util.clj index 4c41a72..e58e504 100644 --- a/test/active/lawrence/util/parse_lex_util.clj +++ b/test/active/lawrence/util/parse_lex_util.clj @@ -10,8 +10,6 @@ "Convert list of [token attribute-value] vectors to input." [g vs] (map (fn [[t av]] - ;;(rt/make-pair (gr/grammar-name->symbol t g) - ;; av (rt/make-pair (gr/grammar-name->symbol t g) av)) vs)) @@ -22,8 +20,6 @@ (binding [*ns* (find-ns sym-name-space)] (eval (scanner->expression scanner)))) -(def method-lr :lr) -(def method-slr :slr) (defn parse [g m vs] @@ -46,10 +42,7 @@ (scan-to-list scan-one (string->list input) - (make-position 1 0)) - ] - (println "Scan Result output: ") - (println (first scan-result)) + (make-position 1 0))] (first scan-result)) ) @@ -63,7 +56,7 @@ - (println "Scan Result: ") + (println "Scan Result output: ") (println output) (parse yacc-result method output ;;(first scan-result) )) From c107dc3e2823a592f364e88b0e5e964a4924f0aa Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 08:55:37 +0200 Subject: [PATCH 07/23] corrected things for pull request --- src/active/lawrence/grammar.clj | 30 ++++++++++-------------- test/active/lawrence/direct_lr_test.clj | 1 - test/active/lawrence/functional_test.clj | 1 - test/active/lawrence/grammar_test.clj | 14 +++-------- test/active/lawrence/test.clj | 4 ---- 5 files changed, 16 insertions(+), 34 deletions(-) delete mode 100644 test/active/lawrence/test.clj diff --git a/src/active/lawrence/grammar.clj b/src/active/lawrence/grammar.clj index a84e527..1d99d88 100644 --- a/src/active/lawrence/grammar.clj +++ b/src/active/lawrence/grammar.clj @@ -12,7 +12,7 @@ ; - the nonterminals come before the terminals ; - the start production is first -(define-record-type grammer +(define-record-type Grammar (really-make-grammar name nonterminals terminals @@ -61,17 +61,15 @@ number-of-symbols (+ number-of-terminals number-of-nonterminals)] (really-make-grammar name - nonterminals - terminals - number-of-terminals - number-of-symbols - error - start - productions-by-lhs - symbol->name-procedure - name->symbol-procedure - terminal-attribution - (atom {})))) + nonterminals terminals + number-of-terminals + number-of-symbols + error start + productions-by-lhs + symbol->name-procedure + name->symbol-procedure + terminal-attribution + (atom {})))) (defn grammar-fetch-property [grammar name proc] @@ -107,10 +105,8 @@ (- lhs (grammar-nonterminal-offset grammar)))) (defn grammar-start-production - [in-grammar] - ;;(println (grammar-start grammar)) - (println in-grammar) - (first (grammar-productions-with-lhs (grammar-start in-grammar) in-grammar))) + [grammar] + (first (grammar-productions-with-lhs (grammar-start grammar) grammar))) (defn grammar-for-each-production [proc grammar] @@ -123,7 +119,7 @@ (proc prod)) (recur (+ 1 i)))))) -(define-record-type production +(define-record-type Production (make-production readable lhs rhs attribution) production? [readable production-readable diff --git a/test/active/lawrence/direct_lr_test.clj b/test/active/lawrence/direct_lr_test.clj index 4d53cb2..3dba170 100644 --- a/test/active/lawrence/direct_lr_test.clj +++ b/test/active/lawrence/direct_lr_test.clj @@ -53,4 +53,3 @@ ;;(should-accept goptional (list [:bar]) :absent) (should-accept goptional (list [:bar] [:foo]) :present)) -(run-all-tests) \ No newline at end of file diff --git a/test/active/lawrence/functional_test.clj b/test/active/lawrence/functional_test.clj index c4330e4..b92461a 100644 --- a/test/active/lawrence/functional_test.clj +++ b/test/active/lawrence/functional_test.clj @@ -80,5 +80,4 @@ "(9*5)" 45) ) -(run-tests 'active.lawrence.functional-test) diff --git a/test/active/lawrence/grammar_test.clj b/test/active/lawrence/grammar_test.clj index d3a7724..571d304 100644 --- a/test/active/lawrence/grammar_test.clj +++ b/test/active/lawrence/grammar_test.clj @@ -1,17 +1,11 @@ (ns active.lawrence.grammar-test - (:require [active.lawrence.grammar :refer :all] - [clojure.test :refer :all] - )) + (:require [active.lawrence.grammar :refer :all])) -(deftest grammar-g00 - (testing "little grammar test" (define-grammar g00 (:l) S ((S ((:l) $1)))) -)) -(deftest grammar-g00 - (testing "little grammar test" + (define-grammar g08 (:l :r) S @@ -20,8 +14,6 @@ (T ((:l S :r) $1) ((:l :r) $1)))) - )) - ; Constant arithmetic expressions (define-grammar g10 @@ -93,4 +85,4 @@ ((S ((:bar O) $2)) (O ((:foo) :present) (() :absent)))) -(run-all-tests) + diff --git a/test/active/lawrence/test.clj b/test/active/lawrence/test.clj deleted file mode 100644 index 99a2939..0000000 --- a/test/active/lawrence/test.clj +++ /dev/null @@ -1,4 +0,0 @@ -(ns active.lawrence.test - (:require [clojure.test :refer :all])) - -(run-all-tests) From ff4d5cb661fa51dbc9ad597d7d67913ba8d404e9 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 09:00:49 +0200 Subject: [PATCH 08/23] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2eae690..22bae4d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ pom.xml.asc /.nrepl-port /.idea *.iml +test/active/lawrence/calc_it_parser.clj From 3d00adc678977b301d3d0ce12523728bd069e192 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 09:01:23 +0200 Subject: [PATCH 09/23] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 58ba788dc668bcbf31febb2548c9d85ed185722b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z-O8O({YS3Oz1(E!f&pEM7vaFJMFuDm5`hgE3p0)Er77XMG``#OHBl zcLNr47O^w1`_1oe_JiyXV~o4Yu+Nyy7_*=ua#Sh=-Ibx5Nk-&2Mmi5-8G!W>%uVdC z1Acp*g-o)CApidTag=7g-Y2is8#}vAt7)~ZJMT&6Ugl@Z)b$rPXkAJf2c_-@SJ5n= z+WTiR$^0mpEmT1i&LHLXI!Z#ByKEyt+l0AbZyn|v^^Xe^eT z!~iky&lup1i8pa!QRZy@u{=C$1+;r;D418E0s{KRB>)WEM>;B~;{tWaa|{+5aTN5c QazMHWC_< Date: Wed, 19 Jun 2024 09:28:03 +0200 Subject: [PATCH 10/23] corrected code examples to point on Marcus Crestanis code --- doc/REFERENCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index fa1a40f..c7ca3d8 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -86,7 +86,7 @@ here a addition is defined (infix) code: 5 + 3 - so the first and the third plac any rule we defined ends in a defined **_terminal/ token_**. ### Some code examples how to call lawrence and test it direct or generate a specialized parser -[Code to call lawrence parse](../test/active/lawrence/util/parse_lex_util.clj) +[Code to call lawrence parse](https://github.com/cresh/parser/tree/main) #### **Remark :** The definition of the terminals for this example is done in a scanner specification From 1b9d1c1b3b29551b0387c1f715ea816e5e2dc4f0 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 09:37:05 +0200 Subject: [PATCH 11/23] reformatted code a bit --- test/active/lawrence/util/parse_lex_util.clj | 53 +++++++------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/test/active/lawrence/util/parse_lex_util.clj b/test/active/lawrence/util/parse_lex_util.clj index e58e504..3cc7650 100644 --- a/test/active/lawrence/util/parse_lex_util.clj +++ b/test/active/lawrence/util/parse_lex_util.clj @@ -1,63 +1,46 @@ (ns active.lawrence.util.parse-lex-util (:require [active.ephemerol.char-set :refer :all] - [active.lawrence.grammar :as gr] - [active.lawrence.runtime :as rt] + [active.ephemerol.regexp :refer :all] + [active.ephemerol.scanner :refer :all] + [active.ephemerol.scanner-run :refer :all] [active.lawrence.direct-lr :as direct] - [active.ephemerol.regexp :refer :all] - [active.ephemerol.scanner :refer :all] - [active.ephemerol.scanner-run :refer :all])) + [active.lawrence.grammar :as gr] + [active.lawrence.runtime :as rt])) + (defn input "Convert list of [token attribute-value] vectors to input." [g vs] (map (fn [[t av]] - (rt/make-pair (gr/grammar-name->symbol t g) - av)) + (rt/make-pair (gr/grammar-name->symbol t g) + av)) vs)) - (defn eval-scanner [scanner sym-name-space] (binding [*ns* (find-ns sym-name-space)] (eval (scanner->expression scanner)))) - - (defn parse [g m vs] (let [cooked-input (input g vs)] (println cooked-input) - (direct/parse g 1 m cooked-input))) - - + (direct/parse g 1 m cooked-input))) (defn def-complete-scan [sym-name-space this-scanner-spec input] - (let [scanner (compute-scanner this-scanner-spec) scan-one (make-scan-one (eval-scanner scanner sym-name-space)) - - - scan-result - - (scan-to-list - scan-one - (string->list input) - (make-position 1 0))] - (first scan-result)) ) + scan-result (scan-to-list + scan-one + (string->list input) + (make-position 1 0))] + (first scan-result))) (defn execute-direct [sym-name-space this-scanner-spec yacc-result input method] - - (let [output (apply list (def-complete-scan sym-name-space - this-scanner-spec - input))] - - - - (println "Scan Result output: ") - (println output) - (parse yacc-result method output ;;(first scan-result) - )) - ) + this-scanner-spec + input))] + (parse yacc-result method output ;;(first scan-result) + ))) From 14653de6e2efaee333dcaa75eeb279055b7afae5 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 09:43:14 +0200 Subject: [PATCH 12/23] updated .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 22bae4d..01c20ae 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ pom.xml.asc /.nrepl-port /.idea *.iml -test/active/lawrence/calc_it_parser.clj + From fb91e28ac9de182eada58f8504796a053b5bdcc9 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 15:19:57 +0200 Subject: [PATCH 13/23] deleted file accidentally moved to this project --- COPYING | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 COPYING diff --git a/COPYING b/COPYING deleted file mode 100644 index 98443b7..0000000 --- a/COPYING +++ /dev/null @@ -1,48 +0,0 @@ -Copyright (c) 1999-2008 Michael Sperber and Peter Thiemann. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. All advertising materials mentioning features or use of this software - must display the following acknowledgement: -4. The names of the authors of this software may not be used to - endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. - -Distributing Autoconf Output -**************************** - -[excerpt from autoconf documentation] - - The configuration scripts that Autoconf produces are covered by the -GNU General Public License. This is because they consist almost -entirely of parts of Autoconf itself, rearranged somewhat, and Autoconf -is distributed under the terms of the GPL. As applied to Autoconf, the -GPL just means that you need to distribute `configure.in' along with -`configure'. - - Programs that use Autoconf scripts to configure themselves do not -automatically come under the GPL. Distributing an Autoconf -configuration script as part of a program is considered to be *mere -aggregation* of that work with the Autoconf script. Such programs are -not derivative works based on Autoconf; only their configuration scripts -are. We still encourage software authors to distribute their work under -terms like those of the GPL, but doing so is not required to use -Autoconf. From 5a36d84b9f79fcca42c28621b27ec0f2865d68d8 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 15:27:12 +0200 Subject: [PATCH 14/23] deleted file accidentally moved to this project --- test/active/lawrence/util/parse_lex_util.clj | 21 +++++++------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/test/active/lawrence/util/parse_lex_util.clj b/test/active/lawrence/util/parse_lex_util.clj index 3cc7650..61e2f64 100644 --- a/test/active/lawrence/util/parse_lex_util.clj +++ b/test/active/lawrence/util/parse_lex_util.clj @@ -1,7 +1,5 @@ (ns active.lawrence.util.parse-lex-util - (:require [active.ephemerol.char-set :refer :all] - [active.ephemerol.regexp :refer :all] - [active.ephemerol.scanner :refer :all] + (:require [active.ephemerol.scanner :refer :all] [active.ephemerol.scanner-run :refer :all] [active.lawrence.direct-lr :as direct] [active.lawrence.grammar :as gr] @@ -19,28 +17,23 @@ [scanner sym-name-space] (binding [*ns* (find-ns sym-name-space)] (eval (scanner->expression scanner)))) + (defn parse [g m vs] - (let [cooked-input (input g vs)] - (println cooked-input) - (direct/parse g 1 m cooked-input))) + (direct/parse g 1 m (input g vs))) (defn def-complete-scan [sym-name-space this-scanner-spec input] (let [scanner (compute-scanner this-scanner-spec) - scan-one (make-scan-one (eval-scanner scanner - sym-name-space)) + scan-one (make-scan-one (eval-scanner scanner sym-name-space)) scan-result (scan-to-list scan-one (string->list input) (make-position 1 0))] (first scan-result))) - (defn execute-direct [sym-name-space this-scanner-spec yacc-result input method] - (let [output (apply list (def-complete-scan sym-name-space - this-scanner-spec - input))] - (parse yacc-result method output ;;(first scan-result) - ))) + (let [output (apply list + (def-complete-scan sym-name-space this-scanner-spec input))] + (parse yacc-result method output))) \ No newline at end of file From a36930ab10a8144d8a51ce6f63be372a9fed2ffe Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 15:30:19 +0200 Subject: [PATCH 15/23] removed directories --- doc/.DS_Store | Bin 6148 -> 0 bytes doc/examples/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 doc/.DS_Store delete mode 100644 doc/examples/.DS_Store diff --git a/doc/.DS_Store b/doc/.DS_Store deleted file mode 100644 index b079008cc1ee5cd97b6a39b66ab8b0a17cafc476..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z<-bZYe?!3Oz1(E!f&pEM7vbFJMFuDm5WNgK4%jtrbckXMG``#OHBl zcLSE@;7P>Jz~-BspWU4gvOkP5K9~n>#_EhQ0S%F(QXpt9bnVz+M6Sn}u$YA`^%v=+ zV4%Nf!nF%n^DFb%n0;HnA1fbxAO0kc(pjtZ$#+WS-Mxyah?=-}pVY#gd9!&s@TRxe zyHYClbKUc=qi`{*ADpXX=0!<3)d^7$Lde}slmu!qQ1c{6b*^h1qAIGRdSkil^xI9@ z>7A~ca@jv=HD$NgU9GC(@aXvLa`YUJ6ZK}uBX0ax^(Qg`j5i|eNJ$32w7p7n)%5}(JJ zBny`I;7P>JK=MuIC)xR6^8)~)HyyMA8UP@%5eiaP2$@&9N-mgCm^mUy;Q^vB8xL1Z z^cPL^?Gh3QAcGNn`~EP|A^JYTVG@rgt=6X~l`9*YRaupFdFMar%%234>9`k+ZfJC= zbrKeO5MISm)^BW|>U0vsX*4nk@gTyG+v_+T=&Yxw>0oSfed~}lS?f1;XS2?6yQw;d zNAsqd9Uruss(aX-&uemLZ~x??|D3#}`puFlkar_n4hwikWvQ-Lf0QOVeMDc8SHv?i z1Iz$3zznPp1MUov_4O&4D`f_lfgdtJ`-8$p=sCK)o%<5=YCLDxkk$Yx<8CYbXY=;dx z|IhK4S^3CcOyLnTzzqB|21Mn|KkH#p?rdEukIq_!?H(Hm#pR@+puTVkzya+eyT)n# bigb+g9Of2j7P6akM7{_ZLbziFeu05677$GH From 6059184b964917b4cf9263c9cf79303e4ed89ca9 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 15:30:41 +0200 Subject: [PATCH 16/23] code formatting and optimizing --- test/active/lawrence/calc_it_parser.clj | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/active/lawrence/calc_it_parser.clj diff --git a/test/active/lawrence/calc_it_parser.clj b/test/active/lawrence/calc_it_parser.clj new file mode 100644 index 0000000..68b2320 --- /dev/null +++ b/test/active/lawrence/calc_it_parser.clj @@ -0,0 +1,35 @@ +(ns active.lawrence.calc_it-parser (:require [active.lawrence.runtime :refer :all] [active.lawrence.parser-runtime :refer :all]) (:import [active.lawrence.runtime RetVal])) +(declare ds-parse-0 ds-parse-bar-0 ds-parse-5 ds-parse-bar-5 ds-parse-4 ds-parse-bar-4 ds-parse-3 ds-parse-bar-3 ds-parse-2 ds-parse-bar-2 ds-parse-1 ds-parse-bar-1 ds-parse-7 ds-parse-bar-7 ds-parse-6 ds-parse-bar-6 ds-parse-9 ds-parse-bar-9 ds-parse-8 ds-parse-bar-8 ds-parse-10 ds-parse-bar-10 ds-parse-11 ds-parse-bar-11 ds-parse-12 ds-parse-bar-12 ds-parse-13 ds-parse-bar-13 ds-parse-14 ds-parse-bar-14 ds-parse-15 ds-parse-bar-15) +(defn- ds-parse-0 [es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) (= 8 (.-lhs rv__2216__auto__)) (if (empty? (.-input rv__2216__auto__)) rv__2216__auto__ (parse-error "input beyond EOF" #{} (.-input rv__2216__auto__))) :else (ds-parse-bar-0 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) (= 8 (.-lhs rv__2216__auto__)) (if (empty? (.-input rv__2216__auto__)) rv__2216__auto__ (parse-error "input beyond EOF" #{} (.-input rv__2216__auto__))) :else (ds-parse-bar-0 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-0 [nt__2221__auto__ av__2219__auto__ es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-3 av__2219__auto__ es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) (= 8 (.-lhs rv__2220__auto__)) (if (empty? (.-input rv__2220__auto__)) rv__2220__auto__ (parse-error "input beyond EOF" #{7 5} (.-input rv__2220__auto__))) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) es__2214__auto__ (.-input rv__2220__auto__))))) +(defn- ds-parse-5 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 11 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) 6 (->RetVal 11 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 6 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 1 (let [^RetVal rv__2216__auto__ (ds-parse-6 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) 2 (let [^RetVal rv__2216__auto__ (ds-parse-7 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-5 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-4 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 10 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 6) (->RetVal 10 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 4 6 3 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 4 (let [^RetVal rv__2216__auto__ (ds-parse-8 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) 3 (let [^RetVal rv__2216__auto__ (ds-parse-9 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-4 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-3 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 8 1 (identity av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-3 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-2 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-2 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-2 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-2 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-10 av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 es__2214__auto__ (.-input rv__2220__auto__))))) +(defn- ds-parse-1 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 9 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 3 4 6) (->RetVal 9 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 4 6 3 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-1 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-7 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-7 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-7 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-7 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-11 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) +(defn- ds-parse-6 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-6 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-6 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-6 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-12 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) +(defn- ds-parse-9 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-9 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-9 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-9 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-13 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) +(defn- ds-parse-8 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-8 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-8 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-8 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-14 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) +(defn- ds-parse-10 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{6} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 6 (let [^RetVal rv__2216__auto__ (ds-parse-15 (pair-attribute-value p__2215__auto__) av-0 av-1 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) (reduce__2217__auto__)))))) +(defn- ds-parse-bar-10 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-11 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 53, :column 34} (- $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) 6 (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 53, :column 34} (- $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{6} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-11 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-12 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 52, :column 34} (+ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) 6 (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 52, :column 34} (+ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{6} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-12 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-13 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 55, :column 34} (* $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 6) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 55, :column 34} (* $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 6 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-13 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-14 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 56, :column 34} (/ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 6) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 56, :column 34} (/ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 6 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-14 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn- ds-parse-15 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 9 3 ((fn [$1 $2 $3] $2) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 3 4 6) (->RetVal 9 3 ((fn [$1 $2 $3] $2) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 4 6 3 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) +(defn- ds-parse-bar-15 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) +(defn parse [input__2250__auto__] (let [^active.lawrence.runtime.RetVal retval__2251__auto__ (ds-parse-0 3 (seq input__2250__auto__))] (.-attribute-value retval__2251__auto__))) From 87c23d2f336025fdc67edb831ddbc8f99486895b Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Wed, 19 Jun 2024 15:34:59 +0200 Subject: [PATCH 17/23] deleted file --- test/active/lawrence/calc_it_parser.clj | 35 ------------------------- 1 file changed, 35 deletions(-) delete mode 100644 test/active/lawrence/calc_it_parser.clj diff --git a/test/active/lawrence/calc_it_parser.clj b/test/active/lawrence/calc_it_parser.clj deleted file mode 100644 index 68b2320..0000000 --- a/test/active/lawrence/calc_it_parser.clj +++ /dev/null @@ -1,35 +0,0 @@ -(ns active.lawrence.calc_it-parser (:require [active.lawrence.runtime :refer :all] [active.lawrence.parser-runtime :refer :all]) (:import [active.lawrence.runtime RetVal])) -(declare ds-parse-0 ds-parse-bar-0 ds-parse-5 ds-parse-bar-5 ds-parse-4 ds-parse-bar-4 ds-parse-3 ds-parse-bar-3 ds-parse-2 ds-parse-bar-2 ds-parse-1 ds-parse-bar-1 ds-parse-7 ds-parse-bar-7 ds-parse-6 ds-parse-bar-6 ds-parse-9 ds-parse-bar-9 ds-parse-8 ds-parse-bar-8 ds-parse-10 ds-parse-bar-10 ds-parse-11 ds-parse-bar-11 ds-parse-12 ds-parse-bar-12 ds-parse-13 ds-parse-bar-13 ds-parse-14 ds-parse-bar-14 ds-parse-15 ds-parse-bar-15) -(defn- ds-parse-0 [es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) (= 8 (.-lhs rv__2216__auto__)) (if (empty? (.-input rv__2216__auto__)) rv__2216__auto__ (parse-error "input beyond EOF" #{} (.-input rv__2216__auto__))) :else (ds-parse-bar-0 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) (= 8 (.-lhs rv__2216__auto__)) (if (empty? (.-input rv__2216__auto__)) rv__2216__auto__ (parse-error "input beyond EOF" #{} (.-input rv__2216__auto__))) :else (ds-parse-bar-0 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-0 [nt__2221__auto__ av__2219__auto__ es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-3 av__2219__auto__ es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) (= 8 (.-lhs rv__2220__auto__)) (if (empty? (.-input rv__2220__auto__)) rv__2220__auto__ (parse-error "input beyond EOF" #{7 5} (.-input rv__2220__auto__))) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) es__2214__auto__ (.-input rv__2220__auto__))))) -(defn- ds-parse-5 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 11 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) 6 (->RetVal 11 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 6 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 1 (let [^RetVal rv__2216__auto__ (ds-parse-6 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) 2 (let [^RetVal rv__2216__auto__ (ds-parse-7 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-5 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-4 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 10 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 6) (->RetVal 10 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 4 6 3 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 4 (let [^RetVal rv__2216__auto__ (ds-parse-8 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) 3 (let [^RetVal rv__2216__auto__ (ds-parse-9 (pair-attribute-value p__2215__auto__) av-0 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-4 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-3 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 8 1 (identity av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-3 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-2 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-2 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-2 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-2 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-10 av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 es__2214__auto__ (.-input rv__2220__auto__))))) -(defn- ds-parse-1 [av-0 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 9 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 3 4 6) (->RetVal 9 1 ((fn [$1] $1) av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 4 6 3 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-1 [nt__2221__auto__ av__2219__auto__ av-0 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-7 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-7 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-7 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-7 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-11 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) -(defn- ds-parse-6 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-6 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-6 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-6 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 11 (ds-parse-12 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-5 av__2219__auto__ es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) -(defn- ds-parse-9 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-9 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-9 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-9 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-13 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) -(defn- ds-parse-8 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{7 5} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 7 (let [^RetVal rv__2216__auto__ (ds-parse-1 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-8 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) 5 (let [^RetVal rv__2216__auto__ (ds-parse-2 (pair-attribute-value p__2215__auto__) es__2214__auto__ (rest in__2213__auto__))] (cond (> (.dot rv__2216__auto__) 1) (dec-dot rv__2216__auto__) :else (ds-parse-bar-8 (.lhs rv__2216__auto__) (.-attribute-value rv__2216__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2216__auto__)))) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-8 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__) 9 (ds-parse-4 av__2219__auto__ es__2214__auto__ in__2213__auto__) 10 (ds-parse-14 av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__))] (cond (> (.dot rv__2220__auto__) 1) (dec-dot rv__2220__auto__) :else (recur (.lhs rv__2220__auto__) (.-attribute-value rv__2220__auto__) av-0 av-1 es__2214__auto__ (.-input rv__2220__auto__))))) -(defn- ds-parse-10 [av-0 av-1 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (case (pair-token (first in__2213__auto__)) (parse-error "parse error" #{6} in__2213__auto__)))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ 6 (let [^RetVal rv__2216__auto__ (ds-parse-15 (pair-attribute-value p__2215__auto__) av-0 av-1 es__2214__auto__ (rest in__2213__auto__))] (dec-dot rv__2216__auto__)) (reduce__2217__auto__)))))) -(defn- ds-parse-bar-10 [nt__2221__auto__ av__2219__auto__ av-0 av-1 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-11 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 53, :column 34} (- $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) 6 (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 53, :column 34} (- $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{6} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-11 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-12 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 52, :column 34} (+ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) 6 (->RetVal 11 3 ((fn [$1 $2 $3] ^{:line 52, :column 34} (+ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{6} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-12 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-13 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 55, :column 34} (* $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 6) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 55, :column 34} (* $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 6 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-13 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-14 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 56, :column 34} (/ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 6) (->RetVal 10 3 ((fn [$1 $2 $3] ^{:line 56, :column 34} (/ $1 $3)) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 6 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-14 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn- ds-parse-15 [av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [reduce__2217__auto__ (fn [] (if (empty? in__2213__auto__) (->RetVal 9 3 ((fn [$1 $2 $3] $2) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (case (pair-token (first in__2213__auto__)) (1 2 3 4 6) (->RetVal 9 3 ((fn [$1 $2 $3] $2) av-2 av-1 av-0) es__2214__auto__ nil in__2213__auto__) (parse-error "parse error" #{1 4 6 3 2} in__2213__auto__))))] (if (empty? in__2213__auto__) (reduce__2217__auto__) (let [p__2215__auto__ (first in__2213__auto__) symbol__2218__auto__ (pair-token p__2215__auto__)] (case symbol__2218__auto__ (reduce__2217__auto__)))))) -(defn- ds-parse-bar-15 [nt__2221__auto__ av__2219__auto__ av-0 av-1 av-2 es__2214__auto__ in__2213__auto__] (let [^RetVal rv__2220__auto__ (case (int nt__2221__auto__))] (dec-dot rv__2220__auto__))) -(defn parse [input__2250__auto__] (let [^active.lawrence.runtime.RetVal retval__2251__auto__ (ds-parse-0 3 (seq input__2250__auto__))] (.-attribute-value retval__2251__auto__))) From c6a2f0eb3a84428106ea0d1b6deee737bc9dfebc Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Thu, 20 Jun 2024 10:32:18 +0200 Subject: [PATCH 18/23] changed text and making further explanations --- doc/REFERENCE.md | 65 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index c7ca3d8..a914563 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -1,19 +1,36 @@ ## The parser and his functionality - - Remark if you like further explanation about left-to-right (shift - reduce parsers) look at -the documentation of Essence: - - [S48 Essence LR Parrser Generator Documentation](https://www.s48.org/essence/doc/html/essence.html) -- in that document there is also an general explanation about the way LR parser generators work. + +#### - for those who are interested in a better understanding of shift - reduce parser or are not familiar with it: + +Shift Reduce parser attempts for the construction of parse in a +similar manner as done in bottom-up parsing i.e. the parse tree is +constructed from leaves(bottom) to the root(up). +A more general form of the shift-reduce parser is the LR parser. + +##### This parser requires some data structures i.e. + +- _An input buffer for storing the input string._ +- _A stack for storing and accessing the production rules._ + +Out of an article of (geeks for geeks (Author not mentioned)) +[Shift Reduce - parser compiler](https://www.geeksforgeeks.org/shift-reduce-parser-compiler/) + +**REMARK:** here is the documentation of Essence where also a good explanation can be found: + [S48 Essence LR Parser Generator Documentation](https://www.s48.org/essence/doc/html/essence.html) + +- in that document also the specific documentation can be found and the way the Lawrence + parser generator work. +- ### Parser and history Lawrence is a implementation of an LR / SLR parser generator derived from the Essence parser generator written in Scheme-48. +Written by Peter Thieman, Mike Sperber ### Definition of a context free grammer - -the same grammar in lawrence +##### - Example of a grammar we use to explain the steps: ```scheme (define-grammar @@ -37,6 +54,7 @@ the same grammar in lawrence ``` ### The explanation of the grammars above + The expressions: - define terminals @@ -93,3 +111,36 @@ The definition of the terminals for this example is done in a scanner specificat written with macros from ephemerol. See the `**_de.active-group/ephemerol_**` project on GitHub: [**_Ephemerol_**](https://github.com/active-group/ephemerol) +#### Here some code explained: +This code is part of a project Marcus Crestani set up to simplify the call of ephemerol / lawrence in a way +that it is possible to call the parser directly or to generate a specialized parser in +the context of having a given scanner spec. . + +- Here a base macro creating a scanner with output matching to lawrence: +```scheme +(defmacro make-scan-result-for-lawrence + [?enum ?lexeme->attribute] ...) +``` + +- with this definition more specialized forms can be defined: + +1. definition for a keyword with no parameter + +```scheme +(defmacro keyword-result + [?enum] + `(make-scan-result-for-lawrence ...)) +``` + +2. definition for a keyword with one parameter (e.g. a number ) + +```scheme +defmacro number-result + [] + `(make-scan-result-for-lawrence :number ,@_) .... +``` + +A more detailed explanation by Marcus Crestani will be available later on +[Functional development BLOG](https://funktionale-programmierung.de) + + From 86e6096c1c7ded5ce6450414a97dcd2e4a4b0a12 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Thu, 20 Jun 2024 11:02:41 +0200 Subject: [PATCH 19/23] short addition --- doc/REFERENCE.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index a914563..5d4b0be 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -140,7 +140,33 @@ defmacro number-result `(make-scan-result-for-lawrence :number ,@_) .... ``` +Here is a simple scanner definition with tese simplifying macros: + +```scheme +;; scanner specification +(def scanner-specification + (scanner/scanner-spec + ;; skip whitespace + (char-set/char-set:whitespace + (fn [_lexeme _position input input-position] + (scan-one input input-position))) + + ;; keywords + ("+" (keyword-result :+)) + ("-" (keyword-result :-)) + ("*" (keyword-result :*)) + ("/" (keyword-result :/)) + ("(" (keyword-result :l)) + (")" (keyword-result :r)) + + ;; numbers + ((+ char-set/char-set:digit) (number-result)))) + +``` + A more detailed explanation by Marcus Crestani will be available later on [Functional development BLOG](https://funktionale-programmierung.de) +**_Will be continued_** ...... + From c59df3aa1dbfdd901d5b0d2657e406e320aa335b Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Thu, 20 Jun 2024 18:09:14 +0200 Subject: [PATCH 20/23] Update README.md a Little enhancement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index acab24a..3435df2 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ An LR parser generator for Clojure. ## Usage -For the specification and reference and more see REFERENCE.md +For the specification and reference and more see [In the Reference](./doc/REFERENCE.md) in the /doc directory of this project ## License From 63ebe6e87fc752b715f0310f96b82774585a9edb Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Thu, 20 Jun 2024 18:15:53 +0200 Subject: [PATCH 21/23] changed settings for codeblocks from ```scheme to ```clojure --- doc/REFERENCE.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index 5d4b0be..70a5f70 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -32,7 +32,7 @@ Written by Peter Thieman, Mike Sperber ##### - Example of a grammar we use to explain the steps: -```scheme +```clojure (define-grammar calculator (:plus :minus :mul :div :lparen :rparen @@ -58,7 +58,7 @@ Written by Peter Thieman, Mike Sperber The expressions: - define terminals -```scheme +```clojure (:+ :- :* :/ :**) ``` @@ -71,13 +71,13 @@ is the start symbol. Thjis symbol is needed by the generator to determine the st - The $(n) where (n) is a integer defines a variable the (n) there defines the placement of the variable inside a term - Example: Lawrence (example above but as infix) - ```scheme + ```clojure ((term :plus expression) (+ $1 $3)) ``` here a addition is defined (infix) code: 5 + 3 - so the first and the third placements defines variables -> $1 $3 #### The structure of a rule -```scheme +```clojure 1. ((expression ((term) $1) 2. ((:$error) 0).....)) ``` @@ -85,17 +85,17 @@ here a addition is defined (infix) code: 5 + 3 - so the first and the third plac - 2: here the **_rule_** what happens in case of a parser error is defined the **_rule_** tells us that we simply go on in case of a error - ```scheme + ```clojure 3. ((term :plus expression) (+ $1 $3)) ``` - 3: and now after we defined a **expression** by a term we define that a **term** and a **terminal** -```scheme +```clojure (term ((product) $1)... ) ``` - 4: with this **_rule_** we define a **term** in final as a result of the definition of **product** -```scheme +```clojure (product ((:decimal-symbol) $1)...) ``` @@ -117,7 +117,7 @@ that it is possible to call the parser directly or to generate a specialized par the context of having a given scanner spec. . - Here a base macro creating a scanner with output matching to lawrence: -```scheme +```clojure (defmacro make-scan-result-for-lawrence [?enum ?lexeme->attribute] ...) ``` @@ -126,7 +126,7 @@ the context of having a given scanner spec. . 1. definition for a keyword with no parameter -```scheme +```clojure (defmacro keyword-result [?enum] `(make-scan-result-for-lawrence ...)) @@ -134,7 +134,7 @@ the context of having a given scanner spec. . 2. definition for a keyword with one parameter (e.g. a number ) -```scheme +```clojure defmacro number-result [] `(make-scan-result-for-lawrence :number ,@_) .... @@ -142,7 +142,7 @@ defmacro number-result Here is a simple scanner definition with tese simplifying macros: -```scheme +```clojure ;; scanner specification (def scanner-specification (scanner/scanner-spec From b471760c61fa2aacebefe9821742e99f369d9591 Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Thu, 20 Jun 2024 23:51:14 +0200 Subject: [PATCH 22/23] Update LICENSE Eclipse Public 2.0 --- LICENSE | 405 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 234 insertions(+), 171 deletions(-) diff --git a/LICENSE b/LICENSE index 7689f30..e48e096 100644 --- a/LICENSE +++ b/LICENSE @@ -1,214 +1,277 @@ -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC -LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM -CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. +Eclipse Public License - v 2.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE + PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION + OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 1. DEFINITIONS "Contribution" means: -a) in the case of the initial Contributor, the initial code and -documentation distributed under this Agreement, and + a) in the case of the initial Contributor, the initial content + Distributed under this Agreement, and -b) in the case of each subsequent Contributor: + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + where such changes and/or additions to the Program originate from + and are Distributed by that particular Contributor. A Contribution + "originates" from a Contributor if it was added to the Program by + such Contributor itself or anyone acting on such Contributor's behalf. + Contributions do not include changes or additions to the Program that + are not Modified Works. -i) changes to the Program, and +"Contributor" means any person or entity that Distributes the Program. -ii) additions to the Program; +"Licensed Patents" mean patent claims licensable by a Contributor which +are necessarily infringed by the use or sale of its Contribution alone +or when combined with the Program. -where such changes and/or additions to the Program originate from and are -distributed by that particular Contributor. A Contribution 'originates' from -a Contributor if it was added to the Program by such Contributor itself or -anyone acting on such Contributor's behalf. Contributions do not include -additions to the Program which: (i) are separate modules of software -distributed in conjunction with the Program under their own license -agreement, and (ii) are not derivative works of the Program. +"Program" means the Contributions Distributed in accordance with this +Agreement. -"Contributor" means any person or entity that distributes the Program. +"Recipient" means anyone who receives the Program under this Agreement +or any Secondary License (as applicable), including Contributors. -"Licensed Patents" mean patent claims licensable by a Contributor which are -necessarily infringed by the use or sale of its Contribution alone or when -combined with the Program. +"Derivative Works" shall mean any work, whether in Source Code or other +form, that is based on (or derived from) the Program and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. -"Program" means the Contributions distributed in accordance with this -Agreement. +"Modified Works" shall mean any work in Source Code or other form that +results from an addition to, deletion from, or modification of the +contents of the Program, including, for purposes of clarity any new file +in Source Code form that contains any contents of the Program. Modified +Works shall not include works that contain only declarations, +interfaces, types, classes, structures, or files of the Program solely +in each case in order to link to, bind by name, or subclass the Program +or Modified Works thereof. -"Recipient" means anyone who receives the Program under this Agreement, -including all Contributors. +"Distribute" means the acts of a) distributing or b) making available +in any manner that enables the transfer of a copy. -2. GRANT OF RIGHTS +"Source Code" means the form of a Program preferred for making +modifications, including but not limited to software source code, +documentation source, and configuration files. -a) Subject to the terms of this Agreement, each Contributor hereby grants -Recipient a non-exclusive, worldwide, royalty-free copyright license to -reproduce, prepare derivative works of, publicly display, publicly perform, -distribute and sublicense the Contribution of such Contributor, if any, and -such derivative works, in source code and object code form. - -b) Subject to the terms of this Agreement, each Contributor hereby grants -Recipient a non-exclusive, worldwide, royalty-free patent license under -Licensed Patents to make, use, sell, offer to sell, import and otherwise -transfer the Contribution of such Contributor, if any, in source code and -object code form. This patent license shall apply to the combination of the -Contribution and the Program if, at the time the Contribution is added by the -Contributor, such addition of the Contribution causes such combination to be -covered by the Licensed Patents. The patent license shall not apply to any -other combinations which include the Contribution. No hardware per se is -licensed hereunder. - -c) Recipient understands that although each Contributor grants the licenses -to its Contributions set forth herein, no assurances are provided by any -Contributor that the Program does not infringe the patent or other -intellectual property rights of any other entity. Each Contributor disclaims -any liability to Recipient for claims brought by any other entity based on -infringement of intellectual property rights or otherwise. As a condition to -exercising the rights and licenses granted hereunder, each Recipient hereby -assumes sole responsibility to secure any other intellectual property rights -needed, if any. For example, if a third party patent license is required to -allow Recipient to distribute the Program, it is Recipient's responsibility -to acquire that license before distributing the Program. - -d) Each Contributor represents that to its knowledge it has sufficient -copyright rights in its Contribution, if any, to grant the copyright license -set forth in this Agreement. +"Secondary License" means either the GNU General Public License, +Version 2.0, or any later versions of that license, including any +exceptions or additional permissions as identified by the initial +Contributor. -3. REQUIREMENTS +2. GRANT OF RIGHTS -A Contributor may choose to distribute the Program in object code form under -its own license agreement, provided that: + a) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free copyright + license to reproduce, prepare Derivative Works of, publicly display, + publicly perform, Distribute and sublicense the Contribution of such + Contributor, if any, and such Derivative Works. + + b) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free patent + license under Licensed Patents to make, use, sell, offer to sell, + import and otherwise transfer the Contribution of such Contributor, + if any, in Source Code or other form. This patent license shall + apply to the combination of the Contribution and the Program if, at + the time the Contribution is added by the Contributor, such addition + of the Contribution causes such combination to be covered by the + Licensed Patents. The patent license shall not apply to any other + combinations which include the Contribution. No hardware per se is + licensed hereunder. + + c) Recipient understands that although each Contributor grants the + licenses to its Contributions set forth herein, no assurances are + provided by any Contributor that the Program does not infringe the + patent or other intellectual property rights of any other entity. + Each Contributor disclaims any liability to Recipient for claims + brought by any other entity based on infringement of intellectual + property rights or otherwise. As a condition to exercising the + rights and licenses granted hereunder, each Recipient hereby + assumes sole responsibility to secure any other intellectual + property rights needed, if any. For example, if a third party + patent license is required to allow Recipient to Distribute the + Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + + d) Each Contributor represents that to its knowledge it has + sufficient copyright rights in its Contribution, if any, to grant + the copyright license set forth in this Agreement. + + e) Notwithstanding the terms of any Secondary License, no + Contributor makes additional grants to any Recipient (other than + those set forth in this Agreement) as a result of such Recipient's + receipt of the Program under the terms of a Secondary License + (if permitted under the terms of Section 3). -a) it complies with the terms and conditions of this Agreement; and +3. REQUIREMENTS -b) its license agreement: +3.1 If a Contributor Distributes the Program in any form, then: -i) effectively disclaims on behalf of all Contributors all warranties and -conditions, express and implied, including warranties or conditions of title -and non-infringement, and implied warranties or conditions of merchantability -and fitness for a particular purpose; + a) the Program must also be made available as Source Code, in + accordance with section 3.2, and the Contributor must accompany + the Program with a statement that the Source Code for the Program + is available under this Agreement, and informs Recipients how to + obtain it in a reasonable manner on or through a medium customarily + used for software exchange; and -ii) effectively excludes on behalf of all Contributors all liability for -damages, including direct, indirect, special, incidental and consequential -damages, such as lost profits; + b) the Contributor may Distribute the Program under a license + different than this Agreement, provided that such license: + i) effectively disclaims on behalf of all other Contributors all + warranties and conditions, express and implied, including + warranties or conditions of title and non-infringement, and + implied warranties or conditions of merchantability and fitness + for a particular purpose; -iii) states that any provisions which differ from this Agreement are offered -by that Contributor alone and not by any other party; and + ii) effectively excludes on behalf of all other Contributors all + liability for damages, including direct, indirect, special, + incidental and consequential damages, such as lost profits; -iv) states that source code for the Program is available from such -Contributor, and informs licensees how to obtain it in a reasonable manner on -or through a medium customarily used for software exchange. + iii) does not attempt to limit or alter the recipients' rights + in the Source Code under section 3.2; and -When the Program is made available in source code form: + iv) requires any subsequent distribution of the Program by any + party to be under a license that satisfies the requirements + of this section 3. -a) it must be made available under this Agreement; and +3.2 When the Program is Distributed as Source Code: -b) a copy of this Agreement must be included with each copy of the Program. + a) it must be made available under this Agreement, or if the + Program (i) is combined with other material in a separate file or + files made available under a Secondary License, and (ii) the initial + Contributor attached to the Source Code the notice described in + Exhibit A of this Agreement, then the Program may be made available + under the terms of such Secondary Licenses, and -Contributors may not remove or alter any copyright notices contained within -the Program. + b) a copy of this Agreement must be included with each copy of + the Program. -Each Contributor must identify itself as the originator of its Contribution, -if any, in a manner that reasonably allows subsequent Recipients to identify -the originator of the Contribution. +3.3 Contributors may not remove or alter any copyright, patent, +trademark, attribution notices, disclaimers of warranty, or limitations +of liability ("notices") contained within the Program from any copy of +the Program which they Distribute, provided that Contributors may add +their own appropriate notices. 4. COMMERCIAL DISTRIBUTION -Commercial distributors of software may accept certain responsibilities with -respect to end users, business partners and the like. While this license is -intended to facilitate the commercial use of the Program, the Contributor who -includes the Program in a commercial product offering should do so in a -manner which does not create potential liability for other Contributors. -Therefore, if a Contributor includes the Program in a commercial product -offering, such Contributor ("Commercial Contributor") hereby agrees to defend -and indemnify every other Contributor ("Indemnified Contributor") against any -losses, damages and costs (collectively "Losses") arising from claims, -lawsuits and other legal actions brought by a third party against the -Indemnified Contributor to the extent caused by the acts or omissions of such -Commercial Contributor in connection with its distribution of the Program in -a commercial product offering. The obligations in this section do not apply -to any claims or Losses relating to any actual or alleged intellectual -property infringement. In order to qualify, an Indemnified Contributor must: -a) promptly notify the Commercial Contributor in writing of such claim, and -b) allow the Commercial Contributor tocontrol, and cooperate with the -Commercial Contributor in, the defense and any related settlement -negotiations. The Indemnified Contributor may participate in any such claim -at its own expense. - -For example, a Contributor might include the Program in a commercial product -offering, Product X. That Contributor is then a Commercial Contributor. If -that Commercial Contributor then makes performance claims, or offers -warranties related to Product X, those performance claims and warranties are -such Commercial Contributor's responsibility alone. Under this section, the -Commercial Contributor would have to defend claims against the other -Contributors related to those performance claims and warranties, and if a -court requires any other Contributor to pay any damages as a result, the -Commercial Contributor must pay those damages. +Commercial distributors of software may accept certain responsibilities +with respect to end users, business partners and the like. While this +license is intended to facilitate the commercial use of the Program, +the Contributor who includes the Program in a commercial product +offering should do so in a manner which does not create potential +liability for other Contributors. Therefore, if a Contributor includes +the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and indemnify every +other Contributor ("Indemnified Contributor") against any losses, +damages and costs (collectively "Losses") arising from claims, lawsuits +and other legal actions brought by a third party against the Indemnified +Contributor to the extent caused by the acts or omissions of such +Commercial Contributor in connection with its distribution of the Program +in a commercial product offering. The obligations in this section do not +apply to any claims or Losses relating to any actual or alleged +intellectual property infringement. In order to qualify, an Indemnified +Contributor must: a) promptly notify the Commercial Contributor in +writing of such claim, and b) allow the Commercial Contributor to control, +and cooperate with the Commercial Contributor in, the defense and any +related settlement negotiations. The Indemnified Contributor may +participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those performance +claims and warranties, and if a court requires any other Contributor to +pay any damages as a result, the Commercial Contributor must pay +those damages. 5. NO WARRANTY -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON -AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER -EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR -CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A -PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the -appropriateness of using and distributing the Program and assumes all risks -associated with its exercise of rights under this Agreement , including but -not limited to the risks and costs of program errors, compliance with -applicable laws, damage to or loss of data, programs or equipment, and -unavailability or interruption of operations. +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT +PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" +BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF +TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR +PURPOSE. Each Recipient is solely responsible for determining the +appropriateness of using and distributing the Program and assumes all +risks associated with its exercise of rights under this Agreement, +including but not limited to the risks and costs of program errors, +compliance with applicable laws, damage to or loss of data, programs +or equipment, and unavailability or interruption of operations. 6. DISCLAIMER OF LIABILITY -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY -CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION -LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT +PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS +SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST +PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE -EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY -OF SUCH DAMAGES. +EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. 7. GENERAL If any provision of this Agreement is invalid or unenforceable under -applicable law, it shall not affect the validity or enforceability of the -remainder of the terms of this Agreement, and without further action by the -parties hereto, such provision shall be reformed to the minimum extent -necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Program itself -(excluding combinations of the Program with other software or hardware) -infringes such Recipient's patent(s), then such Recipient's rights granted -under Section 2(b) shall terminate as of the date such litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it fails to -comply with any of the material terms or conditions of this Agreement and -does not cure such failure in a reasonable period of time after becoming -aware of such noncompliance. If all Recipient's rights under this Agreement -terminate, Recipient agrees to cease use and distribution of the Program as -soon as reasonably practicable. However, Recipient's obligations under this -Agreement and any licenses granted by Recipient relating to the Program shall -continue and survive. - -Everyone is permitted to copy and distribute copies of this Agreement, but in -order to avoid inconsistency the Agreement is copyrighted and may only be -modified in the following manner. The Agreement Steward reserves the right to -publish new versions (including revisions) of this Agreement from time to -time. No one other than the Agreement Steward has the right to modify this -Agreement. The Eclipse Foundation is the initial Agreement Steward. The -Eclipse Foundation may assign the responsibility to serve as the Agreement -Steward to a suitable separate entity. Each new version of the Agreement will -be given a distinguishing version number. The Program (including -Contributions) may always be distributed subject to the version of the -Agreement under which it was received. In addition, after a new version of -the Agreement is published, Contributor may elect to distribute the Program -(including its Contributions) under the new version. Except as expressly -stated in Sections 2(a) and 2(b) above, Recipient receives no rights or -licenses to the intellectual property of any Contributor under this -Agreement, whether expressly, by implication, estoppel or otherwise. All -rights in the Program not expressly granted under this Agreement are -reserved. - -This Agreement is governed by the laws of the State of New York and the -intellectual property laws of the United States of America. No party to this -Agreement will bring a legal action under this Agreement more than one year -after the cause of action arose. Each party waives its rights to a jury trial -in any resulting litigation. +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other software +or hardware) infringes such Recipient's patent(s), then such Recipient's +rights granted under Section 2(b) shall terminate as of the date such +litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of +time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use +and distribution of the Program as soon as reasonably practicable. +However, Recipient's obligations under this Agreement and any licenses +granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted and +may only be modified in the following manner. The Agreement Steward +reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement +Steward has the right to modify this Agreement. The Eclipse Foundation +is the initial Agreement Steward. The Eclipse Foundation may assign the +responsibility to serve as the Agreement Steward to a suitable separate +entity. Each new version of the Agreement will be given a distinguishing +version number. The Program (including Contributions) may always be +Distributed subject to the version of the Agreement under which it was +received. In addition, after a new version of the Agreement is published, +Contributor may elect to Distribute the Program (including its +Contributions) under the new version. + +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient +receives no rights or licenses to the intellectual property of any +Contributor under this Agreement, whether expressly, by implication, +estoppel or otherwise. All rights in the Program not expressly granted +under this Agreement are reserved. Nothing in this Agreement is intended +to be enforceable by any entity that is not a Contributor or Recipient. +No third-party beneficiary rights are created under this Agreement. + +Exhibit A - Form of Secondary Licenses Notice + +"This Source Code may also be made available under the following +Secondary Licenses when the conditions for such availability set forth +in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), +version(s), and exceptions or additional permissions here}." + + Simply including a copy of this Agreement, including this Exhibit A + is not sufficient to license the Source Code under Secondary Licenses. + + If it is not possible or desirable to put the notice in a particular + file, then You may include the notice in a location (such as a LICENSE + file in a relevant directory) where a recipient would be likely to + look for such a notice. + + You may add additional accurate notices of copyright ownership. From d9d3604cb50cfb83cea086788d33b1ebf911181b Mon Sep 17 00:00:00 2001 From: Harald Glab-Plhak Date: Fri, 21 Jun 2024 14:37:22 +0200 Subject: [PATCH 23/23] continued documentation. Added the ways to call the parser in a way that it works with ephemerol --- doc/REFERENCE.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/doc/REFERENCE.md b/doc/REFERENCE.md index 70a5f70..624a9e5 100644 --- a/doc/REFERENCE.md +++ b/doc/REFERENCE.md @@ -167,6 +167,55 @@ Here is a simple scanner definition with tese simplifying macros: A more detailed explanation by Marcus Crestani will be available later on [Functional development BLOG](https://funktionale-programmierung.de) +### How to write code making the parser generator working + +```clojure +;; here the real functionality of parse in lawrence is called +(defn parse + [input] + (lr-parser/parse grammar 1 :slr input)) + +;; here the scan result is given to the parser to get both connected +;; and to get a correct parser in cooperation with the scanner +;; scan and parse input +(def scan+parse + (comp parse scan)) + +;; just an example to see if the whole thing is working +(scan+parse "1+2*(65/5)") +``` + +And to be complete here again the scanner-generation of ephemorol +See []() for documentation + +```clojure +(defn scan + [input] + (let [scanned (scanner-run/scan-to-list scan-one (scanner-run/string->list input) + (scanner-run/make-position 1 0)) + scan-result (first scanned)] + (if (scanner-run/scan-error? scan-result) + ;; handle scan error + (throw (Exception. (pr-str scanned))) + scan-result))) + +``` + +et voila we have both connected up and running + +### How to store a specialized parser in connection with ephemerol on disk "blah_parser.clj" + +```clojure + (lr-parser/write-ds-parse-ns core/grammar 1 :slr + + ;; here the namespace as symbol + 'parser.generated-parser + ;; the needed requiring for the generated specialized + ;; parser + '([parser.generate :refer [parse-error]]) + "src/parser/generated_parser.clj")) +``` + **_Will be continued_** ......