Subversion Repositories PlanixRsrch.SVN

Compare Revisions

Ignore whitespace Rev 255 → Rev 266

/tags/mgen/0.0.3/mgen_skip_spaces.c
0,0 → 1,43
/*
* Copyright 2019,2020, The PLANIX Project
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
*/
 
#include "mgen.h"
 
int
mgen_skip_spaces(struct mgen_stream * mf )
{
int c;
while (1) {
c=mgen_getc(mf);
if ( mgen_isspace(c) ) {
continue;
}
break;
};
return c;
}
 
/tags/mgen/0.0.3/mi.prg
0,0 → 1,0
PROGRAMGgtBEGIN...END.
/tags/mgen/0.0.3/LICENSE
0,0 → 1,26
/*
* Copyright 2019,2020, The PLANIX Project
*
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
*/
/tags/mgen/0.0.3/my.bnf
0,0 → 1,11
<Programm> ::= a b c
 
<Programm1> ::= <Wort> Z u m s e l
<Buchstabe> ::= <Kleinbuchstabe> | <Grossbuchstabe>
<Wort> ::= <Buchstabe> <Wortrest> <Delimiter>
<Wortrest> ::= <Buchstabe> <Wortrest> |
<Kleinbuchstabe> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
<Grossbuchstabe> ::= A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
<Delimiter> ::= _ <Delimiterrest>
<Delimiterrest> ::= <Delimiter> |
 
/tags/mgen/0.0.3/Makefile
0,0 → 1,41
 
 
OBJS= mgen_getc.o \
mgen_open.o \
mgen_ungetc.o \
mgen_skip_spaces.o \
mgen_perror.o \
mgen_read_rule_set.o \
mgen_create_rule_set.o \
mgen_print_symlist.o \
mgen_print_rhs_list.o \
mgen_parse.o \
mgen_ring_init.o \
mgen_ring_alloc.o \
mgen_ring_prev.o\
mgen_ring_next.o\
mgen_ring_seek.o\
mgen_get_char_at.o
 
PRGOBJS=\
bnf.o
 
TSTOBJS=\
test.o
 
PRG=bnf
TSTPRG=test
 
.c.o:
$(CC) -c $(CFLAGS) $<
 
$(PRG): $(OBJS) $(PRGOBJS)
$(CC) $(LDFLAGS) -o $(PRG) $(PRGOBJS) $(OBJS) -lmavl
 
$(TSTPRG): $(OBJS) $(TSTOBJS)
$(CC) $(LDFLAGS) -o $(TSTPRG) $(TSTOBJS) $(OBJS) -lmavl -lmutests
 
clean:
rm -f *.o
rm -f $(PRG) $(TSTPRG)
rm -f *.core
Property changes:
Added: svn:mergeinfo
## -0,0 +0,5 ##
Merged /branches/bnf/mgen/Makefile:r129-228
Merged /branches/tmp-mgen/Makefile:r217-234
Merged /branches/tmp-mgen-restored/Makefile:r235-236
Merged /branches/bnf/bnf_cleanup/Makefile:r123-126
Merged /branches/mgen-tmp/Makefile:r152-155
Index: mgen/0.0.3/README
===================================================================
--- mgen/0.0.3/README (nonexistent)
+++ mgen/0.0.3/README (revision 266)
@@ -0,0 +1 @@
+A simple *true* BNF-Parser in pure ANSI C 89
Index: mgen/0.0.3/test.c
===================================================================
--- mgen/0.0.3/test.c (nonexistent)
+++ mgen/0.0.3/test.c (revision 266)
@@ -0,0 +1,209 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <mutests.h>
+
+#include "mgen.h"
+
+
+
+static char *
+gen_test_file(char *str)
+{
+ FILE *f;
+ char *filename;
+ filename = tmpnam(NULL);
+ f=fopen(filename,"wt");
+ (void)fprintf(f,str);
+ (void)fclose(f);
+ return filename;
+}
+
+
+
+int test_mgen_read_rule_set1(char *bnf, char *prg, char * start, int wrc)
+{
+ char * filename;
+ MGEN_FILE * mf;
+ struct mgen_rule_set * rules;
+ int rc;
+
+ filename = gen_test_file(bnf);
+ mf = mgen_open(filename,"");
+ rules = mgen_read_rule_set(mf);
+
+ mu_assert(rules!=NULL,"create rules");
+ (void) remove(filename);
+
+ filename = gen_test_file(prg);
+ mf = mgen_open(filename,"");
+ rc = mgen_parse(mf,rules, start);
+ mu_assert(rc == wrc, "mgen_parse bnf: %s, prg: %s",bnf,prg);
+
+ (void) remove (filename);
+ return 1;
+}
+
+int test_mgen_read_rule_set()
+{
+ int rc;
+ rc = test_mgen_read_rule_set1(
+ "<Program> ::= a b c",
+ "abc",
+ "Program",
+ 1);
+ rc |= test_mgen_read_rule_set1(
+ "<Program> ::= a b c",
+ "abx",
+ "Program",
+ 0);
+ rc |= test_mgen_read_rule_set1(
+"<Program> ::= <Word> a b c\n\
+<Word> ::= <Letter> <Wordrest>\n\
+<Wordrest> ::= <Letter> | \n\
+<Letter> ::= x | y | z",
+
+"xyabc",
+ "Program",
+ 1);
+ rc |= test_mgen_read_rule_set1(
+"<Programm1> ::= a b c\n"
+"<Programm> ::= <Wort> Z u m s e l\n"
+"<Buchstabe> ::= <Kleinbuchstabe> | <Grossbuchstabe>\n"
+"<Wort> ::= <Buchstabe> <Wortrest> <Delimiter>\n"
+"<Wortrest> ::= <Buchstabe> <Wortrest> |\n"
+"<Kleinbuchstabe> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z\n"
+"<Grossbuchstabe> ::= A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z\n"
+"<Delimiter> ::= _ <Delimiterrest>\n"
+"<Delimiterrest> ::= <Delimiter> |\n",
+ "Z____Zumsel",
+ "Programm",
+ 1);
+
+ rc |= test_mgen_read_rule_set1(
+"<Programm> ::= <syntax>\n"
+"<syntax> ::= <rule> EOF | <rule> <syntax>\n"
+"<rule> ::= <opt-whitespace> x <line-end>\n"
+"<EOL> ::= N\n"
+"<opt-whitespace> ::= S <opt-whitespace> |\n"
+"<line-end> ::= <opt-whitespace> N | <opt-whitespace> <EOL> <line-end>\n",
+ "xSNxNEOF",
+ "Programm",
+ 1);
+
+ return rc;
+}
+
+int test_mgen_ring_seek1(char *str,int bufsize,int blocksize)
+{
+ char * filename;
+ MGEN_FILE * mf;
+ int i,c,rc;
+
+ filename = gen_test_file(str);
+
+ mf = mgen_open(filename,"");
+ mu_assert(mf!=NULL, "seek: can't open file %s",filename);
+
+ mgen_ring_set_block_size(&mf->ring,(size_t)blocksize);
+ mgen_ring_set_buffer_size(&mf->ring,(size_t)bufsize);
+
+ for(i=0; i<(int)strlen(str); i++){
+ c = mgen_getc(mf);
+ mu_assert( c == str[i], "seek: test 1");
+ }
+
+ for(i=0; i<(int)strlen(str); i++){
+ rc = mgen_ring_seek(&mf->ring,(size_t)i);
+ if ( (int)strlen(str)-i > bufsize )
+ mu_assert(!rc,"seek: test 44");
+ else{
+ mu_assert(rc,"seek: test 45");
+ c = mgen_getc(mf);
+ mu_assert (c == str[i], "seek: test 77");
+ }
+ }
+
+ (void)remove(filename);
+ return 1;
+}
+
+int test_mgen_ring_seek()
+{
+ int rc=0;
+ rc |= test_mgen_ring_seek1("012345678",5,3);
+ rc |= test_mgen_ring_seek1("0123456789123",100,3);
+ rc |= test_mgen_ring_seek1("xxaass0123456789123",5,1);
+ rc |= test_mgen_ring_seek1("12345678",8,2);
+ rc |= test_mgen_ring_seek1("12345678",8,8);
+ rc |= test_mgen_ring_seek1("12345678",9,8);
+ return rc;
+}
+
+
+
+int test_mgen_getc()
+{
+ MGEN_FILE * mf;
+ char * str;
+ char *filename;
+ int i,rc;
+ int maxbuf,diff,blocksize;
+
+ str = "Hello World"; /* 11 characters */
+ diff = 3;
+ blocksize = 2;
+ maxbuf = (int)strlen(str)-diff;
+
+ filename = gen_test_file(str);
+
+ mf = mgen_open(filename,"");
+ mu_assert(mf!=NULL, "can't open file %s",filename);
+
+ mgen_ring_set_block_size(&mf->ring,(size_t)blocksize);
+ mgen_ring_set_buffer_size(&mf->ring,(size_t)maxbuf);
+
+ for (i=0; (size_t)i<strlen(str); i++){
+ int c;
+ c = mgen_getc(mf);
+ mu_assert(c == str[i],"test 1");
+ mu_assert((size_t)i+1 == mf->ring.abspos,"test 2");
+ }
+
+/* mu_assert(mf->ring.pos == (size_t)maxbuf % (size_t)diff-1, "test 3");*/
+
+ /* unget characters into the whole buffer */
+ for (i=0; i<maxbuf; i++){
+ rc = mgen_ungetc('0'+i,mf);
+ mu_assert(rc == '0'+i,"test 4");
+ }
+
+ /* unget one more character should result in EOF */
+ rc = mgen_ungetc('x',mf);
+ mu_assert( rc == EOF, "test 5");
+
+ for (i=0; i<maxbuf; i++){
+ rc = mgen_getc(mf);
+ mu_assert(rc == '0'+maxbuf-1-i, "test 6");
+ }
+
+ rc = mgen_getc(mf);
+ mu_assert(rc == EOF,"test 7");
+
+ (void)fclose(mf->infile);
+ (void)remove(filename);
+
+ return 1;
+}
+
+int main()
+{
+ mutests tf = {
+ test_mgen_getc,
+ test_mgen_ring_seek,
+ test_mgen_read_rule_set,
+ NULL
+ };
+ return mutests_run(tf);
+}
+
Index: mgen/0.0.3/algol60.bnf
===================================================================
--- mgen/0.0.3/algol60.bnf (nonexistent)
+++ mgen/0.0.3/algol60.bnf (revision 266)
@@ -0,0 +1,111 @@
+<program> ::= <block> | <compound statement>
+<block> ::= <unlabelled block> | <label>: <block>
+<unlabelled block> ::= <block head> ; <compound tail>
+<block head> ::= begin <declaration> | <block head> ; <declaration>
+<compound statement> ::= <unlabelled compound> | <label>: <compound statement>
+<unlabelled compound> ::= begin <compound tail>
+<compound tail> ::= <statement> end | <statement> ; <compound tail>
+<declaration> ::= <type declaration> | <array declaration> | <switch declaration> | <procedure declaration>
+<type declaration> ::= <local or own type> <type list>
+<local or own type> ::= <type> | own <type>
+<type> ::= real | integer | boolean
+<type list> ::= <simple variable> | <simple variable> , <type list>
+<array declaration> ::= array <array list> | <local or own type> array <array list>
+<array list> ::= <array segment> | <array list> , <array segment>
+<array segment> ::= <array identifier> [ <bound pair list> ] | <array identifier> , <array segment>
+<array identifier> ::= <identifier>
+<bound pair list> ::= <bound pair> | <bound pair list> , <bound pair>
+<bound pair> ::= <lower bound> : <upper bound>
+<upper bound> ::= <arithmetic expression>
+<lower bound> ::= <arithmetic expression>
+<switch declaration> ::= switch <switch identifier> := <switch list>
+<switch identifier> ::= <identifier>
+<switch list> ::= <designational expression> | <switch list> , <designational expression>
+<procedure declaration> ::= procedure <procedure heading> <procedure body> | <type> procedure <procedure heading> <procedure body>
+<procedure heading> ::= <procedure identifier> <formal parameter part> ; <value part> <specification part>
+<procedure identifier> ::= <identifier>
+<formal parameter part> ::= <empty> | ( <formal parameter list> )
+<formal parameter list> ::= <formal parameter> | <formal parameter list> <parameter delimiter> <formal parameter>
+<formal parameter> ::= <identifier>
+<value part> ::= value <identifier list> ; | <empty>
+<specification part> ::= <empty> | <specifier> <identifier list> ; | <specification part> <specifier> <identifier list>
+<specifier> ::= string | <type> | array | <type> array | label | switch | procedure | <type> procedure
+<identifier list> ::= <identifier> | <identifier list> , <identifier>
+<procedure body> ::= <statement> | <code>
+<statement> ::= <unconditional statement> | <conditional statement> | <for statement>
+<unconditional statement> ::= <basic statement> | <compound statement> | <block>
+<basic statement> ::= <unlabelled basic statement> | <label>: <basic statement>
+<label> ::= <identifier> | <unsigned integer>
+<unlabelled basic statement> ::= <assignment statement> | <go to statement> | <dummy statement> | <procedure statement>
+<assignment statement> ::= <left part list> <arithmetic expression> | <left part list> <Boolean expression>
+<left part list> ::= <left part> | <left part list> <left part>
+<left part> ::= <variable> := | <procedure identifier> :=
+<go to statement> ::= goto <designational expression>
+<designational expression> ::= <simple designational expression> | <if clause> <simple designational expression> else <designational expression>
+<simple designational expression> ::= <label> | <switch designator> | (<designational expression>)
+<switch designator> ::= <switch identifier> [<subscript expression>]
+<dummy statement> ::= <empty>
+<procedure statement> ::= <procedure identifier> <actual parameter part>
+<actual parameter part> ::= <empty> | ( <actual parameter list> )
+<actual parameter list> ::= <actual parameter> | <actual parameter list> <parameter delimiter> <actual parameter>
+<parameter delimiter> ::= , | ) <letter string> : (
+<actual parameter> ::= <string> | <expression> | <array identifier> | <switch identifier> | <procedure identifier>
+<conditional statement> ::= <if statement> | <if statement> else <statement> | <if clause> <for statement> | <label>: <conditional statement>
+<if statement> ::= <if clause> <unconditional statement>
+<if clause> ::= if <Boolean expression> then
+<for statement> ::= <for clause> <statement> | <label>: <for statement>
+<for clause> ::= for <variable> := <for list> do
+<for list> ::= <for list element> | <for list> , <for list element>
+<for list element> ::= <arithmetic expression> | <arithmetic expression> step <arithmetic expression> until <arithmetic expression> | <arithmetic expression> while <Boolean expression>
+<expression> ::= <arithmetic expression> | <Boolean expression> | <designational expression>
+<arithmetic expression> ::= <simple arithmetic expression> | <if clause> <simple arithmetic expression> else <arithmetic expression>
+<simple arithmetic expression> ::= <term> | <adding operator> <term> | <simple arithmetic expression> <adding operator> <term>
+<adding operator> ::= + | –
+<term> ::= <factor> | <term> <multiplying operator> <factor>
+<multiplying operator> ::= × | / | ÷
+<factor> ::= <primary> | <factor> | <factor> ↑ <primary>
+<primary> ::= <unsigned number> | <variable> | <function designator> | ( <arithmetic expression> )
+<unsigned number> ::= <decimal number> | <exponential part> | <decimal number> <exponential part>
+
+<decimal number> ::= <unsigned integer> | <decimal fraction> | <unsigned integer> <decimal fraction>
+<unsigned integer> ::= <digit> | <unsigned integer> <digit>
+<decimal fraction> ::= . <unsigned integer>
+<exponential part> ::= 10 <integer>
+<integer> ::= <unsigned integer> | + <unsigned integer> | – <unsigned integer>
+<Boolean expression> ::= <simple Boolean> | <if clause> <simple Boolean> else <Boolean expression>
+<simple Boolean> ::= <implication> | <simple Boolean> ≣ <implication>
+<implication> ::= <Boolean term> | <implication> ⊃ <Boolean term>
+<Boolean term> ::= <Boolean factor> | <Boolean term> ⋁ <Boolean factor>
+<Boolean factor> ::= <Boolean secondary> | <Boolean factor> ⋀ <Boolean secondary>
+<Boolean secondary> ::= <Boolean primary> | ¬ <Boolean primary>
+<Boolean primary> ::= <logical value> | <variable> | <function designator> | <relation> | ( <Boolean expression> )
+<relation> ::= <simple arithmetic expression> <relational operator> <simple arithmetic expression>
+<relational operator> ::= < | ≤ | = | ≠ | > | ≥
+<function designator> ::= <procedure identifier> <actual parameter part>
+<variable> ::= <simple variable> | <subscripted variable>
+<simple variable> ::= <variable identifier>
+<variable identifier> ::= <identifier>
+<subscripted variable> ::= <array identifier> [ <subscript list> ]
+<subscript list> ::= <subscript expression> | <subscript list> , <subscript expression>
+<subscript expression> ::= <arithmetic expression>
+<string> ::= "<open string>"
+<open string> ::= <proper string> "<open string>" | <open string><open string>
+<proper string> ::= <any sequence of symbols not containing " > | <empty>
+<letter string> ::= <letter> | <letter string> <letter>
+<identifier> ::= letter> | <identifier> <letter> | <identifier> <digit>
+<basic symbol> ::= <letter> | <digit> | <logical value> | <delimiter>
+<letter> ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
+A| B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
+<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
+<logical value> ::= true | false
+<delimiter> ::= <operator> | <separator> | <bracket> | <declarator> | <specificator>
+<operator> ::= <arithmetic operator> | <relational operator> | <logical operator> | <sequential operator>
+<arithmetic operator> ::= + | – | × | / | ÷ | ↑
+<relational operator> ::= < | ≤ | = | ≠ | > | ≥
+<logical operator> ::= ≣ | ⊃ | ⋁ | ⋀ | ¬
+<sequential operator> ::= goto | if | then | else | for | do
+<separator> ::= , | . | 10 | : | ; | := | _ | step | until | while | comment
+<bracket> ::= ( | ) | [ | ] | ` | ' | begin | end
+<declarator> ::= own | boolean | integer | real | array | switch | procedure
+<specificator> ::= string | label | value
+
Index: mgen/0.0.3/x.prg
===================================================================
--- mgen/0.0.3/x.prg (nonexistent)
+++ mgen/0.0.3/x.prg (revision 266)
@@ -0,0 +1 @@
+xSNxNEOFa
Index: mgen/0.0.3/algol60.raw
===================================================================
--- mgen/0.0.3/algol60.raw (nonexistent)
+++ mgen/0.0.3/algol60.raw (revision 266)
@@ -0,0 +1,7 @@
+:
+<program> ::= <block> | <compound statement><block> ::= <unlabelled block> | <label>: <block>
+<unlabelled block> ::= <block head> ;
+<compound tail><block head> ::= begin <declaration> | <block head> ; <declaration>
+<compound statement> ::= <unlabelled compound> | <label>: <compound statement><unlabelled compound> ::= begin <compound tail><compound tail> ::= <statement> end | <statement> ; <compound tail><declaration> ::= <type declaration> | <array declaration> | <switch declaration> | <procedure declaration><type declaration> ::= <local or own type> <type list><local or own type> ::= <type> | own <type><type> ::= real | integer | boolean<type list> ::= <simple variable> | <simple variable> , <type list><array declaration> ::= array <array list> | <local or own type> array <array list><array list> ::= <array segment> | <array list> , <array segment><array segment> ::= <array identifier> [ <bound pair list> ] | <array identifier> , <array segment><array identifier> ::= <identifier><bound pair list> ::= <bound pair> | <bound pair list> , <bound pair><bound pair> ::= <lower bound> : <upper bound><upper bound> ::= <arithmetic expression><lower bound> ::= <arithmetic expression><switch declaration> ::= switch <switch identifier> := <switch list><switch identifier> ::= <identifier><switch list> ::= <designational expression> | <switch list> , <designational expression><procedure declaration> ::= procedure <procedure heading> <procedure body> | <type> procedure <procedure heading> <procedure body><procedure heading> ::= <procedure identifier> <formal parameter part> ; <value part> <specification part><procedure identifier> ::= <identifier><formal parameter part> ::= <empty> | ( <formal parameter list> )<formal parameter list> ::= <formal parameter> | <formal parameter list> <parameter delimiter> <formal parameter><formal parameter> ::= <identifier> <value part> ::= value <identifier list> ; | <empty><specification part> ::= <empty> | <specifier> <identifier list> ; | <specification part> <specifier> <identifier list><specifier> ::= string | <type> | array | <type> array | label | switch | procedure | <type> procedure<identifier list> ::= <identifier> | <identifier list> , <identifier><procedure body> ::= <statement> | <code><statement> ::= <unconditional statement> | <conditional statement> | <for statement><unconditional statement> ::= <basic statement> | <compound statement> | <block><basic statement> ::= <unlabelled basic statement> | <label>: <basic statement><label> ::= <identifier> | <unsigned integer><unlabelled basic statement> ::= <assignment statement> | <go to statement> | <dummy statement> | <procedure statement><assignment statement> ::= <left part list> <arithmetic expression> | <left part list> <Boolean expression><left part list> ::= <left part> | <left part list> <left part><left part> ::= <variable> := | <procedure identifier> :=<go to statement> ::= goto <designational expression><designational expression> ::= <simple designational expression> |<if clause> <simple designational expression> else <designational expression><simple designational expression> ::= <label> | <switch designator> | (<designational expression>)<switch designator> ::= <switch identifier> [<subscript expression>]<dummy statement> ::= <empty><procedure statement> ::= <procedure identifier> <actual parameter part><actual parameter part> ::= <empty> | ( <actual parameter list> )<actual parameter list> ::= <actual parameter> | <actual parameter list> <parameter delimiter> <actual parameter><parameter delimiter> ::= , | ) <letter string> : (<actual parameter> ::= <string> | <expression> | <array identifier> | <switch identifier> | <procedure identifier><conditional statement> ::= <if statement> | <if statement> else <statement> | <if clause> <for statement> | <label>: <conditional statement><if statement> ::= <if clause> <unconditional statement><if clause> ::= if <Boolean expression> then<for statement> ::= <for clause> <statement> | <label>: <for statement><for clause> ::= for <variable> := <for list> do<for list> ::= <for list element> | <for list> , <for list element><for list element> ::= <arithmetic expression> |<arithmetic expression> step <arithmetic expression> until <arithmetic expression> |<arithmetic expression> while <Boolean expression><expression> ::= <arithmetic expression> | <Boolean expression> | <designational expression><arithmetic expression> ::= <simple arithmetic expression> | <if clause> <simple arithmetic expression> else <arithmetic expression><simple arithmetic expression> ::= <term> | <adding operator> <term> | <simple arithmetic expression> <adding operator> <term><adding operator> ::= + | –<term> ::= <factor> | <term> <multiplying operator> <factor><multiplying operator> ::= × | / | ÷<factor> ::= <primary> | <factor> | <factor> ↑ <primary><primary> ::= <unsigned number> | <variable> | <function designator> | ( <arithmetic expression> )<unsigned number> ::= <decimal number> | <exponential part> | <decimal number> <exponential part>
+<decimal number> ::= <unsigned integer> | <decimal fraction> | <unsigned integer> <decimal fraction><unsigned integer> ::= <digit> | <unsigned integer> <digit><decimal fraction> ::= . <unsigned integer><exponential part> ::= 10 <integer><integer> ::= <unsigned integer> | + <unsigned integer> | – <unsigned integer><Boolean expression> ::= <simple Boolean> | <if clause> <simple Boolean> else <Boolean expression><simple Boolean> ::= <implication> | <simple Boolean> ≣ <implication><implication> ::= <Boolean term> | <implication> ⊃ <Boolean term><Boolean term> ::= <Boolean factor> | <Boolean term> ⋁ <Boolean factor><Boolean factor> ::= <Boolean secondary> | <Boolean factor> ⋀ <Boolean secondary><Boolean secondary> ::= <Boolean primary> | ¬ <Boolean primary><Boolean primary> ::= <logical value> | <variable> | <function designator> | <relation> | ( <Boolean expression> )<relation> ::= <simple arithmetic expression> <relational operator> <simple arithmetic expression><relational operator> ::= < | ≤ | = | ≠ | > | ≥<function designator> ::= <procedure identifier> <actual parameter part><variable> ::= <simple variable> | <subscripted variable><simple variable> ::= <variable identifier><variable identifier> ::= <identifier><subscripted variable> ::= <array identifier> [ <subscript list> ]<subscript list> ::= <subscript expression> | <subscript list> , <subscript expression><subscript expression> ::= <arithmetic expression><string> ::= "<open string>"<open string> ::= <proper string> "<open string>" | <open string><open string><proper string> ::= <any sequence of symbols not containing " > | <empty><letter string> ::= <letter> | <letter string> <letter><identifier> ::= letter> | <identifier> <letter> | <identifier> <digit><basic symbol> ::= <letter> | <digit> | <logical value> | <delimiter><letter> ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |A |B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <logical value> ::= true | false<delimiter> ::= <operator> | <separator> | <bracket> | <declarator> | <specificator><operator> ::= <arithmetic operator> | <relational operator> | <logical operator> | <sequential operator><arithmetic operator> ::= + | – | × | / | ÷ | ↑<relational operator> ::= < | ≤ | = | ≠ | > | ≥<logical operator> ::= ≣ | ⊃ | ⋁ | ⋀ | ¬<sequential operator> ::= goto | if | then | else | for | do<separator> ::= , | . | 10 | : | ; | := | _ | step | until | while | comment<bracket> ::= ( | ) | [ | ] | ` | ' | begin | end<declarator> ::= own | boolean | integer | real | array | switch | procedure<specificator> ::= string | label | value
+
Index: mgen/0.0.3/algol60.txt
===================================================================
--- mgen/0.0.3/algol60.txt (nonexistent)
+++ mgen/0.0.3/algol60.txt (revision 266)
@@ -0,0 +1,110 @@
+
+<program> ::= <block> | <compound statement>
+<block> ::= <unlabelled block> | <label>: <block>
+<unlabelled block> ::= <block head> ;
+<compound tail>
+<block head> ::= begin <declaration> | <block head> ; <declaration>
+<compound statement> ::= <unlabelled compound> | <label>: <compound statement>
+<unlabelled compound> ::= begin <compound tail>
+<compound tail> ::= <statement> end | <statement> ;
+<compound tail>
+<declaration> ::=
+ <type declaration> | <array declaration> | <switch declaration> | <procedure declaration>
+
+<type declaration> ::= <local or own type>
+<type list>
+<local or own type> ::= <type> | own
+<type>
+<type> ::= real | integer | boolean
+<type list> ::= <simple variable> | <simple variable> , <type list>
+<array declaration> ::= array <array list> | <local or own type> array <array list>
+<array list> ::= <array segment> | <array list> , <array segment>
+<array segment> ::= <array identifier> [ <bound pair list> ] | <array identifier> , <array segment>
+<array identifier> ::= <identifier>
+<bound pair list> ::= <bound pair> | <bound pair list> , <bound pair>
+<bound pair> ::= <lower bound> : <upper bound>
+<upper bound> ::= <arithmetic expression>
+<lower bound> ::= <arithmetic expression>
+<switch declaration> ::= switch <switch identifier> := <switch list>
+<switch identifier> ::= <identifier>
+<switch list> ::= <designational expression> | <switch list> , <designational expression>
+<procedure declaration> ::= procedure <procedure heading> <procedure body> | <type> procedure <procedure heading> <procedure body>
+<procedure heading> ::= <procedure identifier> <formal parameter part> ; <value part> <specification part>
+<procedure identifier> ::= <identifier>
+<formal parameter part> ::= <empty> | ( <formal parameter list> )
+<formal parameter list> ::= <formal parameter> | <formal parameter list> <parameter delimiter> <formal parameter>
+<formal parameter> ::= <identifier> <value part> ::= value <identifier list> ; | <empty>
+<specification part> ::= <empty> | <specifier> <identifier list> ; | <specification part> <specifier> <identifier list>
+<specifier> ::= string | <type> | array | <type> array | label | switch | procedure | <type> procedure<identifier list> ::= <identifier> | <identifier list> , <identifier>
+<procedure body> ::= <statement> | <code>
+<statement> ::= <unconditional statement> | <conditional statement> | <for statement>
+<unconditional statement> ::= <basic statement> | <compound statement> | <block>
+<basic statement> ::= <unlabelled basic statement> | <label>: <basic statement>
+<label> ::= <identifier> | <unsigned integer>
+<unlabelled basic statement> ::= <assignment statement> | <go to statement> | <dummy statement> | <procedure statement>
+<assignment statement> ::= <left part list> <arithmetic expression> | <left part list> <Boolean expression>
+<left part list> ::= <left part> | <left part list> <left part>
+<left part> ::= <variable> := | <procedure identifier> :=<go to statement> ::= goto <designational expression>
+<designational expression> ::= <simple designational expression> |<if clause> <simple designational expression> else <designational expression>
+<simple designational expression> ::= <label> | <switch designator> | (<designational expression>)
+<switch designator> ::= <switch identifier> [<subscript expression>]
+<dummy statement> ::= <empty>
+<procedure statement> ::= <procedure identifier> <actual parameter part>
+<actual parameter part> ::= <empty> | ( <actual parameter list> )
+<actual parameter list> ::= <actual parameter> | <actual parameter list> <parameter delimiter> <actual parameter>
+
+<parameter delimiter> ::= , | ) <letter string> : (
+<actual parameter> ::= <string> | <expression> | <array identifier> | <switch identifier> | <procedure identifier>
+
+<conditional statement> ::= <if statement> | <if statement> else <statement> |
+ <if clause> <for statement> | <label>: <conditional statement>
+
+<if statement> ::= <if clause> <unconditional statement>
+<if clause> ::= if <Boolean expression> then<for statement> ::= <for clause> <statement> | <label>: <for statement>
+<for clause> ::= for <variable> := <for list> do<for list> ::= <for list element> | <for list> , <for list element>
+<for list element> ::= <arithmetic expression> |<arithmetic expression> step <arithmetic expression> until <arithmetic expression> |<arithmetic expression> while <Boolean expression>
+<expression> ::= <arithmetic expression> | <Boolean expression> | <designational expression>
+<arithmetic expression> ::= <simple arithmetic expression> | <if clause> <simple arithmetic expression> else <arithmetic expression>
+<simple arithmetic expression> ::= <term> | <adding operator> <term> | <simple arithmetic expression> <adding operator> <term>
+<adding operator> ::= + | –<term> ::= <factor> | <term> <multiplying operator> <factor>
+<multiplying operator> ::= × | / | ÷<factor> ::= <primary> | <factor> | <factor> ↑ <primary>
+<primary> ::= <unsigned number> | <variable> | <function designator> | ( <arithmetic expression> )<unsigned number> ::= <decimal number> | <exponential part> | <decimal number> <exponential part>
+<decimal number> ::= <unsigned integer> | <decimal fraction> | <unsigned integer> <decimal fraction>
+<unsigned integer> ::= <digit> | <unsigned integer> <digit>
+<decimal fraction> ::= . <unsigned integer>
+<exponential part> ::= 10 <integer>
+<integer> ::= <unsigned integer> | + <unsigned integer> | – <unsigned integer>
+<Boolean expression> ::= <simple Boolean> | <if clause> <simple Boolean> else <Boolean expression>
+<simple Boolean> ::= <implication> | <simple Boolean> ≣ <implication>
+<implication> ::= <Boolean term> | <implication> ⊃ <Boolean term>
+<Boolean term> ::= <Boolean factor> | <Boolean term> ⋁ <Boolean factor>
+<Boolean factor> ::= <Boolean secondary> | <Boolean factor> ⋀ <Boolean secondary>
+<Boolean secondary> ::= <Boolean primary> | ¬ <Boolean primary>
+<Boolean primary> ::= <logical value> | <variable> | <function designator> | <relation> | ( <Boolean expression> )<relation> ::= <simple arithmetic expression> <relational operator> <simple arithmetic expression>
+<relational operator> ::= < | ≤ | = | ≠ | > | ≥<function designator> ::= <procedure identifier> <actual parameter part>
+<variable> ::= <simple variable> | <subscripted variable>
+<simple variable> ::= <variable identifier>
+<variable identifier> ::= <identifier>
+<subscripted variable> ::= <array identifier> [ <subscript list> ]<subscript list> ::= <subscript expression> | <subscript list> , <subscript expression>
+<subscript expression> ::= <arithmetic expression>
+<string> ::= "<open string>"
+<open string> ::= <proper string> "<open string>" | <open string>
+<open string>
+<proper string> ::= <any sequence of symbols not containing " > | <empty>
+<letter string> ::= <letter> | <letter string> <letter>
+<identifier> ::= letter> | <identifier> <letter> | <identifier> <digit>
+<basic symbol> ::= <letter> | <digit> | <logical value> | <delimiter>
+<letter> ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |A |B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
+<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
+<logical value> ::= true | false
+<delimiter> ::= <operator> | <separator> | <bracket> | <declarator> | <specificator>
+<operator> ::= <arithmetic operator> | <relational operator> | <logical operator> | <sequential operator>
+<arithmetic operator> ::= + | – | × | / | ÷ | ↑
+<relational operator> ::= < | ≤ | = | ≠ | > | ≥
+<logical operator> ::= ≣ | ⊃ | ⋁ | ⋀ | ¬
+<sequential operator> ::= goto | if | then | else | for | do
+<separator> ::= , | . | 10 | : | ; | := | _ | step | until | while | comment
+<bracket> ::= ( | ) | [ | ] | ` | ' | begin | end
+<declarator> ::= own | boolean | integer | real | array | switch | procedure
+<specificator> ::= string | label | value
+
Index: mgen/0.0.3/bnf.bnf
===================================================================
--- mgen/0.0.3/bnf.bnf (nonexistent)
+++ mgen/0.0.3/bnf.bnf (revision 266)
@@ -0,0 +1,22 @@
+<Programm> ::= <syntax>
+
+<syntax> ::= <rule> | <rule> <syntax>
+<rule> ::= <opt-whitespace> < <rule-name> > <opt-whitespace> ::= <opt-whitespace> <expression> <line-end>
+<opt-whitespace> ::= \s <opt-whitespace> |
+<expression> ::= <list> | <list> <opt-whitespace> \| <opt-whitespace> <expression>
+<line-end> ::= <opt-whitespace> <EOL> | <line-end> <line-end>
+<list> ::= <term> | <term> <opt-whitespace> <list>
+<term> ::= <literal> | < <rule-name> >
+<literal> ::= " <text1> " | ' <text2> '
+<text1> ::= | <character1> <text1>
+<text2> ::= | <character2> <text2>
+<character> ::= <letter> | <digit> | <symbol>
+<letter> ::= A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z
+<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
+<symbol> ::= | | | ! | # | $ | % | & | ( | ) | * | + | , | - | . | / | : | ; | > | = | < | ? | @ | [ | \ | ] | ^ | _ | ` | { | } | ~
+<character1> ::= <character> | '
+<character2> ::= <character> | "
+<rule-name> ::= <letter> | <rule-name> <rule-char>
+<rule-char> ::= <letter> | <digit> | -
+
+<EOL> ::= \n
Index: mgen/0.0.3/bnf.c
===================================================================
--- mgen/0.0.3/bnf.c (nonexistent)
+++ mgen/0.0.3/bnf.c (revision 266)
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2019, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <libmavl/mavl.h>
+
+#define MAX_NONTERMINAL 1024
+#define MAX_TERMINAL 1024
+
+#include "mgen.h"
+
+const char * prgname;
+
+void
+print(struct mavl *t)
+{
+ struct mavliter it;
+ void *data;
+
+ mavliter_init(&it, t);
+ (void)mavliter_seek_set(&it);
+
+ while ((data = mavliter_get(&it)) != NULL) {
+ struct mgen_rule * rule = (struct mgen_rule *)data;
+ struct rhs_elem *e;
+ struct mgen_sym *sym;
+ char * delim_or, *delim_spc;
+
+ delim_or="";
+
+ (void)printf("<%s> ::= ",rule->name);
+ e = rule->rhs_list;
+ while (e!=NULL){
+ sym = e->sym_list;
+ (void)printf("%s",delim_or);
+ delim_or="|";
+ delim_spc="";
+ while (sym!=NULL){
+ if (sym->type == MGEN_NT_SYM)
+ (void)printf("%s<%s>",delim_spc,sym->name);
+ else
+ (void)printf("%s'%s'",delim_spc,sym->name);
+ sym = sym->next;
+ delim_spc=" ";
+ }
+ e=e->next;
+ }
+ (void)printf("\n");
+
+
+ (void)mavliter_next(&it);
+ }
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct mgen_stream *mf;
+ struct mgen_rule_set * rules;
+ int rc;
+ FILE *infile;
+ const char * filename;
+
+ if (argc>0)
+ prgname = argv[0];
+ else
+ prgname ="";
+
+ if (argc==1){
+ infile = stdin;
+ filename = NULL;
+ }
+ else{
+ infile = fopen(argv[1],"rt");
+ filename=argv[1];
+ if (!infile){
+ (void)fprintf(stderr,
+ "%s: error: can't open '%s': %s\n",
+ prgname,filename,strerror(errno)
+ );
+ return errno;
+ }
+
+ }
+
+ mf = mgen_open_stream(infile,prgname);
+ if (!mf){
+ (void)fprintf(stderr,"Error: %s",strerror(errno));
+ return errno;
+ }
+printf("Read Rules\n");
+ rules = mgen_read_rule_set(mf);
+printf("Done read rules\n");
+ if (rules==NULL)
+ return 1;
+
+ if (argc==3){
+ mf = mgen_open(argv[2],prgname);
+ if (!mf){
+ perror("");
+ return 1;
+ }
+/* mgen_set_block_size(mf,1112);
+ mgen_set_buf_size(mf,1118);
+*/
+
+ (void)printf("------------------------------\n");
+ print(rules->rules);
+
+(void)printf("call parse\n");
+(void)printf("================================================\n");
+ rc = mgen_parse(mf,rules,"Programm");
+ (void)printf("RC: %s\n", rc ? "TRUE" : "FALSE");
+
+ /*run(rules,argv[2]);*/
+ }
+ return 0;
+}
Index: mgen/0.0.3/example.bnf
===================================================================
--- mgen/0.0.3/example.bnf (nonexistent)
+++ mgen/0.0.3/example.bnf (revision 266)
@@ -0,0 +1,6 @@
+
+<Ziffer ausser Null> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
+<Ziffer> ::= 0 | <Ziffer ausser Null>
+<Zweistellige Zahl> ::= <Ziffer ausser Null> <Ziffer>
+<Zehn bis Neunzehn> ::= 1 <Ziffer>
+<Zweiundvierzig> ::= 42
Index: mgen/0.0.3/man/mgen_ring.3
===================================================================
--- mgen/0.0.3/man/mgen_ring.3 (nonexistent)
+++ mgen/0.0.3/man/mgen_ring.3 (revision 266)
@@ -0,0 +1,17 @@
+.TH MGEN_RING 3
+.SH NAME
+mgen_ring_alloc
+.SH SYNOPSIS
+.B #include <mgen.h>
+.PP
+int
+.B mgen_ring_alloc
+(MGEN_RING *ring);
+.SH DESCRIPTION
+.PP
+The
+.B mgen_ring_alloc()
+function ensures that enough memory is allocated to store one
+element into the buffer at m.buf[m.pos]. The function returns 1
+when successful, otherwise 0.
+
Index: mgen/0.0.3/mgen.h
===================================================================
--- mgen/0.0.3/mgen.h (nonexistent)
+++ mgen/0.0.3/mgen.h (revision 266)
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2019, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#ifndef _MGEN_H
+#define _MGEN_H
+
+
+#include <ctype.h>
+#include <stdio.h>
+#include <libmavl/mavl.h>
+
+#ifndef MGEN_BUF_BLOCK_SIZE
+#define MGEN_BUF_BLOCK_SIZE 1024
+#endif
+
+#ifndef MGEN_BUF_SIZE
+#define MGEN_BUF_SIZE (8192)
+#endif
+
+/* representation of a dynamically
+ * growing (ring) buffer */
+struct mgen_ring{
+ void *buf;
+ size_t pos;
+ size_t maxpos;
+ size_t abspos;
+ size_t absmaxpos;
+
+ size_t block_size;
+ size_t bufmax_size;
+ size_t buf_size;
+ size_t elem_size;
+};
+typedef struct mgen_ring MGEN_RING;
+void mgen_ring_init(struct mgen_ring *m,size_t elem_size);
+size_t mgen_ring_next(struct mgen_ring *m);
+int mgen_ring_prev(struct mgen_ring *m);
+int mgen_ring_alloc(MGEN_RING *ring);
+int mgen_ring_seek(MGEN_RING * ring, size_t pos);
+
+struct mgen_char{
+ int c;
+ int line;
+ int col;
+};
+typedef struct mgen_char MGEN_CHAR;
+
+#define mgen_ring_set_block_size(r,s) ((r)->block_size=s)
+#define mgen_ring_set_buffer_size(r,s) ((r)->bufmax_size=s)
+#define mgen_ring_getat(ring,type,pos) (&(((type*)((ring)->buf))[pos]))
+
+
+
+struct mgen_stream {
+ FILE *infile; /* file pointer of current open file */
+ int line; /* line number */
+ int col; /* current column */
+
+ MGEN_RING ring;
+
+ char *buf;
+ int buflast;
+ int buffirst;
+ int bufptr;
+ int bufmax;
+
+
+
+
+ int prev_col;
+
+ int tab_size;
+ int block_size;
+ int buf_size;
+
+ const char *filename;
+ const char *prgname;
+
+/* int eof:1;*/
+};
+
+
+typedef struct mgen_stream MGEN_FILE;
+
+enum {
+ MGEN_NT_SYM, /* describes a non-terminal symbol */
+ MGEN_T_SYM /* a terminal symbol */
+};
+
+/* representation of a symbol */
+struct mgen_sym {
+ int type;
+ struct mgen_sym * next;
+ char *name;
+};
+
+/*extern struct rhs_elem;*/
+struct rhs_elem{
+ struct mgen_sym * sym_list;
+ struct rhs_elem * next;
+};
+
+struct mgen_rule {
+ char * name;
+ int line;
+ struct rhs_elem * rhs_list;
+};
+
+
+struct mgen_rule_set {
+ struct mavl * rules;
+};
+typedef struct mgen_rule_set MGEN_RULE_SET;
+
+int mgen_getc(struct mgen_stream * mf);
+MGEN_CHAR * mgen_get_char_at(MGEN_FILE *mf,size_t pos);
+struct mgen_stream * mgen_open(const char *filename, const char *prgname);
+int mgen_ungetc(int c, struct mgen_stream *mf);
+int mgen_skip_spaces(struct mgen_stream * mf );
+void mgen_perror(struct mgen_stream *mf, char *msg, ...);
+struct mgen_stream * mgen_open_stream(FILE *infile, const char *prgname);
+struct mgen_rule_set * mgen_read_rule_set(struct mgen_stream *mf);
+struct mgen_rule_set * mgen_create_rule_set();
+int mgen_parse( struct mgen_stream *mf,
+ struct mgen_rule_set *rules,
+ const char * start);
+
+/* debugging stuff */
+void print_symlist(struct mgen_sym * sym);
+void print_rhs_list(struct rhs_elem *e);
+
+#define mgen_isspace(c) isspace(c)
+
+
+#define mgen_tell(mf) (mf->ring.abspos)
+
+/*#define mgen_seek(mf,pos) (mf->bufptr=(pos))*/
+
+
+#define mgen_seek(mf,pos) mgen_ring_seek(&((mf)->ring),pos)
+
+
+#define mgen_set_block_size(mf,s) mf->block_size=s
+#define mgen_set_buf_size(mf,s) mf->buf_size=s
+
+#endif
/mgen/0.0.3/mgen.h
Property changes:
Added: svn:mergeinfo
## -0,0 +0,5 ##
Merged /branches/tmp-mgen-restored/mgen.h:r235-236
Merged /branches/mgen-tmp/mgen.h:r152-155
Merged /branches/bnf/bnf_cleanup/mgen.h:r123-126
Merged /branches/bnf/mgen/mgen.h:r129-228
Merged /branches/tmp-mgen/mgen.h:r217-234
Index: mgen/0.0.3/mgen_create_rule_set.c
===================================================================
--- mgen/0.0.3/mgen_create_rule_set.c (nonexistent)
+++ mgen/0.0.3/mgen_create_rule_set.c (revision 266)
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+#include <string.h>
+#include "mgen.h"
+
+static int
+cmp_rules(const void *v1, const void *v2)
+{
+ const char *s1,*s2;
+ s1 = ((struct mgen_rule *)v1)->name;
+ s2 = ((struct mgen_rule *)v2)->name;
+
+ return strcmp(s1,s2);
+}
+
+
+struct mgen_rule_set *
+mgen_create_rule_set()
+{
+ MGEN_RULE_SET * rs;
+ rs = malloc (sizeof(MGEN_RULE_SET));
+ if (!rs)
+ return NULL;
+
+ rs->rules = mavl_create(cmp_rules,
+ NULL, sizeof (struct mgen_rule) );
+ if (!rs->rules){
+ free(rs);
+ return NULL;
+ }
+ return rs;
+}
Index: mgen/0.0.3/mgen_get_char_at.c
===================================================================
--- mgen/0.0.3/mgen_get_char_at.c (nonexistent)
+++ mgen/0.0.3/mgen_get_char_at.c (revision 266)
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+#include "mgen.h"
+
+MGEN_CHAR *
+mgen_get_char_at(MGEN_FILE *mf,size_t pos)
+{
+ MGEN_CHAR * mc;
+ size_t p = mf->ring.abspos;
+ if (!mgen_ring_seek(&mf->ring,pos-1))
+ return NULL;
+
+ mc = mgen_ring_getat(&mf->ring,MGEN_CHAR,mf->ring.pos);
+ (void)mgen_ring_seek(&mf->ring,p);
+ return mc;
+
+}
+
+
/mgen/0.0.3/mgen_get_char_at.c
Property changes:
Added: svn:mergeinfo
## -0,0 +0,2 ##
Merged /branches/mgen-tmp/mgen_get_char_at.c:r152-155
Merged /branches/bnf/bnf_cleanup/mgen_get_char_at.c:r123-126
Index: mgen/0.0.3/mgen_getc.c
===================================================================
--- mgen/0.0.3/mgen_getc.c (nonexistent)
+++ mgen/0.0.3/mgen_getc.c (revision 266)
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2019, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <stdio.h>
+#include "mgen.h"
+
+/**
+ * Function: mgen_getc
+ * -------------------
+ * Read one character from inputstream.
+ *
+ * mf: mgen_stream to read from
+ *
+ * returns: the next character from stream.
+ *
+ */
+int
+mgen_getc(struct mgen_stream * mf)
+{
+ int c;
+
+ if (mf->ring.abspos != mf->ring.absmaxpos){
+ if (!mgen_ring_alloc(&mf->ring))
+ return EOF;
+
+ c = ((MGEN_CHAR*)(mf->ring.buf))[mf->ring.pos].c;
+ (void)mgen_ring_next(&mf->ring);
+ }
+ else{
+ (void)mgen_ring_alloc(&mf->ring);
+ c = fgetc(mf->infile);
+ if (c==EOF)
+ return EOF;
+
+ ((MGEN_CHAR*)(mf->ring.buf))[mf->ring.pos].c=c;
+ ((MGEN_CHAR*)(mf->ring.buf))[mf->ring.pos].line=mf->line;
+ ((MGEN_CHAR*)(mf->ring.buf))[mf->ring.pos].col=mf->col;
+ (void)mgen_ring_next(&mf->ring);
+
+ /* count line number an column number */
+ switch(c) {
+ case '\n':
+ mf->line++;
+ mf->prev_col = mf->col;
+ mf->col=1;
+ break;
+ case '\t':
+ mf->col+=mf->tab_size;
+ break;
+ default:
+ mf->col++;
+ }
+
+ }
+
+ return c;
+}
+
Index: mgen/0.0.3/mgen_open.c
===================================================================
--- mgen/0.0.3/mgen_open.c (nonexistent)
+++ mgen/0.0.3/mgen_open.c (revision 266)
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mgen.h"
+
+static struct mgen_stream *
+mgen_stream_create()
+{
+ struct mgen_stream * mf;
+ mf = malloc(sizeof(struct mgen_stream));
+ if (!mf)
+ return NULL;
+
+ mgen_ring_init(&(mf->ring),sizeof(MGEN_CHAR));
+
+
+/* mf->buf = malloc(MGEN_BUF_BLOCK_SIZE);
+ if (!mf->buf){
+ free (mf);
+ return NULL;
+ }*/
+
+ mf->buf = NULL;
+ mf->bufmax = 0;
+ mf->buflast=0;
+ mf->buffirst=0;
+ mf->buf_size = MGEN_BUF_SIZE;
+ mf->block_size = MGEN_BUF_BLOCK_SIZE;
+
+ mf->line = 1;
+ mf->col=1;
+ mf->bufptr=0;
+ mf->filename = NULL;
+/* mf->eof=0;*/
+ return mf;
+}
+
+struct mgen_stream *
+mgen_open_stream(FILE *infile, const char *prgname)
+{
+ struct mgen_stream * mf;
+ mf = mgen_stream_create();
+ if (!mf){
+ return NULL;
+ }
+ mf->prgname = prgname;
+ mf->infile = infile;
+ return mf;
+}
+
+struct mgen_stream *
+mgen_open(const char *filename, const char *prgname)
+{
+ FILE * infile;
+ struct mgen_stream * mf;
+
+ infile = fopen(filename,"rt");
+ if (infile==NULL)
+ return NULL;
+
+
+ mf = mgen_open_stream(infile,prgname);
+/* mf = mgen_stream_create();*/
+ if (!mf){
+ (void)fclose(infile);
+ return NULL;
+ }
+
+/* mf->infile = infile;*/
+ return mf;
+}
+
Index: mgen/0.0.3/mgen_parse.c
===================================================================
--- mgen/0.0.3/mgen_parse.c (nonexistent)
+++ mgen/0.0.3/mgen_parse.c (revision 266)
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+
+struct status {
+ size_t fpos;
+ struct rhs_elem * e;
+ size_t sstackptr;
+ struct symstack_elem * next_se;
+};
+
+struct mgen_parser {
+ struct mavl * rules;
+ struct mgen_stream * mf;
+ struct symstack_elem * next_se;
+
+ MGEN_RING st;
+ MGEN_RING ss;
+};
+
+struct symstack_elem {
+ struct mgen_sym * sym;
+ struct symstack_elem * next;
+};
+
+
+static const char *
+mgen_format_bool(int b)
+{
+ return b ? "TRUE" : "FALSE";
+}
+
+
+static int
+check_string(struct mgen_stream *mf, char *str)
+{
+ int i,c;
+ i=0;
+ if (str==NULL){
+ int rc;
+ rc = mgen_getc(mf)==EOF;
+/* printf("IS_EOF?: %s\n",mgen_format_bool(rc)); */
+ return rc;
+ }
+
+ while (str[i] != 0){
+ c=mgen_getc(mf);
+/* printf("'%c' == '%c'?:",c,str[i]); */
+ if (c==str[i]){
+/* printf("TRUE\n");*/
+ i++;
+ continue;
+ }
+/* printf("FALSE\n"); */
+ return 0;
+ }
+ return 1;
+}
+
+static struct rhs_elem *
+get_rhs_list(struct mgen_parser * prs, char *rulename)
+{
+ struct mgen_rule *rule,rs;
+ rs.name = rulename;
+ rule = mavl_get(prs->rules,&rs);
+ if ( !rule ){
+ (void)printf("Fatal error rule not found %s\n",rulename);
+ return 0;
+ }
+
+ return rule->rhs_list;
+}
+
+void pushsym(struct mgen_parser * prs, struct mgen_sym * sym)
+{
+ size_t i;
+ struct symstack_elem *se;
+ i = prs->ss.pos;
+ (void)mgen_ring_alloc(&prs->ss);
+ se = &(((struct symstack_elem*)(prs->ss.buf))[i]);
+ (void)mgen_ring_next(&prs->ss);
+
+ se->next=prs->next_se;
+ se->sym = sym;
+ prs->next_se=se;
+/* printf("PUSH SSSTACK to %d\n",prs->ss.abspos);*/
+
+/* =sym->next;
+ (void)mgen_ring_next(&prs->ss);*/
+
+}
+
+
+static int
+run_rhs_list(struct mgen_parser *prs, struct rhs_elem * e)
+{
+ struct mgen_sym * sym;
+ struct status * st;
+ size_t i;
+
+ prs->next_se=NULL;
+
+loop0:
+ /* push curent status on ststack */
+ i = prs->st.pos;
+ (void)mgen_ring_alloc(&prs->st);
+ (void)mgen_ring_next(&prs->st);
+ st = (struct status*)(prs->st.buf);
+ st[i].fpos = mgen_tell(prs->mf);
+ st[i].e = e;
+ st[i].sstackptr=prs->ss.abspos;
+ st[i].next_se = prs->next_se;
+
+loop1:
+ if (!e) {
+
+ if (prs->st.abspos==1){
+ MGEN_CHAR *mc;
+
+ mgen_ring_seek(&prs->mf->ring,prs->mf->ring.absmaxpos);
+ mc = mgen_ring_getat(&prs->mf->ring,MGEN_CHAR,prs->mf->ring.pos);
+mc = mgen_get_char_at(prs->mf,prs->mf->ring.absmaxpos);
+printf("ABSMAX: %d\n",prs->mf->ring.absmaxpos);
+printf("Error at '%c', Line: %d, Col: %d\n",mc->c,mc->line,mc->col);
+
+ return 0;
+ }
+
+ /* pop status */
+ (void)mgen_ring_prev(&prs->st);
+ goto loop3;
+ }
+ sym=e->sym_list;
+
+loop2:
+
+ if (!sym) {
+ struct symstack_elem * se;
+ if (prs->next_se == NULL){
+ return 1;
+ }
+/* if (prs->ss.abspos==0){
+ return 1;
+
+ }*/
+/*
+printf("IT IS NOT NULL\n");
+exit(1);*/
+ se = prs->next_se;
+ prs->next_se=se->next;
+ sym = se->sym;
+
+
+ /* sym = popsym(prs); */
+/* (void)mgen_ring_prev(&prs->ss);
+ sym = ((struct mgen_sym**)(prs->ss.buf))[prs->ss.pos];*/
+ goto loop2;
+ }
+ switch( sym->type ){
+ case MGEN_T_SYM:
+/* printf("Terminal: \"%s\"\n",sym->name); */
+ if (check_string(prs->mf,sym->name)){
+
+ sym=sym->next;
+ goto loop2;
+ }
+loop3:
+ (void)mgen_ring_prev(&prs->st);
+ st = &(((struct status*)(prs->st.buf))[prs->st.pos]);
+ (void)mgen_ring_next(&prs->st);
+
+ e=st->e->next;
+ st->e=e;
+ (void)mgen_seek(prs->mf,st->fpos);
+ (void)mgen_ring_seek(&prs->ss,st->sstackptr);
+
+/* printf("SET SSSTACK to %d\n",prs->ss.abspos);*/
+
+ prs->next_se=st->next_se;
+
+ goto loop1;
+
+ case MGEN_NT_SYM:
+/* printf("Rule: <%s>\n",sym->name);*/
+ e = get_rhs_list(prs,sym->name);
+ /* pushsym(prs,sym->next); */
+ if (sym->next || 0){
+ pushsym(prs,sym->next);
+
+/* size_t i1;
+ i1 = prs->ss.pos;
+ (void)mgen_ring_alloc(&prs->ss);
+ ((struct mgen_sym**)(prs->ss.buf))[i1]=
+ sym->next;
+ (void)mgen_ring_next(&prs->ss);
+*/
+ }
+ goto loop0;
+ }
+
+ /* this should never happen */
+ return 0;
+}
+
+int
+mgen_parse(
+ struct mgen_stream *mf,
+ struct mgen_rule_set *rules,
+ const char * start)
+{
+ struct mgen_parser prs;
+ int rc;
+ struct rhs_elem * e;
+
+ prs.rules = rules->rules;
+ prs.mf = mf;
+
+ mgen_ring_init(&prs.st,sizeof(struct status));
+ mgen_ring_init(&prs.ss,sizeof(struct symstack_elem));
+
+ e = get_rhs_list(&prs,(char*)start);
+
+ rc = run_rhs_list(&prs,e);
+ return rc;
+}
/mgen/0.0.3/mgen_parse.c
Property changes:
Added: svn:mergeinfo
## -0,0 +0,5 ##
Merged /branches/bnf/mgen/mgen_parse.c:r129-228
Merged /branches/tmp-mgen-restored/mgen_parse.c:r235-236
Merged /branches/tmp-mgen/mgen_parse.c:r217-234
Merged /branches/bnf/bnf_cleanup/mgen_parse.c:r123-126
Merged /branches/mgen-tmp/mgen_parse.c:r152-155
Index: mgen/0.0.3/mgen_perror.c
===================================================================
--- mgen/0.0.3/mgen_perror.c (nonexistent)
+++ mgen/0.0.3/mgen_perror.c (revision 266)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "mgen.h"
+
+void
+mgen_perror(struct mgen_stream *mf, char *msg, ...)
+{
+ va_list argp;
+ va_start(argp, msg);
+
+ if (mf->filename){
+ (void)fprintf(stderr,"\"%s\",",mf->filename);
+ }
+
+ (void)fprintf(stderr, "line %d, col %d: error: ",
+ mf->line, mf->col);
+
+ (void)vfprintf(stderr,msg,argp);
+ (void)fprintf(stderr,"\n");
+ va_end(argp);
+}
Index: mgen/0.0.3/mgen_print_rhs_list.c
===================================================================
--- mgen/0.0.3/mgen_print_rhs_list.c (nonexistent)
+++ mgen/0.0.3/mgen_print_rhs_list.c (revision 266)
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+void
+print_rhs_list(struct rhs_elem *e)
+{
+ struct mgen_sym *sym;
+ char * delim_or, *delim_spc;
+ delim_or="";
+ while (e!=NULL){
+ sym = e->sym_list;
+ (void)printf("%s",delim_or);
+ delim_or="|";
+ delim_spc="";
+ while (sym!=NULL){
+ if (sym->type == MGEN_NT_SYM)
+ (void)printf("%s<%s>",delim_spc,sym->name);
+ else
+ (void)printf("%s%s",delim_spc,sym->name);
+ sym = sym->next;
+ delim_spc=" ";
+ }
+ e=e->next;
+ }
+}
+
+
Index: mgen/0.0.3/mgen_print_symlist.c
===================================================================
--- mgen/0.0.3/mgen_print_symlist.c (nonexistent)
+++ mgen/0.0.3/mgen_print_symlist.c (revision 266)
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+void
+print_symlist(struct mgen_sym * sym)
+{
+ char *delim_spc;
+ delim_spc="";
+ while (sym!=NULL){
+ if (sym->type == MGEN_NT_SYM)
+ (void)printf("%s<%s>",delim_spc,sym->name);
+ else
+ (void)printf("%s%s",delim_spc,sym->name);
+ sym = sym->next;
+ delim_spc=" ";
+ }
+}
+
Index: mgen/0.0.3/mgen_read_rule_set.c
===================================================================
--- mgen/0.0.3/mgen_read_rule_set.c (nonexistent)
+++ mgen/0.0.3/mgen_read_rule_set.c (revision 266)
@@ -0,0 +1,481 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+#include <string.h>
+#include <errno.h>
+
+#include "mgen.h"
+
+#define MAX_NONTERMINAL 1024
+#define MAX_TERMINAL 1024
+
+struct bnf0_prs {
+ struct mgen_rule * current_rule;
+ struct rhs_elem * current_rhs_elem;
+ struct mgen_sym ** current_sym;
+ MGEN_RULE_SET *rules;
+ int error;
+};
+
+static int
+skip_comment(struct mgen_stream * mf)
+{
+ int c;
+ do {
+ c=mgen_getc(mf);
+ }while (c!='\n' && c!=EOF);
+ return c;
+}
+
+static int
+get_non_terminal(struct bnf0_prs * prs,struct mgen_stream * mf, char * result)
+{
+ int c;
+ int i;
+
+ c=EOF; /* this eliminates a compiler warning
+ about c may be used unassigned */
+
+ for (i=0; i<MAX_NONTERMINAL; i++){
+ c = mgen_getc(mf);
+ if (c=='>')
+ break;
+ if (c=='\n' || c==EOF){
+ mgen_perror(mf,"missing '>' at end of non-terminal");
+ prs->error=1;
+ return EOF;
+ }
+ result[i]=(char)c;
+ }
+
+ if (i==MAX_NONTERMINAL && c!='>'){
+ mgen_perror(mf,"non-terminal symbol too long");
+ prs->error=1;
+ return EOF;
+ }
+ result[i]=0;
+
+ return c;
+}
+
+static int
+get_terminal(struct bnf0_prs * prs,struct mgen_stream * mf, char * result)
+{
+ int c;
+ int i;
+
+ c=EOF; /* this eliminates a compiler warning
+ about c may be used unassigned */
+
+ for (i=0; i<MAX_TERMINAL; i++){
+ c = mgen_getc(mf);
+ if (c==' ' || c=='\n' || c=='|' ||
+ c=='\t' || c=='\r' || c==EOF)
+ break;
+ result[i]=(char)c;
+ }
+
+ if (i==MAX_TERMINAL ){
+ mgen_perror(mf,"terminal symbol too long");
+ prs->error=1;
+ return EOF;
+ }
+ result[i]=0;
+ if (strcmp(result,"\\n")==0){
+ (void)strcpy(result,"\n");
+ }
+ if (strcmp(result,"\\s")==0){
+ (void)strcpy(result," ");
+ }
+ if (strcmp(result,"\\t")==0){
+ (void)strcpy(result,"\t");
+ }
+ if (strcmp(result,"\\r")==0){
+ (void)strcpy(result,"\r");
+ }
+
+
+
+ return c;
+}
+
+
+static struct rhs_elem *
+append_rhs_elem(struct rhs_elem ** next)
+{
+ while (*next!=NULL){
+ next = &((*next)->next);
+ }
+ *next = malloc(sizeof(struct rhs_elem));
+ if (!*next)
+ return NULL;
+
+ (*next)->sym_list=NULL;
+ (*next)->next=NULL;
+ return *next;
+}
+
+static struct mgen_sym *
+append_sym(struct mgen_sym ** next, int type, char *name)
+{
+ struct mgen_sym * sym;
+ sym = malloc( sizeof( struct mgen_sym));
+ if (!sym)
+ return NULL;
+
+ if (name == NULL){
+ sym->name=NULL;
+ sym->type=type;
+ *next = sym;
+ return sym;
+ }
+ sym->name = malloc( strlen(name)+1);
+ if (!sym->name){
+ free(sym);
+ return NULL;
+ }
+ (void)strcpy (sym->name,name);
+ sym->type=type;
+ sym->next=NULL;
+
+ *next = sym;
+ return sym;
+}
+
+MGEN_CHAR *
+mgen_get_char(MGEN_FILE *mf)
+{
+ MGEN_CHAR * mc;
+ if (!mgen_ring_prev(&mf->ring)){
+ return NULL;
+ }
+ mc = mgen_ring_getat(&mf->ring,MGEN_CHAR,mf->ring.pos);
+ (void)mgen_ring_next(&mf->ring);
+ return mc;
+}
+
+static int
+get_left_hand_side(struct mgen_stream * mf, struct bnf0_prs * prs)
+{
+ int c;
+ MGEN_CHAR *mc;
+
+ char result[MAX_NONTERMINAL+1];
+ struct mgen_rule rule;
+ int exists;
+
+ while(1) {
+
+ c = mgen_skip_spaces(mf);
+ if (c==EOF)
+ return EOF;
+
+ mc = mgen_get_char(mf);
+ if (c=='#' && mc->col==1){
+ c=skip_comment(mf);
+ (void)mgen_ungetc(c,mf);
+ continue;
+ }
+ break;
+ }
+
+
+ if (c != '<' ){
+ mgen_perror(mf,"'<' expected.");
+ prs->error=1;
+ return EOF;
+ }
+ mc = mgen_get_char(mf);
+ if (mc->col != 1){
+ mgen_perror(mf,
+ "left hand side of a rule has to start at column 1.");
+ prs->error=1;
+ return EOF;
+ }
+
+ c = get_non_terminal(prs,mf, result);
+ if (c==EOF)
+ return EOF;
+
+ rule.name = malloc(strlen(result)+1);
+ if (!rule.name){
+ mgen_perror(mf,"can't allocate memory.");
+ prs->error=1;
+ return EOF;
+ }
+ (void)strcpy(rule.name,result);
+ rule.line = mf->line;
+ rule.rhs_list = NULL;
+
+/* (void)printf("non-terminal found: %s\n",rule.name);*/
+
+ prs->current_rule =
+ mavl_insert(prs->rules->rules, &rule, &exists);
+
+ if (!prs->current_rule){
+ mgen_perror(mf,"can't allocate memory\n");
+ prs->error=1;
+ return EOF;
+ }
+
+ if (exists){
+ char msg[MAX_NONTERMINAL+256];
+ (void)sprintf(msg,"symbol <%s> is already defined.",result);
+ mgen_perror(mf,msg);
+ prs->error=1;
+ return EOF;
+ }
+
+ prs->current_rhs_elem =
+ append_rhs_elem(&(prs->current_rule->rhs_list));
+
+ if (!prs->current_rhs_elem)
+ return EOF;
+ prs->current_sym = &prs->current_rhs_elem->sym_list;
+ return 0;
+}
+
+static int
+get_right_hand_side(struct mgen_stream *mf, struct bnf0_prs *prs)
+{
+ int c;
+ MGEN_CHAR * mc;
+ struct mgen_sym * sym;
+
+ /* int nsyms;
+ * nsyms = 0;*/
+
+ do{
+ c = mgen_skip_spaces(mf);
+ switch (c) {
+ case '\\':{
+ int c1;
+ c1=mgen_getc(mf);
+ if (c1!='|'){
+ (void)mgen_ungetc(c1,mf);
+ goto l0;
+ }
+
+ sym=append_sym(
+ prs->current_sym,MGEN_T_SYM,"|"
+ );
+
+ if (!sym){
+ mgen_perror(mf,
+ "Can't allocate memory"
+ );
+ prs->error=1;
+ return EOF;
+ }
+ prs->current_sym = &sym->next;
+ break;
+ }
+
+
+ case '|':
+ prs->current_rhs_elem =
+ append_rhs_elem(
+ &(prs->current_rule->rhs_list)
+ );
+ if (!prs->current_rhs_elem)
+ return EOF;
+ prs->current_sym =
+ &prs->current_rhs_elem->sym_list;
+ break;
+
+ case '<': {
+ int c1;
+ char result[MAX_NONTERMINAL+1];
+
+ mc = mgen_get_char(mf);
+ if (mc->col <= 1){
+ (void)mgen_ungetc(c,mf);
+ return c;
+ }
+
+ c1 = mgen_getc(mf);
+ (void)mgen_ungetc(c1,mf);
+ if (!mgen_isspace(c1)) {
+ c = get_non_terminal(prs,mf,result);
+ if (c==EOF)
+ return EOF;
+
+ sym=append_sym(
+ prs->current_sym,
+ MGEN_NT_SYM,result
+ );
+
+ if (!sym) {
+ mgen_perror(mf,
+ "Can't allocate memory"
+ );
+ prs->error=1;
+ return EOF;
+ }
+
+ prs->current_sym = &sym->next;
+ break;
+ }
+ /* this goto statement prevents the
+ * compiler warning fall into default
+ * statement */
+ goto l0;
+ }
+l0:
+ default:{
+ char result[MAX_TERMINAL+1];
+ char *fr;
+ (void)mgen_ungetc(c,mf);
+ c=get_terminal(prs,mf,result);
+
+ if (strcmp(result,"\\eof")==0)
+ fr = NULL;
+ else
+ fr = result;
+
+
+ sym=append_sym(
+ prs->current_sym,MGEN_T_SYM,fr
+ );
+
+ if (!sym){
+ mgen_perror(mf,
+ "Can't allocate memory"
+ );
+ prs->error=1;
+ return EOF;
+ }
+ (void)mgen_ungetc(c,mf);
+ prs->current_sym = &sym->next;
+ }
+ }
+
+ }while (c!=EOF);
+ return EOF;
+}
+
+static int
+get_assignment (struct bnf0_prs * prs,struct mgen_stream * mf)
+{
+ int c,i,n;
+ char * search = "::=";
+
+ c = mgen_skip_spaces(mf);
+
+ i=0; n=(int)strlen(search);
+ do {
+ if (c!=search[i]){
+ mgen_perror(mf,"'::=' expected.");
+ prs->error=1;
+ return EOF;
+ }
+ i++;
+ c=mgen_getc(mf);
+ }while(i<n);
+ return c;
+}
+
+static void
+verify(struct bnf0_prs * prs)
+{
+ struct mavl *t;
+ struct mavliter it;
+ void *data;
+ struct mgen_stream mf;
+
+ t = prs->rules->rules;
+
+ mavliter_init(&it, t);
+ (void)mavliter_seek_set(&it);
+ while ((data = mavliter_get(&it)) != NULL) {
+ struct mgen_rule * rule = (struct mgen_rule *)data;
+ struct rhs_elem *e;
+ struct mgen_sym *sym;
+
+ e = rule->rhs_list;
+ while (e!=NULL){
+ sym = e->sym_list;
+ while (sym!=NULL){
+ if (sym->type == MGEN_NT_SYM){
+ void * r;
+ struct mgen_rule trule;
+ trule.name = sym->name;
+ r = mavl_get(t,&trule);
+ if (!r){
+ char msg[MAX_NONTERMINAL+256];
+ (void)sprintf(msg,"unedfined non-terminal: <%s>",sym->name);
+ mf.line = rule->line;
+ mf.col = 0;
+ mf.filename=NULL;
+ prs->error=1;
+ mgen_perror(&mf,msg);
+ return;
+ }
+ /* (void)printf("%s<%s>",delim_spc,sym->name);*/
+ }
+ sym = sym->next;
+ }
+ e=e->next;
+ }
+ (void)mavliter_next(&it);
+ }
+}
+
+
+
+struct mgen_rule_set * mgen_read_rule_set( struct mgen_stream *mf)
+{
+ struct bnf0_prs prs;
+ /*struct mgen_rule_set * rules;*/
+ int c;
+
+ prs.error=0;
+
+ prs.rules = mgen_create_rule_set();
+ if (!prs.rules){
+ mgen_perror(mf,"can't allocate memory");
+ return NULL;
+ }
+
+ do {
+ c = get_left_hand_side(mf,&prs);
+ if (c==EOF)
+ break;
+ c = get_assignment(&prs,mf);
+ if (c==EOF)
+ break;
+ c = get_right_hand_side(mf,&prs);
+
+ }while(c!=EOF);
+printf("now verify\n");
+ verify(&prs);
+printf("verify done\n");
+
+ if (prs.error){
+ return NULL;
+ }
+ return prs.rules;
+}
/mgen/0.0.3/mgen_read_rule_set.c
Property changes:
Added: svn:mergeinfo
## -0,0 +0,4 ##
Merged /branches/bnf/mgen/mgen_read_rule_set.c:r129-228
Merged /branches/bnf/bnf_cleanup/mgen_read_rule_set.c:r123-126
Merged /branches/tmp-mgen/mgen_read_rule_set.c:r217-222
Merged /branches/mgen-tmp/mgen_read_rule_set.c:r152-155
Index: mgen/0.0.3/mgen_ring_alloc.c
===================================================================
--- mgen/0.0.3/mgen_ring_alloc.c (nonexistent)
+++ mgen/0.0.3/mgen_ring_alloc.c (revision 266)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+int
+mgen_ring_alloc(MGEN_RING *ring)
+{
+ if(ring->buf_size == ring->bufmax_size){
+ return 1;
+ }
+
+ if (ring->pos==ring->buf_size){
+ size_t s;
+ void * newbuf;
+
+ s=ring->buf_size+ring->block_size;
+ if ( s>ring->bufmax_size && ring->bufmax_size!=0) {
+ s = ring->bufmax_size;
+ }
+
+ newbuf = realloc(ring->buf,s*ring->elem_size);
+ if (!newbuf)
+ return 0;
+ ring->buf = newbuf;
+ ring->buf_size=s;
+ return 1;
+ }
+
+ return 1;
+}
+
+
Index: mgen/0.0.3/mgen_ring_init.c
===================================================================
--- mgen/0.0.3/mgen_ring_init.c (nonexistent)
+++ mgen/0.0.3/mgen_ring_init.c (revision 266)
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+void
+mgen_ring_init(struct mgen_ring *m, size_t elem_size)
+{
+ m->buf=NULL;
+ m->pos=0;
+ m->maxpos=0;
+ m->abspos=0;
+ m->absmaxpos=0;
+
+ m->block_size=MGEN_BUF_BLOCK_SIZE;
+ m->bufmax_size=MGEN_BUF_SIZE;
+ m->buf_size=0;
+ m->elem_size=elem_size;
+}
+
+
+
Index: mgen/0.0.3/mgen_ring_next.c
===================================================================
--- mgen/0.0.3/mgen_ring_next.c (nonexistent)
+++ mgen/0.0.3/mgen_ring_next.c (revision 266)
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+size_t
+mgen_ring_next(struct mgen_ring *m)
+{
+ m->pos++;
+
+ if (m->pos == m->bufmax_size && m->bufmax_size!=0){
+ m->pos=0;
+ }
+ m->abspos++;
+ if (m->abspos > m->absmaxpos){
+ m->absmaxpos = m->abspos;
+ m->maxpos=m->pos;
+ }
+ return m->pos;
+}
+
Index: mgen/0.0.3/mgen_ring_prev.c
===================================================================
--- mgen/0.0.3/mgen_ring_prev.c (nonexistent)
+++ mgen/0.0.3/mgen_ring_prev.c (revision 266)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+#include "mgen.h"
+
+int
+mgen_ring_prev(struct mgen_ring *m)
+{
+ if ( (m->buf_size!=m->bufmax_size) || (m->bufmax_size==0) ){
+ if (m->abspos>0){
+ m->pos--;
+ m->abspos--;
+ return 1;
+ }
+ return 0;
+ }
+
+/* printf("%d >= %d\n",m->absmaxpos - m->abspos,m->bufmax_size);*/
+ if ((m->absmaxpos - m->abspos) >= m->bufmax_size){
+/* printf("ERRR!\n");*/
+ return 0;
+ }
+
+ if(m->pos==0){
+ m->pos = m->bufmax_size-1;
+ m->abspos--;
+ return 1;
+ }
+
+ m->pos--;
+ m->abspos--;
+ return 1;
+
+}
+
+
Index: mgen/0.0.3/mgen_ring_seek.c
===================================================================
--- mgen/0.0.3/mgen_ring_seek.c (nonexistent)
+++ mgen/0.0.3/mgen_ring_seek.c (revision 266)
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include "mgen.h"
+
+int
+mgen_ring_seek(MGEN_RING * ring, size_t pos)
+{
+ if (ring->buf_size == ring->bufmax_size ){
+ size_t diff;
+
+ diff = ring->absmaxpos-pos;
+ if (diff > ring->buf_size)
+ return 0;
+
+/* npos = ring->maxpos - diff;*/
+
+ if ( ring->maxpos > diff ){
+ ring->pos = ring->maxpos -diff;
+ }
+ else{
+ ring->pos = ring->bufmax_size - (diff-ring->maxpos);
+ }
+
+ if (ring->pos == ring->bufmax_size)
+ ring->pos=0;
+
+ ring->abspos = pos;
+ return 1;
+ }
+ if (pos<0)
+ return 0;
+ ring->pos = pos;
+ ring->abspos = pos;
+ return 1;
+}
+
+
Index: mgen/0.0.3/mgen_ungetc.c
===================================================================
--- mgen/0.0.3/mgen_ungetc.c (nonexistent)
+++ mgen/0.0.3/mgen_ungetc.c (revision 266)
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2019,2020, The PLANIX Project
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <stdio.h>
+#include "mgen.h"
+
+int
+mgen_ungetc(int c, MGEN_FILE *mf)
+{
+ if (!mf->ring.buf)
+ return EOF;
+
+ if (!mgen_ring_prev(&mf->ring))
+ return EOF;
+
+ ((MGEN_CHAR*)mf->ring.buf)[mf->ring.pos].c=c;
+/*
+ switch(c) {
+ case '\n':
+ mf->line--;
+ mf->col=mf->prev_col;
+ break;
+ case '\t':
+ mf->col-=8;
+ break;
+ default:
+ mf->col--;
+ }
+*/ return c;
+}
+/*
+void
+mgen_ungetc(int c, struct mgen_stream *mf)
+{
+ mf->bufptr--;
+ mf->buf[mf->bufptr]=(char)c;
+ mf->eof=0;
+
+ switch(c) {
+ case '\n':
+ mf->line--;
+ mf->col=mf->prev_col;
+ break;
+ case '\t':
+ mf->col-=8;
+ break;
+ default:
+ mf->col--;
+ }
+}
+
+*/
Index: mgen/0.0.3/mipascal.bnf
===================================================================
--- mgen/0.0.3/mipascal.bnf (nonexistent)
+++ mgen/0.0.3/mipascal.bnf (revision 266)
@@ -0,0 +1,13 @@
+#
+# mini pascal
+#
+
+<Programm> ::= PROGRAM <Bezeichner> BEGIN <Satzfolge> END .
+<Bezeichner> ::= <Buchstabe> <Restbezeichner>
+<Restbezeichner> ::= | <Buchstabe oder Ziffer> <Restbezeichner>
+<Buchstabe oder Ziffer> ::= <Buchstabe> | <Ziffer>
+<Grossbuchstabe> ::= A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z
+<Kleinbuchstabe> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z
+<Buchstabe> ::= <Grossbuchstabe> | <Kleinbuchstabe>
+<Ziffer> ::= 0|1|2|3|4|5|6|7|8|9
+<Satzfolge> ::= ...
Index: mgen/0.0.3/my.prg
===================================================================
--- mgen/0.0.3/my.prg (nonexistent)
+++ mgen/0.0.3/my.prg (revision 266)
@@ -0,0 +1 @@
+abc
Index: mgen/0.0.3/x.bnf
===================================================================
--- mgen/0.0.3/x.bnf (nonexistent)
+++ mgen/0.0.3/x.bnf (revision 266)
@@ -0,0 +1,7 @@
+<Programm> ::= <syntax>
+<syntax> ::= <rule> EOF | <rule> <syntax> a
+<rule> ::= <opt-whitespace> x <line-end>
+<opt-whitespace> ::= S <opt-whitespace> |
+<line-end> ::= <opt-whitespace> N | <opt-whitespace> <EOL> <line-end>
+<EOL> ::= N
+<Nudel> ::= abc
Index: mgen/0.0.3
===================================================================
--- mgen/0.0.3 (nonexistent)
+++ mgen/0.0.3 (revision 266)
/mgen/0.0.3
Property changes:
Added: svn:mergeinfo
## -0,0 +0,3 ##
Merged /branches/bnf/bnf_cleanup:r123-126
Merged /branches/mgen-tmp:r152-155
Merged /branches/bnf/mgen:r129-228