Commit 689cc475 authored by Sarah Spall's avatar Sarah Spall Committed by Vikram Narayanan

removing generated files

parent 1e895737
......@@ -20,4 +20,5 @@ flounder_parser.h:
vembyr-1.1/peg.py --h flounder > flounder_parser.h
clean:
rm flounder_parser.* *.o compiler
\ No newline at end of file
rm flounder_parser.* *.o compiler vembyr-1.1/peg_peg.py
vembyr-1.1/peg_peg.pyc
\ No newline at end of file
start-symbol: start
options: debug0
module: Mugen.Air
include: {{
#include "mugen/ast/all.h"
#include <map>
#include "gc.h"
typedef std::list<Ast::Section*> SectionList;
}}
code: {{
template<class X>
X as(const Value & value){
return (X) value.getValue();
}
std::string * toString(const Value & input){
std::ostringstream out;
for (Value::iterator it = input.getValues().begin(); it != input.getValues().end(); it++){
out << (char) (long) (*it).getValue();
}
std::string * object = new std::string(out.str());
GC::save(object);
return object;
}
Ast::String * makeString(std::string * str){
/* FIXME: fix line numbers here */
Ast::String * object = new Ast::String(-1, -1, str);
GC::save(object);
return object;
}
Ast::String * makeString(const Value & value){
/* FIXME: fix line numbers here */
Ast::String * object = new Ast::String(-1, -1, toString(value));
GC::save(object);
return object;
}
Ast::Section * makeSection(const Value & str){
Ast::Section * object = new Ast::Section(as<std::string*>(str));
GC::save(object);
return object;
}
Ast::Keyword * makeKeyword(const Value & value){
/* FIXME: fix line numbers here */
Ast::Keyword * object = new Ast::Keyword(-1, -1, as<char*>(value));
GC::save(object);
return object;
}
Ast::Value * makeValueList(const Value & n1, const Value & n2, const Value & n3, const Value & n4){
std::list<Ast::Value*> values;
values.push_back(as<Ast::Value*>(n1));
values.push_back(as<Ast::Value*>(n2));
values.push_back(as<Ast::Value*>(n3));
values.push_back(as<Ast::Value*>(n4));
Ast::ValueList * object = new Ast::ValueList(values);
GC::save(object);
return object;
}
Ast::Value * makeValueList(const Value & front, const Value & rest){
std::list<Ast::Value*> values;
values.push_back(as<Ast::Value*>(front));
for (Value::iterator it = rest.getValues().begin(); it != rest.getValues().end(); it++){
Ast::Value * value = as<Ast::Value*>(Value((*it).getValue()));
if (value == 0){
/* FIXME! replace empty with a new node */
value = makeKeyword(Value("empty"));
values.push_back(value);
} else {
values.push_back(value);
}
}
Ast::ValueList * object = new Ast::ValueList(values);
GC::save(object);
return object;
}
Ast::Value * makeNumber(const Value & sign, const Value & number){
double value = *(as<double*>(number));
if (sign.getValue() != 0 && strcmp(as<const char *>(sign), "-") == 0){
value = -value;
}
/* FIXME! replace empty with a new node */
Ast::Number * object = new Ast::Number(-1, -1, value);
GC::save(object);
return object;
}
double * parseDouble(const Value & value){
std::string * str = toString(value);
std::istringstream get(*str);
double * number = new double;
get >> *number;
GC::save(number);
return number;
}
std::string * makeHeader(const Value & begin, const Value & action, const Value & num){
std::ostringstream out;
out << as<char*>(begin) << " " << as<char*>(action) << " " << (as<Ast::Value*>(num))->toString();
std::string * object = new std::string(out.str());
GC::save(object);
return object;
}
SectionList * makeSectionList(){
SectionList * object = new SectionList();
GC::save(object);
return object;
}
Ast::Attribute * makeAttributeArray(Ast::Keyword * name, Ast::Value * index, Ast::Value * value){
/* FIXME! fix line numbers here */
Ast::AttributeArray * object = new Ast::AttributeArray(-1, -1, name, index, value);
GC::save(object);
return object;
}
void addSection(const Value & section_list_value, const Value & section_value){
SectionList * sections = (SectionList*) section_list_value.getValue();
Ast::Section * section = (Ast::Section*) section_value.getValue();
if (section == 0){
throw ParseException("Cannot add null section");
}
sections->push_back(section);
}
Ast::Attribute * makeAttributeKeyword(const Value & id, const Value & data){
/* FIXME: fix line numbers here */
Ast::AttributeKeyword * object = new Ast::AttributeKeyword(-1, -1, as<Ast::Keyword*>(id), as<Ast::Value*>(data));
GC::save(object);
return object;
}
Ast::Attribute * makeAttributeKeyword(const Value & id){
/* FIXME: fix line numbers here */
Ast::AttributeKeyword * object = new Ast::AttributeKeyword(-1, -1, as<Ast::Keyword*>(id));
GC::save(object);
return object;
}
}}
rules:
start = current:{{ value = makeSectionList(); }} whitespace newline* (sn line(current) whitespace line_end?)* sn <eof> {{ value = current; GC::cleanup(as<SectionList*>(value)); }} <fail> {{ GC::cleanup(0); }}
line(current) = s comment
| s action {{ addSection(current, $2); }}
action = action_start ast:{{value = makeSection($1); }} whitespace newline+ (action_line(ast) whitespace line_end)* {{ value = ast; }}
action_line(section) = s comment
| s data:collision_default {{ as<Ast::Section*>(section)->addAttribute(as<Ast::Attribute*>(data)); }}
| s data:collision {{ as<Ast::Section*>(section)->addAttribute(as<Ast::Attribute*>(data)); }}
| s data:valuelist {{ as<Ast::Section*>(section)->addValue(as<Ast::Value*>(data)); }}
| s data:loopstart {{ as<Ast::Section*>(section)->addAttribute(as<Ast::Attribute*>(data)); }}
| space s
| line:<line> !(s action_start) (!line_end .)+ &line_end {{ std::cout << "Warning: ignoring input at line " << getCurrentLine(line) << " column " << getCurrentColumn(line) << std::endl; }}
# | space+
line_end = newline+
| &<eof> <void>
newline = "\n"
| "\r"
loopstart = "loopstart"{case} ":"? {{ value = makeAttributeKeyword(Value(makeKeyword($1))); }}
whitespace = sw*
sn = space_newline*
space_newline = space
| newline
sw = space
| comment
inline s = space*
inline space = " "
| "\t"
| <ascii 255>
comment = ";" (!newline .)*
| "=" (!newline .)*
| "-" "-" (!newline .)*
collision_default = "Clsn2Default"{case} ":" s num:integer {{ value = makeAttributeKeyword(Value(makeKeyword($1)), num); }}
| "Clsn1Default"{case} ":" s num:integer {{ value = makeAttributeKeyword(Value(makeKeyword($1)), num); }}
| "Clsn2"{case} ":" s num:integer {{ value = makeAttributeKeyword(Value(makeKeyword($1)), num); }}
| "Clsn1"{case} ":" s num:integer {{ value = makeAttributeKeyword(Value(makeKeyword($1)), num); }}
# change int,int,int,int to valuelist ?
collision = name:"Clsn2"{case} s "[" s index:integer s "]" s "=" s n1:integer s "," s n2:integer s "," s n3:integer s "," s n4:integer {{ value = makeAttributeArray(makeKeyword(name), as<Ast::Value*>(index), makeValueList(n1, n2, n3, n4)); }}
| name:"Clsn1"{case} s "[" s index:integer s "]" s "=" s n1:integer s "," s n2:integer s "," s n3:integer s "," s n4:integer {{ value = makeAttributeArray(makeKeyword(name), as<Ast::Value*>(index), makeValueList(n1, n2, n3, n4)); }}
action_start = "[" s begin:"Begin"{case} s action:"Action"{case} s num:integer s (!"]" .)* "]" {{ value = makeHeader(begin, action, num); }}
inline digit = [0123456789]
integer = sign? digit+ {{ value = parseDouble($2); value = makeNumber($1,value); }}
inline sign = "-"
| "+"
valuelist = value (s "," s value?)* {{ value = makeValueList($1,$2); }}
# FIXME: handle the integer values
value = integer
# Are all these things part of .air files?
| "as"{case} integer "d"{case} integer {{ value = makeKeyword($1); }}
| "a"{case} integer {{ value = makeKeyword($1); }}
| "a"{case} {{ value = makeKeyword($1); }}
| "s"{case} integer {{ value = makeKeyword($1); }}
| "s"{case} {{ value = makeKeyword($1); }}
| "vh"{case} {{ value = makeKeyword($1); }}
| "hv"{case} {{ value = makeKeyword($1); }}
| "v"{case} {{ value = makeKeyword($1); }}
| "h"{case} {{ value = makeKeyword($1); }}
This diff is collapsed.
# mugen def parser
# Can parse about 180kb/s on a 1.8ghz
# Current status:
# 95% done
# TODO: create proper AST structure for filenames
# There are some TODO's left in the code as well.
start-symbol: start
options: debug0, no-memo
module: Mugen.Def
include: {{
#include "mugen/ast/all.h"
#include <map>
#include "gc.h"
typedef std::list<Ast::Section*> SectionList;
}}
code: {{
template<class X>
X as(const Value & value){
return (X) value.getValue();
}
void addSection(const Value & section_list_value, const Value & section_value){
SectionList * sections = (SectionList*) section_list_value.getValue();
Ast::Section * section = (Ast::Section*) section_value.getValue();
if (section == 0){
throw ParseException("Cannot add null section");
}
sections->push_back(section);
}
Ast::Section * makeSection(const Value & str, int line, int column){
Ast::Section * object = new Ast::Section(as<std::string*>(str), line, column);
GC::save(object);
return object;
}
SectionList * makeSectionList(){
SectionList * object = new SectionList();
GC::save(object);
return object;
}
std::string * toString(const Value & input){
std::ostringstream out;
for (Value::iterator it = input.getValues().begin(); it != input.getValues().end(); it++){
out << (char) (long) (*it).getValue();
}
std::string * object = new std::string(out.str());
GC::save(object);
return object;
}
double * parseDouble(const Value & value){
std::string * str = toString(value);
std::istringstream get(*str);
double * number = new double;
get >> *number;
GC::save(number);
return number;
}
double * parseDouble(const Value & left, const Value & right){
std::string * str1 = toString(left);
std::string * str2 = toString(right);
std::istringstream get(*str1 + "." + *str2);
double * number = new double;
get >> *number;
GC::save(number);
return number;
}
std::string * toString(char front, const Value & input){
std::string * str = toString(input);
str->insert(str->begin(), front);
return str;
}
Ast::ValueAttribute * makeValueAttribute(const Value & attribute){
/* FIXME: fix line numbers here */
Ast::ValueAttribute * value = new Ast::ValueAttribute(-1, -1, as<Ast::Attribute*>(attribute));
GC::save(value);
return value;
}
Ast::Attribute * makeAttribute(const Value & line, const Value & id, const Value & data){
Ast::AttributeSimple * object = new Ast::AttributeSimple(getCurrentLine(line), getCurrentColumn(line), as<Ast::Identifier*>(id), as<Ast::Value*>(data));
GC::save(object);
return object;
}
Ast::Attribute * makeAttribute(const Value & id, const Value & data){
Ast::AttributeSimple * object = new Ast::AttributeSimple(as<Ast::Identifier*>(id), as<Ast::Value*>(data));
GC::save(object);
return object;
}
Ast::Attribute * makeAttributeWithInfo(const Value & line, const Value & id){
Ast::AttributeSimple * object = new Ast::AttributeSimple(getCurrentLine(line), getCurrentColumn(line), as<Ast::Identifier*>(id));
GC::save(object);
return object;
}
Ast::Attribute * makeAttribute(const Value & id){
Ast::AttributeSimple * object = new Ast::AttributeSimple(as<Ast::Identifier*>(id));
GC::save(object);
return object;
}
Ast::Attribute * makeAttributeFilename(const Value & id, const Value & data){
/* TODO */
throw ParseException("makeAttributeFilename not implemented");
// return makeAttribute(id, data);
}
Ast::Attribute * makeIndexedAttribute(const Value & id, const Value & index, const Value & data){
/* TODO: fix this */
throw ParseException("makeIndexedAttribute not implemented");
/*
Ast::Attribute * object = new Ast::Attribute(Ast::Attribute::None);
GC::save(object);
return object;
*/
}
Ast::Keyword * makeKeyword(const Value & value){
/* FIXME: fix line numbers here */
Ast::Keyword * object = new Ast::Keyword(-1, -1, as<char*>(value));
GC::save(object);
return object;
}
Ast::Attribute * makeAttributes(const Value & id, const Value & data){
/* TODO */
throw ParseException("makeAttributes not implemented");
/*
Ast::Attribute * object = new Ast::Attribute(Ast::Attribute::None);
GC::save(object);
return object;
*/
}
/* TODO */
Ast::Value * makeValue(){
/* FIXME: fix line numbers here */
Ast::Number * object = new Ast::Number(-1, -1, 0);
GC::save(object);
return object;
}
Ast::Value * makeValueList(const Value & line, const Value & front, const Value & rest){
std::list<Ast::Value*> values;
values.push_back(as<Ast::Value*>(front));
for (Value::iterator it = rest.getValues().begin(); it != rest.getValues().end(); it++){
Ast::Value * value = as<Ast::Value*>(Value((*it).getValue()));
if (value == 0){
/* FIXME! replace empty with a new node */
value = makeKeyword(Value("empty"));
values.push_back(value);
} else {
values.push_back(value);
}
}
Ast::ValueList * object = new Ast::ValueList(getCurrentLine(line), getCurrentColumn(line), values);
GC::save(object);
return object;
}
Ast::Identifier * makeIdentifier(const Value & front, const Value & rest){
std::list<std::string> ids;
ids.push_back(*as<std::string*>(front));
for (Value::iterator it = rest.getValues().begin(); it != rest.getValues().end(); it++){
ids.push_back(*as<std::string*>(Value((*it).getValue())));
}
Ast::Identifier * object = new Ast::Identifier(ids);
GC::save(object);
return object;
}
Ast::Value * makeNumber(const Value & sign, const Value & number){
double value = *(as<double*>(number));
if (sign.getValue() != 0 && strcmp(as<const char *>(sign), "-") == 0){
value = -value;
}
/* FIXME: fix line numbers here */
Ast::Number * object = new Ast::Number(-1, -1, value);
GC::save(object);
return object;
}
Ast::String * makeString(const Value & value){
/* FIXME: fix line numbers here */
Ast::String * object = new Ast::String(-1, -1, toString(value));
GC::save(object);
return object;
}
Ast::Section * asSection(const Value & value){
return as<Ast::Section*>(value);
}
Ast::Attribute * asAttribute(const Value & value){
return as<Ast::Attribute*>(value);
}
Ast::Value * asValue(const Value & value){
return as<Ast::Value*>(value);
}
/* FIXME */
Ast::Value * makeDate(const Value & month, const Value & day, const Value & year){
/* FIXME: fix line numbers here */
Ast::Number * object = new Ast::Number(-1, -1, 0);
GC::save(object);
return object;
}
}}
rules:
start = current:{{ value = makeSectionList(); }} whitespace newline* (line(current) whitespace line_end?)* <eof> {{ value = current; GC::cleanup(as<SectionList*>(value)); }}
<fail> {{ GC::cleanup(0); }}
# start = current real_start($1)
# real_start(c) = blah ... <eof>
# | {{ delete c; }} <error>
# or
# start = current{{..}} blah .. <eof> <fail>{{ delete current.getValue(); }}
line(current) = s comment
| s section {{ addSection(current, $2); }}
# | s characters
#| s attribute {{ value = current; }}
#| s valuelist {{ value = current; }}
#| s loopstart {{ value = current; }}
| space+
line_end = newline+
| &<eof> <void>
inline newline = "\n"
| "\r"
inline whitespace = sw*
inline sw = " "
| "\t"
| comment
inline s = space*
inline space = " "
| "\t"
inline comment = ";" (!"\n" .)*
| "=" (!"\n" .)*
| "-" "-"+
section = line:<line> name:section_start ast:{{value = makeSection(name, getCurrentLine(line), getCurrentColumn(line)); }} whitespace newline+ (section_line(ast) whitespace line_end)* {{ value = ast; }}
section_line(section) = s comment
| s data:attribute {{ asSection(section)->addAttribute(asAttribute(data)); }}
| s data:loopstart {{ asSection(section)->addValue(asValue(data)); }}
| s data:valuelist {{ asSection(section)->addValue(asValue(data)); }}
| space+ !"["
section_start = "[" s data:(!"]" .)+ s "]" {{ value = toString(data); }}
loopstart = "loopstart"{case} {{ value = makeValue(); }}
name = letter alpha_digit* {{ value = toString((char)(long)$1.getValue(),$2); }}
inline letter = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_]
inline alpha_digit = letter
| digit
line_end_or_comment = line_end
| comment
# characters = name s "," s filename
filename = line:<line> !<quote> file:filename_char+ {{ value = new Ast::Filename(getCurrentLine(line), getCurrentColumn(line), toString(file)); GC::save(as<Ast::Filename*>(value)); }}
filename_char = !"," !"\n" !"[" !<ascii 13> !"=" !";" .
attribute = line:<line> id:identifier s "=" s &line_end_or_comment {{ value = makeAttributeWithInfo(line, id); }}
| line:<line> id:identifier s "=" s data:valuelist {{ value = makeAttribute(line, id, data); }}
| line:<line> id:identifier s "=" s data:filename {{ value = makeAttribute(line, id, data); }}
| id:identifier s "(" s index:number s ")" s "=" s data:valuelist {{ value = makeIndexedAttribute(id, index, data); }}
# | id:identifier_list s "=" s data:valuelist {{ value = makeAttributes(id, data); }}
attribute_simple = id:identifier s "=" s data:value {{ value = makeAttribute(id, data); }}
identifier = name ("." name)* {{ value = makeIdentifier($1,$2); }}
# identifier_list = identifier (s "," s filename)+ !(s "=" s value)
identifier_list = identifier (s "," s filename)+
valuelist = line:<line> value (s "," s value?)* {{ value = makeValueList(line, $2,$3); }}
value = string
| date
| number !letter !"-" {{ value = $1; }}
| attribute_simple {{ value = makeValueAttribute($1); }}
| keyword !alpha_digit {{ value = makeKeyword($1); }}
| "s"{case} !filename_char !"." {{ value = makeKeyword($1); }}
| "h"{case} !filename_char !"." {{ value = makeKeyword($1); }}
| "a"{case} number? !filename_char {{ value = makeKeyword($1); }}
| filename
keyword = "normal"
| "parallax"
| "addalpha"
| "add1"
| "add"
| "sub"
date = digit+ "." digit+ "." digit+ {{ value = makeDate($1,$3,$5); }}
| digit+ "/" digit+ "/" digit+ {{ value = makeDate($1,$3,$5); }}
string = <quote> data:(!<quote> !"\n" .)* <quote> {{ value = makeString(data); }}
number = sign? float_or_integer {{ value = makeNumber($1,$2); }}
inline sign = "+"
| "-"
float_or_integer = left:digit* "." right:digit+ {{ value = parseDouble(left,right); }}
| digit+ !"." {{ value = parseDouble($1); }}
inline digit = [0123456789]
This diff is collapsed.
#!/usr/bin/env python
class TestException(Exception):
def __init__(self, message):
Exception.__init__(self, message)
def erase(file):
import os
try:
os.remove(file)
except OSError:
pass
def write(data, file):
f = open(file, 'w')
f.write(data)
f.close()
def rootPath():
return ".test"
file_count = 0
def newFile(suffix = ""):
import os
global file_count
file_count += 1
return "file%d%s" % (file_count, suffix)
# return os.path.join(rootPath(), "file%d%s" % (file_count, suffix))
def get_peg_output(option, grammar):
import subprocess
peg_out = subprocess.Popen(['./peg.py', option, grammar], stdout = subprocess.PIPE)
code = peg_out.wait()
out, err = peg_out.communicate()
if code != 0:
raise TestException(out)
return out
def do_bnf(name, grammar):
print "[%s] Test bnf.." % name
# peg_out = subprocess.Popen(['./peg.py', '--bnf', grammar], stdout = subprocess.PIPE)
# out, err = peg_out.communicate()
out = get_peg_output('--bnf', grammar)
g2 = ".bnf2"
write(out, g2)
out2 = get_peg_output('--bnf', g2)
# peg_out2 = subprocess.Popen(['./peg.py', '--bnf', g2], stdout = subprocess.PIPE)
# out2, err2 = peg_out2.communicate()
erase(g2)
if out != out2:
print "error with bnf generation!!"
print out
print "vs"
print out2
return False
return True
def do_ruby(name, grammar, input):
print "[%s] Test ruby.." % name
out = get_peg_output('--ruby', grammar)
file = newFile('.rb')
write(out, file)
import re
import subprocess
module = re.match(r"(\w+)\.rb", file).group(1)
process = subprocess.Popen(['ruby', '-e', 'require "%s"; puts parse(ARGV[0])' % module, input], stdout = subprocess.PIPE)
code = process.wait()
out, err = process.communicate()
# erase(file)
if code != 0:
raise TestException("Ruby failed: %s" % code)
return out
def do_python(name, grammar, input):
import re
# import subprocess
try:
print "[%s] Test python.." % name
out = get_peg_output('--python', grammar)
# peg_out = subprocess.Popen(['./peg.py', '--python', grammar], stdout = subprocess.PIPE)
# out, err = peg_out.communicate()
file = newFile('.py')
write(out, file)
name = re.match(r"(\w+)\.py", file).group(1)
x = __import__(name)
result = x.parseFile(input)
erase(file)
erase(file + 'c')
if result == None:
raise TestException("Error with python parser")
return result
except Exception as e:
import traceback
traceback.print_exc()
raise TestException(str(e))
def do_cpp(name, grammar, input):
import subprocess