Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlei committed Jun 21, 2018
2 parents 9c0f9a9 + fe7098f commit 3505f96
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 903 deletions.
57 changes: 43 additions & 14 deletions SMOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ b. A quote, immediately following any of: (1) an alphanumeric
Keyword ``end`` -- expression and statement
-------------------------------------------

Any of: ``endwhile``, etc. are ``END_STMT``. Otherwise,
if ``end`` appears inside parentheses of any kind,
it's ``END_EXPR``. Otherwise, ``end`` is illegal.
Any of: ``endwhile``, etc. are ``END_STMT``. Otherwise, lonely ``end``
is a keyword ``END_EXPR``. It is not allowed to be used as a variable,
except if appears inside subscripts, in which case it keeps the upper
bound of the corresponding dimension. It is frequently used with
the auto-expanding array idiom::

a(end+1) = b

Optional ``end`` statement as function terminator
-------------------------------------------------
Expand Down Expand Up @@ -137,26 +141,26 @@ if it was ``[1,2,3]``. Handle with care: ``[x + y]`` vs ``[x +y]``

Term T is::

#. a name or a number
#. literal string enclosed in single or double quotes
#. (T) or [T] or {T} or T' or +T or -T
1. a name or a number
2. literal string enclosed in single or double quotes
3. (T) or [T] or {T} or T' or +T or -T

Terms end with::

#. an alphanumeric charater \w
#. single quote (in octave also double-quote)
#. right parenthesis, bracket, or brace
#. a dot (after a number, such as 3.
1. an alphanumeric charater \w
2. single quote (in octave also double-quote)
3. right parenthesis, bracket, or brace
4. a dot (after a number, such as 3.

The pattern for whitespace accounts for ellipsis as a whitespace, and
for the trailing junk.

Terms start with::

#. an alphanumeric character
#. a single or double quote,
#. left paren, bracket, or brace and finally
#. a dot before a digit, such as .3 .
1. an alphanumeric character
2. a single or double quote,
3. left paren, bracket, or brace and finally
4. a dot before a digit, such as .3 .

TODO: what about curly brackets ???
TODO: what about dot followed by a letter, as in field
Expand Down Expand Up @@ -499,4 +503,29 @@ instance).

----------------------------------------------------------------------


Git hacks
---------
::

git difftool --tool <tool>

where ``tool`` is ``meld`` or ``kdiff3``

Vim hacks
---------
::

http://learnvimscriptthehardway.stevelosh.com
https://www.ibm.com/developerworks/library/l-vim-script-1/index.html
https://devhints.io/vimscript
http://andrewscala.com/vimscript/

Pdf hacks
---------
::

https://www.geeksforgeeks.org/working-with-pdf-files-in-python/

.. vim: tw=70:sw=2
4 changes: 4 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from smop.main import main

if __name__ == "__main__":
main()
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from setuptools import setup

#from smop.version import __version__ as __VERSION__
from smop.version import __version__ as __VERSION__

try:
__VERSION__ = os.popen("git describe --tags").read().strip()
except OSError as e:
__VERSION__ = "''"

open("smop/version.py","w").write("__version__='%s'" % __VERSION__)
#try:
# __VERSION__ = os.popen("git describe --tags").read().strip()
#except OSError as e:
# __VERSION__ = ""
#
#open("smop/version.py","w").write("__version__='%s'" % __VERSION__)

setup(
author = 'Victor Leikehman',
Expand Down
19 changes: 13 additions & 6 deletions smop/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ COVERAGE = python3 -m coverage
CYTHON = cython
PYTHON = python$V
XFILES = -x inputParser.m,dblquad.m,triplequad.m

SMOP = smop
SRCSMOP = main.py parse.py backend.py resolve.py options.py
FLAGS =
MYFLAGS=
PYTEST = python -m pytest

#V = 2.7
V = 3

all:
make -B FLAGS= liboctave.py
all: solver.py
$(PYTEST) test_matlabarray.py
$(PYTEST) test_parse.py
$(PYTEST) test_lexer.py
$(PYTEST) test_solver.py
#$(PYTEST) test_primes.py

#make -B FLAGS= liboctave.py
#$(COVERAGE) run -p main.py solver.m
#$(COVERAGE) combine
foo:
make -B FLAGS=-C liboctave.py
make -B FLAGS=-N liboctave.py
Expand All @@ -37,7 +45,7 @@ liboctave.py:
#$(PYTHON) $@

clean:
rm -f a.* *.pyc solver.so solver.py octave.so
rm -f a.* *.pyc solver.so solver.py octave.so *.py,cover

regress:
make | sort -u | wc
Expand All @@ -48,8 +56,7 @@ regress:
gcc -Wno-cpp -I /usr/include/python$V -O2 -shared -o $@ $^

%.py: %.m
$(PYTHON) main.py -o $@ $^
#$(PYTHON) $@
$(SMOP) $^

%.pdf: %.dot
dot -Tpdf -o $@ $^
Expand Down
5 changes: 1 addition & 4 deletions smop/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def print_header(fp):
if options.no_header:
return
print("# Running Python %s" % sys.version, file=fp)
#print("# Running Python %s" % sys.version, file=fp)
print("# Generated with SMOP ", version.__version__, file=fp)
print("from libsmop import *", file=fp)
print("#", options.filename, file=fp)
Expand Down Expand Up @@ -84,6 +84,3 @@ def main():
pass
if nerrors:
print("Errors:", nerrors)

if __name__ == "__main__":
main()
30 changes: 6 additions & 24 deletions smop/graphviz.py → smop/mygraphviz.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import parse,sys
import node
from node import extend
import sys
import pickle
import networkx as nx



def resolve(t,fp,func_name):
fp.write("digraph %s {\n" % func_name)
fp.write('graph [rankdir="LR"];\n')
for u in node.postorder(t):
if u.__class__ in (node.ident,node.param):
fp.write("%s [label=%s_%s_%s];\n" % (u.lexpos,u.name,u.lineno,u.column))
if u.defs:
for v in u.defs:
fp.write("%s -> %s" % (u.lexpos,v.lexpos))
if u.lexpos < v.lexpos:
fp.write('[color=red]')
#else:
# fp.write('[label=%s.%s]' % (v.lineno,v.column))
fp.write(';\n')
fp.write("}\n")

from . import node
from . import resolve
from . node import extend

@extend(node.node)
def _graphviz(self,fp):
if getattr(self,"__slots__",False):
Expand Down Expand Up @@ -58,6 +43,3 @@ def graphviz(tree,fp):
for u in node.postorder(tree):
u._graphviz(fp)
fp.write("}\n")

if __name__ == '__main__':
main()
Loading

0 comments on commit 3505f96

Please sign in to comment.