Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: scooby/lolcode
base: b7cc307b4c
...
head fork: scooby/lolcode
compare: d5c5def814
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
3  .gitignore
@@ -1,2 +1,3 @@
*.pyc
-*~
+*~
+tests/a.out
View
19 CodeObjects.py
@@ -14,6 +14,13 @@
# 'main' function and a few other functions.
# I can then link that to a C based skeleton.
+class File(object):
+ """ Stores the whole shebang. """
+ def __init__(self, version, block, **kw):
+ super(File, self).__init__(**kw)
+ self.version = version
+ self.block = block
+
class GenC(object):
""" Mixin class to represent something that can generate C.
This just double checks that the overrides return
@@ -25,6 +32,7 @@ def genC(self):
assert isinstance(v, tuple)
assert all(isinstance(x, (str, tuple)) for x in v)
return v
+
class Scope(object):
def __init__(self, **kw):
super(Scope, self).__init__(**kw)
@@ -37,7 +45,7 @@ def declare(self, var):
self.declarations[var.name] = var
def genVar(self):
self.counter += 1
- return "__gen_" + str(self.counter)
+ return "gen_" + str(self.counter)
class Declaration(GenC, Stmnt):
def __init__(self, var, typ):
assert isinstance(var, VarName) and isinstance(typ, LangType)
@@ -45,9 +53,12 @@ def __init__(self, var, typ):
self.typ = typ
def _genC(self):
return (self.typ.genC(), self.var.genC(), ";")
-class Function(Scope):
- def __init__(self, **kw):
- pass
+class Function(Scope, GenC):
+ def __init__(self, name, args, ret, body, **kw):
+ self.name=name
+ self.args=args
+ self.ret=ret
+ self.body=body
class Block(object):
def __init__(self, **kw):
super(Block, self).__init__(**kw)
View
25 LolGrammer.py
@@ -8,7 +8,8 @@ def build(r):
kw = ident('[A-Z]+')
punc = Token(Any('()?!,.'))
inttok = Token(Integer())
- strtok = Token(Literal('"') + ((Literal(':') + Any(')>o":')) | Regexp('[^:"]'))[0:] + Literal('"'))
+ strtok = Token(Literal('"') + ((Literal(':') + Any(')>o":'))
+ | Regexp('[^:"]'))[0:] + Literal('"'))
#strtok = Token('"[^"]*"')
nltok = Token(Newline())
# End of line comments are parsed as a token
@@ -59,8 +60,9 @@ def build(r):
AtomTypes = (~k.NOOBS >> r.voidT) | (~k.TROOFS >> r.boolT) | \
(~k.NUMBARS >> r.intT) | (~k.YARNS >> r.strT)
Bukkity = ((k.VERAH | k.BIG)[0:] & ~k.BUKKIT) > r.bigness
- ComplexType = ((Bukkity & ~k.UF & AtomTypes > r.setT) | (Bukkity & ~k.LISTIN &
- AtomTypes > r.listT) | (Bukkity & ~k.NAMIN & AtomTypes > r.mapT))
+ ComplexType = ((Bukkity & ~k.UF & AtomTypes > r.setT) |
+ (Bukkity & ~k.LISTIN & AtomTypes > r.listT) |
+ (Bukkity & ~k.NAMIN & AtomTypes > r.mapT))
Type = AtomType | ComplexType
LiteralTroof = (~k.FAIL >> r.boolFalse) | (~k.WIN >> r.boolTrue)
@@ -147,8 +149,10 @@ def build(r):
| (~k.INVISIBLE & Expr[1:] & ~BANG > r.debugLnSt) \
| (~k.INVISIBLEZ & Expr[1:] > r.debugLnSt)
- CondBlock = ((((~k.YA & ~k.RLY) >> r.posCon) | ((~k.MEBBE & Expr) >> r.exprCon)
- | ((~k.NO & ~k.WAI) >> r.negCon)) & ~C & Block) >> r.condBlock
+ CondBlock = ((((~k.YA & ~k.RLY) >> r.posCon) |
+ ((~k.MEBBE & Expr) >> r.exprCon)
+ | ((~k.NO & ~k.WAI) >> r.negCon))
+ & ~C & Block) >> r.condBlock
ConditionStatement = (Expr & ~C & ~k.O & ~k.RLY & ~QMARK[0:1] & ~C &
CondBlock[1:] & ~k.OIC) >> r.condSt
@@ -164,7 +168,8 @@ def build(r):
CounterDir = ((~k.UPPIN >> r.ctrInc) | (~k.NERFIN >> r.ctrDec)) \
& ~k.YR & Variable >> r.ctrDir
CounterHead = CounterDir[0:1] & TermClause[0:1] >> r.ctrHead
- CounterStatement = LoopOpen & CounterHead & ~C & Block & LoopClose >> r.ctrSt
+ CounterStatement = LoopOpen & CounterHead & ~C & Block & LoopClose \
+ >> r.ctrSt
IterVars = (~k.STEALIN & Variable & (~k.N & Variable)[0:1]) \
>> r.iterVars
@@ -179,7 +184,8 @@ def build(r):
Arg = ~k.YR & Type[0:1] & Variable > r.arg
ArgList = (Arg & (~k.N & Arg)[0:])[0:1] > r.args
ReturnClause = ~k.AN & ~k.FIND & ~k.MA & Type >> r.returnType
- FuncHead = ~k.HOW & ~k.DUZ & ~k.I & FuncName & ArgList & ReturnClause & ~QMARK[0:1]
+ FuncHead = ~k.HOW & ~k.DUZ & ~k.I & FuncName & ArgList & \
+ ReturnClause & ~QMARK[0:1]
FuncClose = ~k.IF & ~k.U & ~k.SAY & ~k.SO
FuncDef = FuncHead & ~C & Block & FuncClose > r.funcDef
@@ -193,11 +199,11 @@ def build(r):
Block += ((SimpleStatement | ControlStatement) & ~C)[1:] > r.block
TopBlock = ((SimpleStatement | FuncDef) & ~C)[1:] > r.block
- VersionNumber = (inttok + DOT)[0:] + inttok
+ VersionNumber = (inttok + ~DOT)[0:] + inttok
FileHeader = ~k.OH[0:1] & ~k.HAI & VersionNumber[0:1] & ~C > r.fileHeader
FileCloser = ~k.KTHXBYE[0:1]
- matcher = FileHeader & TopBlock & FileCloser > r.file
+ matcher = FileHeader & TopBlock & FileCloser >> r.fileAll
matcher.config.default()
return matcher
@@ -214,4 +220,3 @@ def build(r):
s = ''.join(fh)
p = m(s)
print repr(p)
-
View
8 Responder.py
@@ -180,4 +180,10 @@ def args(s, ax):
def returnType(s, t):
return t
def funcDef(s, nm, ax, t, b):
- return co.
+ return co.Function(name=nm, args=ax, ret=t, body=b)
+ def block(s, ax):
+ return co.Block(ax)
+ def fileHeader(s, numbers):
+ return { 'version': numbers }
+ def fileAll(s, v, b):
+ return co.File(v, b)
View
13 tests/str.cpp
@@ -0,0 +1,13 @@
+#include <string>
+#include <sstream>
+#include <iostream>
+
+using namespace std;
+
+int main(char** argv, int argc) {
+ string x("52string");
+ int i = 0;
+ istringstream iss(x, istringstream::in);
+ iss >> i;
+ cout << "I got an int with " << i << ".";
+}

No commit comments for this range

Something went wrong with that request. Please try again.