Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ build/
src/pyrex/bison_.c
src/pyrex/bison_.h

bison.egg-info
src/bison_.cpython-35m-x86_64-linux-gnu.so
examples/java/javaparser.py
dist/
*.so
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
.PHONY: all module install clean develop java_test

PYTHON=python

JAVAS=javaparser.y javaparser.l

all: module

module:
python2 setup.py build
$(PYTHON) setup.py build

install:
python2 setup.py install
$(PYTHON) setup.py install

clean:
$(PYTHON) setup.py clean
rm -rf *~ *.output tokens.h *.tab.* *.yy.c java-grammar new.* *.o *.so dummy build *.pxi *-lexer.c
rm -rf *-parser.y *-parser.c *-parser.h pybison.c pybison.h
rm -rf bison.c bison.h
rm -rf *.pyc
rm -rf tmp.*
rm -f src/pyrex/bison_.pxi src/pyrex/bison_.c src/pyrex/bison_.h
#rm -rf *.cpython-*.so

develop:
$(PYTHON) setup.py develop


java_test: develop
cd examples/java && bison2py $(JAVAS) javaparser.py && $(PYTHON) run.py

5 changes: 3 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from src.python.node import BisonNode
from src.python.bison import BisonParser, BisonSyntaxError
from __future__ import absolute_import
from .src.python.node import BisonNode
from .src.python.bison import BisonParser, BisonSyntaxError

__all__ = ['BisonNode', 'BisonParser', 'BisonSyntaxError']
9 changes: 6 additions & 3 deletions doc/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"""
A simple pybison parser program implementing a calculator
"""
from __future__ import absolute_import
from __future__ import print_function
from bison import BisonParser
from six.moves import input


class Parser(BisonParser):
Expand Down Expand Up @@ -33,7 +36,7 @@ class Parser(BisonParser):
# ------------------------------------------------------------------
def read(self, nbytes):
try:
return raw_input("> ") + "\n"
return input("> ") + "\n"
except EOFError:
return ''

Expand Down Expand Up @@ -63,7 +66,7 @@ def on_line(self, target, option, names, values):
| exp NEWLINE
"""
if option == 1:
print values[0]
print(values[0])

def on_exp(self, target, option, names, values):
"""
Expand Down Expand Up @@ -109,7 +112,7 @@ def on_exp(self, target, option, names, values):
extern void (*py_input)(PyObject *parser, char *buf, int *result,
int max_size);
#define returntoken(tok) \
yylval = PyString_FromString(strdup(yytext)); return (tok);
yylval = PyUnicode_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) { \
(*py_input)(py_parser, buf, &result, max_size); \
}
Expand Down
12 changes: 6 additions & 6 deletions doc/walkthrough.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ <h3>1.3. Preparing Your Tokeniser File</h3>
#include "tokens.h"
extern void *py_parser;
extern void (*py_input)(PyObject *parser, char *buf, int *result, int max_size);
#define returntoken(tok) yylval = PyString_FromString(strdup(yytext)); return (tok);
#define returntoken(tok) yylval = PyUnicode_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) {(*py_input)(py_parser, buf, &result, max_size);}
}%</pre></b>

Expand Down Expand Up @@ -257,7 +257,7 @@ <h3>1.3. Preparing Your Tokeniser File</h3>
</blockquote>

<b><pre>
#define returntoken(tok) yylval = PyString_FromString(strdup(yytext)); return (tok);</pre></b>
#define returntoken(tok) yylval = PyUnicode_FromString(strdup(yytext)); return (tok);</pre></b>

A macro which wraps all tokens values as Python strings, so your parser target handlers can uplift
the original input text which constitutes that token.
Expand Down Expand Up @@ -685,15 +685,15 @@ <h3>2.8. Add Flex Script</h3>

<b><pre>
%{
int yylineno = 0;
int yylineno = 0; // Remove if engine fails to build.
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include "Python.h"
#define YYSTYPE void *
#include "tokens.h"
extern void *py_parser;
extern void (*py_input)(PyObject *parser, char *buf, int *result, int max_size);
#define returntoken(tok) yylval = PyString_FromString(strdup(yytext)); return (tok);
#define returntoken(tok) yylval = PyUnicode_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) { (*py_input)(py_parser, buf, &result, max_size); }
%}
</pre></b>
Expand Down Expand Up @@ -770,15 +770,15 @@ <h3>2.8. Add Flex Script</h3>

lexscript = r"""
%{
int yylineno = 0;
int yylineno = 0; // Remove if engine fails to build.
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include "Python.h"
#define YYSTYPE void *
#include "tokens.h"
extern void *py_parser;
extern void (*py_input)(PyObject *parser, char *buf, int *result, int max_size);
#define returntoken(tok) yylval = PyString_FromString(strdup(yytext)); return (tok);
#define returntoken(tok) yylval = PyUnicode_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) { (*py_input)(py_parser, buf, &result, max_size); }
%}

Expand Down
4 changes: 2 additions & 2 deletions examples/C/c.l
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ IS (u|U|l|L)*
/* this scanner sourced from: http://www.lysator.liu.se/c/ANSI-C-grammar-l.html */

void count();
int yylineno = 0;
//int yylineno = 0;
#include <stdio.h>
#include <string.h>
#include "Python.h"
#define YYSTYPE void *
#include "tokens.h"
extern void *py_parser;
extern void (*py_input)(PyObject *parser, char *buf, int *result, int max_size);
#define returntoken(tok) /*printf("%d=%s\n", tok, yytext);*/ yylval = PyString_FromString(strdup(yytext)); return (tok);
#define returntoken(tok) /*printf("%d=%s\n", tok, yytext);*/ yylval = PyUnicode_FromString(strdup(yytext)); return (tok);
#define YY_INPUT(buf,result,max_size) { (*py_input)(py_parser, buf, &result, max_size); }

%}
Expand Down
Loading