1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Reworked build system: makefiles replaced with in-program logic; core replaced with targets; preproc/ replaced with Wiring's; now prepend "#include "WProgram.h" instead of wiringlite.inc; new entries in preferences.txt; bundled Wiring libs.

This commit is contained in:
David A. Mellis
2005-09-25 14:11:32 +00:00
parent 10b3f4fe08
commit 7fbb37cbe0
98 changed files with 44948 additions and 18090 deletions

View File

@ -1,9 +0,0 @@
*Lexer.java
*Recognizer.java
*TokenTypes.java
*TokenTypes.txt
*TreeParser.java
*TreeParserTokenTypes.java
*TreeParserTokenTypes.txt
expanded*.g

133
app/preproc/CSymbolTable.java Executable file
View File

@ -0,0 +1,133 @@
package processing.app.preproc;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
public class CSymbolTable {
/** holds list of scopes */
private Vector scopeStack;
/** table where all defined names are mapped to TNode tree nodes */
private Hashtable symTable;
public CSymbolTable() {
scopeStack = new Vector(10);
symTable = new Hashtable(533);
}
/** push a new scope onto the scope stack.
*/
public void pushScope(String s) {
//System.out.println("push scope:" + s);
scopeStack.addElement(s);
}
/** pop the last scope off the scope stack.
*/
public void popScope() {
//System.out.println("pop scope");
int size = scopeStack.size();
if(size > 0)
scopeStack.removeElementAt(size - 1);
}
/** return the current scope as a string
*/
public String currentScopeAsString() {
StringBuffer buf = new StringBuffer(100);
boolean first = true;
Enumeration e = scopeStack.elements();
while(e.hasMoreElements()) {
if(first)
first = false;
else
buf.append("::");
buf.append(e.nextElement().toString());
}
return buf.toString();
}
/** given a name for a type, append it with the
current scope.
*/
public String addCurrentScopeToName(String name) {
String currScope = currentScopeAsString();
return addScopeToName(currScope, name);
}
/** given a name for a type, append it with the
given scope. MBZ
*/
public String addScopeToName(String scope, String name) {
if(scope == null || scope.length() > 0)
return scope + "::" + name;
else
return name;
}
/** remove one level of scope from name MBZ*/
public String removeOneLevelScope(String scopeName) {
int index = scopeName.lastIndexOf("::");
if (index > 0) {
return scopeName.substring(0,index);
}
if (scopeName.length() > 0) {
return "";
}
return null;
}
/** add a node to the table with it's key as
the current scope and the name */
public TNode add(String name, TNode node) {
return (TNode)symTable.put(addCurrentScopeToName(name),node);
}
/** lookup a fully scoped name in the symbol table */
public TNode lookupScopedName(String scopedName) {
return (TNode)symTable.get(scopedName);
}
/** lookup an unscoped name in the table by prepending
the current scope.
MBZ -- if not found, pop scopes and look again
*/
public TNode lookupNameInCurrentScope(String name) {
String scope = currentScopeAsString();
String scopedName;
TNode tnode = null;
//System.out.println( "\n"+ this.toString() );
while (tnode == null && scope != null) {
scopedName = addScopeToName(scope, name);
//System.out.println("lookup trying " + scopedName);
tnode = (TNode)symTable.get(scopedName);
scope = removeOneLevelScope(scope);
}
return tnode;
}
/** convert this table to a string */
public String toString() {
StringBuffer buff = new StringBuffer(300);
buff.append("CSymbolTable { \nCurrentScope: " + currentScopeAsString() +
"\nDefinedSymbols:\n");
Enumeration ke = symTable.keys();
Enumeration ve = symTable.elements();
while(ke.hasMoreElements()) {
buff.append(ke.nextElement().toString() + " (" +
TNode.getNameForType(((TNode)ve.nextElement()).getType()) + ")\n");
}
buff.append("}\n");
return buff.toString();
}
};

32
app/preproc/CToken.java Executable file
View File

@ -0,0 +1,32 @@
package processing.app.preproc;
import antlr.CommonToken;
public class CToken extends antlr.CommonToken {
String source = "";
int tokenNumber;
public String getSource()
{
return source;
}
public void setSource(String src)
{
source = src;
}
public int getTokenNumber()
{
return tokenNumber;
}
public void setTokenNumber(int i)
{
tokenNumber = i;
}
public String toString() {
return "CToken:" +"(" + hashCode() + ")" + "[" + getType() + "] "+ getText() + " line:" + getLine() + " source:" + source ;
}
}

15
app/preproc/CVS/Entries Normal file
View File

@ -0,0 +1,15 @@
/CSymbolTable.java/1.1.1.1/Thu Sep 22 15:32:54 2005//
/CToken.java/1.1.1.1/Thu Sep 22 15:32:54 2005//
/ExtendedCommonASTWithHiddenTokens.java/1.1.1.1/Thu Sep 22 15:32:55 2005//
/LineObject.java/1.1.1.1/Thu Sep 22 15:32:55 2005//
/Makefile/1.1.1.1/Thu Sep 22 15:32:55 2005//
/PreprocessorInfoChannel.java/1.1.1.1/Thu Sep 22 15:32:55 2005//
/StdCParser.g/1.1.1.1/Thu Sep 22 15:32:56 2005//
/TNode.java/1.1.1.1/Thu Sep 22 15:32:56 2005//
/TNodeFactory.java/1.1.1.1/Thu Sep 22 15:32:56 2005//
/WEmitter.g/1.4/Thu Sep 22 15:32:56 2005//
/WParser.g/1.4/Thu Sep 22 15:32:57 2005//
/WTreeParser.g/1.2/Thu Sep 22 15:32:57 2005//
/whitespace_test.pde/1.1.1.1/Thu Sep 22 15:32:56 2005//
/PdePreprocessor.java/1.13/Sat Sep 24 11:26:19 2005//
D

View File

@ -0,0 +1 @@
wiring/app/preproc

1
app/preproc/CVS/Root Normal file
View File

@ -0,0 +1 @@
:ext:dmellis@wcvs.uniandes.edu.co:/home/cvs/cvsrep

2
app/preproc/ExtendedCommonASTWithHiddenTokens.java Normal file → Executable file
View File

@ -4,7 +4,7 @@ package antlr;
* Project led by Terence Parr at http://www.jGuru.com
* Software rights: http://www.antlr.org/RIGHTS.html
*
* $Id: ExtendedCommonASTWithHiddenTokens.java,v 1.1 2005/04/09 02:30:36 benfry Exp $
* $Id: ExtendedCommonASTWithHiddenTokens.java,v 1.1.1.1 2005/06/22 22:18:14 h Exp $
*/
import java.io.*;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,157 +0,0 @@
// $ANTLR 2.7.2: "java.g" -> "JavaLexer.java"$
package antlr.java;
public interface JavaTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int BLOCK = 4;
int MODIFIERS = 5;
int OBJBLOCK = 6;
int SLIST = 7;
int CTOR_DEF = 8;
int METHOD_DEF = 9;
int VARIABLE_DEF = 10;
int INSTANCE_INIT = 11;
int STATIC_INIT = 12;
int TYPE = 13;
int CLASS_DEF = 14;
int INTERFACE_DEF = 15;
int PACKAGE_DEF = 16;
int ARRAY_DECLARATOR = 17;
int EXTENDS_CLAUSE = 18;
int IMPLEMENTS_CLAUSE = 19;
int PARAMETERS = 20;
int PARAMETER_DEF = 21;
int LABELED_STAT = 22;
int TYPECAST = 23;
int INDEX_OP = 24;
int POST_INC = 25;
int POST_DEC = 26;
int METHOD_CALL = 27;
int EXPR = 28;
int ARRAY_INIT = 29;
int IMPORT = 30;
int UNARY_MINUS = 31;
int UNARY_PLUS = 32;
int CASE_GROUP = 33;
int ELIST = 34;
int FOR_INIT = 35;
int FOR_CONDITION = 36;
int FOR_ITERATOR = 37;
int EMPTY_STAT = 38;
int FINAL = 39;
int ABSTRACT = 40;
int STRICTFP = 41;
int SUPER_CTOR_CALL = 42;
int CTOR_CALL = 43;
int LITERAL_package = 44;
int SEMI = 45;
int LITERAL_import = 46;
int LBRACK = 47;
int RBRACK = 48;
int LITERAL_void = 49;
int LITERAL_boolean = 50;
int LITERAL_byte = 51;
int LITERAL_char = 52;
int LITERAL_short = 53;
int LITERAL_int = 54;
int LITERAL_float = 55;
int LITERAL_long = 56;
int LITERAL_double = 57;
int IDENT = 58;
int DOT = 59;
int STAR = 60;
int LITERAL_private = 61;
int LITERAL_public = 62;
int LITERAL_protected = 63;
int LITERAL_static = 64;
int LITERAL_transient = 65;
int LITERAL_native = 66;
int LITERAL_threadsafe = 67;
int LITERAL_synchronized = 68;
int LITERAL_volatile = 69;
int LITERAL_class = 70;
int LITERAL_extends = 71;
int LITERAL_interface = 72;
int LCURLY = 73;
int RCURLY = 74;
int COMMA = 75;
int LITERAL_implements = 76;
int LPAREN = 77;
int RPAREN = 78;
int LITERAL_this = 79;
int LITERAL_super = 80;
int ASSIGN = 81;
int LITERAL_throws = 82;
int COLON = 83;
int LITERAL_if = 84;
int LITERAL_else = 85;
int LITERAL_for = 86;
int LITERAL_while = 87;
int LITERAL_do = 88;
int LITERAL_break = 89;
int LITERAL_continue = 90;
int LITERAL_return = 91;
int LITERAL_switch = 92;
int LITERAL_throw = 93;
int LITERAL_assert = 94;
int LITERAL_case = 95;
int LITERAL_default = 96;
int LITERAL_try = 97;
int LITERAL_finally = 98;
int LITERAL_catch = 99;
int PLUS_ASSIGN = 100;
int MINUS_ASSIGN = 101;
int STAR_ASSIGN = 102;
int DIV_ASSIGN = 103;
int MOD_ASSIGN = 104;
int SR_ASSIGN = 105;
int BSR_ASSIGN = 106;
int SL_ASSIGN = 107;
int BAND_ASSIGN = 108;
int BXOR_ASSIGN = 109;
int BOR_ASSIGN = 110;
int QUESTION = 111;
int LOR = 112;
int LAND = 113;
int BOR = 114;
int BXOR = 115;
int BAND = 116;
int NOT_EQUAL = 117;
int EQUAL = 118;
int LT = 119;
int GT = 120;
int LE = 121;
int GE = 122;
int LITERAL_instanceof = 123;
int SL = 124;
int SR = 125;
int BSR = 126;
int PLUS = 127;
int MINUS = 128;
int DIV = 129;
int MOD = 130;
int INC = 131;
int DEC = 132;
int BNOT = 133;
int LNOT = 134;
int LITERAL_true = 135;
int LITERAL_false = 136;
int LITERAL_null = 137;
int LITERAL_new = 138;
int NUM_INT = 139;
int CHAR_LITERAL = 140;
int STRING_LITERAL = 141;
int NUM_FLOAT = 142;
int NUM_LONG = 143;
int NUM_DOUBLE = 144;
int WS = 145;
int SL_COMMENT = 146;
int ML_COMMENT = 147;
int ESC = 148;
int HEX_DIGIT = 149;
int VOCAB = 150;
int EXPONENT = 151;
int FLOAT_SUFFIX = 152;
}

View File

@ -1,151 +0,0 @@
// $ANTLR 2.7.2: java.g -> JavaTokenTypes.txt$
Java // output token vocab name
BLOCK=4
MODIFIERS=5
OBJBLOCK=6
SLIST=7
CTOR_DEF=8
METHOD_DEF=9
VARIABLE_DEF=10
INSTANCE_INIT=11
STATIC_INIT=12
TYPE=13
CLASS_DEF=14
INTERFACE_DEF=15
PACKAGE_DEF=16
ARRAY_DECLARATOR=17
EXTENDS_CLAUSE=18
IMPLEMENTS_CLAUSE=19
PARAMETERS=20
PARAMETER_DEF=21
LABELED_STAT=22
TYPECAST=23
INDEX_OP=24
POST_INC=25
POST_DEC=26
METHOD_CALL=27
EXPR=28
ARRAY_INIT=29
IMPORT=30
UNARY_MINUS=31
UNARY_PLUS=32
CASE_GROUP=33
ELIST=34
FOR_INIT=35
FOR_CONDITION=36
FOR_ITERATOR=37
EMPTY_STAT=38
FINAL="final"=39
ABSTRACT="abstract"=40
STRICTFP="strictfp"=41
SUPER_CTOR_CALL=42
CTOR_CALL=43
LITERAL_package="package"=44
SEMI=45
LITERAL_import="import"=46
LBRACK=47
RBRACK=48
LITERAL_void="void"=49
LITERAL_boolean="boolean"=50
LITERAL_byte="byte"=51
LITERAL_char="char"=52
LITERAL_short="short"=53
LITERAL_int="int"=54
LITERAL_float="float"=55
LITERAL_long="long"=56
LITERAL_double="double"=57
IDENT=58
DOT=59
STAR=60
LITERAL_private="private"=61
LITERAL_public="public"=62
LITERAL_protected="protected"=63
LITERAL_static="static"=64
LITERAL_transient="transient"=65
LITERAL_native="native"=66
LITERAL_threadsafe="threadsafe"=67
LITERAL_synchronized="synchronized"=68
LITERAL_volatile="volatile"=69
LITERAL_class="class"=70
LITERAL_extends="extends"=71
LITERAL_interface="interface"=72
LCURLY=73
RCURLY=74
COMMA=75
LITERAL_implements="implements"=76
LPAREN=77
RPAREN=78
LITERAL_this="this"=79
LITERAL_super="super"=80
ASSIGN=81
LITERAL_throws="throws"=82
COLON=83
LITERAL_if="if"=84
LITERAL_else="else"=85
LITERAL_for="for"=86
LITERAL_while="while"=87
LITERAL_do="do"=88
LITERAL_break="break"=89
LITERAL_continue="continue"=90
LITERAL_return="return"=91
LITERAL_switch="switch"=92
LITERAL_throw="throw"=93
LITERAL_assert="assert"=94
LITERAL_case="case"=95
LITERAL_default="default"=96
LITERAL_try="try"=97
LITERAL_finally="finally"=98
LITERAL_catch="catch"=99
PLUS_ASSIGN=100
MINUS_ASSIGN=101
STAR_ASSIGN=102
DIV_ASSIGN=103
MOD_ASSIGN=104
SR_ASSIGN=105
BSR_ASSIGN=106
SL_ASSIGN=107
BAND_ASSIGN=108
BXOR_ASSIGN=109
BOR_ASSIGN=110
QUESTION=111
LOR=112
LAND=113
BOR=114
BXOR=115
BAND=116
NOT_EQUAL=117
EQUAL=118
LT=119
GT=120
LE=121
GE=122
LITERAL_instanceof="instanceof"=123
SL=124
SR=125
BSR=126
PLUS=127
MINUS=128
DIV=129
MOD=130
INC=131
DEC=132
BNOT=133
LNOT=134
LITERAL_true="true"=135
LITERAL_false="false"=136
LITERAL_null="null"=137
LITERAL_new="new"=138
NUM_INT=139
CHAR_LITERAL=140
STRING_LITERAL=141
NUM_FLOAT=142
NUM_LONG=143
NUM_DOUBLE=144
WS=145
SL_COMMENT=146
ML_COMMENT=147
ESC=148
HEX_DIGIT=149
VOCAB=150
EXPONENT=151
FLOAT_SUFFIX=152

126
app/preproc/LineObject.java Executable file
View File

@ -0,0 +1,126 @@
package processing.app.preproc;
class LineObject {
LineObject parent = null;
String source = "";
int line = 1;
boolean enteringFile = false;
boolean returningToFile = false;
boolean systemHeader = false;
boolean treatAsC = false;
public LineObject()
{
super();
}
public LineObject( LineObject lobj )
{
parent = lobj.getParent();
source = lobj.getSource();
line = lobj.getLine();
enteringFile = lobj.getEnteringFile();
returningToFile = lobj.getReturningToFile();
systemHeader = lobj.getSystemHeader();
treatAsC = lobj.getTreatAsC();
}
public LineObject( String src)
{
source = src;
}
public void setSource(String src)
{
source = src;
}
public String getSource()
{
return source;
}
public void setParent(LineObject par)
{
parent = par;
}
public LineObject getParent()
{
return parent;
}
public void setLine(int l)
{
line = l;
}
public int getLine()
{
return line;
}
public void newline()
{
line++;
}
public void setEnteringFile(boolean v)
{
enteringFile = v;
}
public boolean getEnteringFile()
{
return enteringFile;
}
public void setReturningToFile(boolean v)
{
returningToFile = v;
}
public boolean getReturningToFile()
{
return returningToFile;
}
public void setSystemHeader(boolean v)
{
systemHeader = v;
}
public boolean getSystemHeader()
{
return systemHeader;
}
public void setTreatAsC(boolean v)
{
treatAsC = v;
}
public boolean getTreatAsC()
{
return treatAsC;
}
public String toString() {
StringBuffer ret;
ret = new StringBuffer("# " + line + " \"" + source + "\"");
if (enteringFile) {
ret.append(" 1");
}
if (returningToFile) {
ret.append(" 2");
}
if (systemHeader) {
ret.append(" 3");
}
if (treatAsC) {
ret.append(" 4");
}
return ret.toString();
}
}

36
app/preproc/Makefile Executable file
View File

@ -0,0 +1,36 @@
classfiles = LineObject.class PreprocessorInfoChannel.class StdCParser.class StdCLexer.class WParser.class WLexer.class WTreeParser.class WEmitter.class
javafiles = CSymbolTable.java TNode.java TNodeFactory.java CToken.java LineObject.java PreprocessorInfoChannel.java StdCParser.java StdCLexer.java WParser.java WLexer.java WTreeParser.java WEmitter.java
all : $(javafiles) $(classfiles)
clean :
StdCParser.java StdCLexer.java : StdCParser.g
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool StdCParser.g
WParser.java WLexer.java : WParser.g WParser.g
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool -glib "StdCParser.g" WParser.g
WTreeParser.java : WTreeParser.g
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool WTreeParser.g
WEmitter.java : WEmitter.g WTreeParser.g
java -cp "..\\..\\build\\windows\\work\\lib\\antlr.jar" antlr.Tool -glib "WTreeParser.g" WEmitter.g
.SUFFIXES: .java .class
.java.class :
../../build/windows/work/jikes -cp "..\\..\\build\\windows\\work\\java\\lib\\rt.jar;..\\..\\build\\windows\\work\\lib\\mrj.jar;..\\..\\build\\windows\\work\\lib\\antlr.jar;." $<

View File

@ -1,922 +0,0 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
package processing.app.preproc;
import processing.app.*;
/* Based on original code copyright (c) 2003 Andy Tripp <atripp@comcast.net>.
* shipped under GPL with permission.
*/
import antlr.*;
import antlr.collections.*;
import antlr.collections.impl.*;
import java.io.*;
import java.util.*;
/**
* PDEEmitter: A class that can take an ANTLR Java AST and produce
* reasonably formatted Java code from it. To use it, create a
* PDEEmitter object, call setOut() if you want to print to something
* other than System.out, and then call print(), passing the
* AST. Typically, the AST node that you pass would be the root of a
* tree - the ROOT_ID node that represents a Java file.
*/
public class PdeEmitter implements PdeTokenTypes
{
private PrintStream out = System.out;
private PrintStream debug = System.err;
private static int ALL = -1;
private java.util.Stack stack = new java.util.Stack();
private static String[] tokenNames;
private final static int ROOT_ID = 0;
static {
setupTokenNames();
}
/*
private static Hashtable publicMethods;
private static final String publicMethodList[] = {
"setup", "draw", //"loop",
"mousePressed", "mouseReleased", "mouseClicked",
"mouseEntered", "mouseExited",
"mouseMoved", "mouseDragged",
"keyPressed", "keyReleased", "keyTyped"
};
static {
publicMethods = new Hashtable();
for (int i = 0; i < publicMethodList.length; i++) {
publicMethods.put(publicMethodList[i], new Object());
}
}
*/
// Map each AST token type to a String
private static void setupTokenNames() {
tokenNames = new String[200];
for (int i=0; i<tokenNames.length; i++) {
tokenNames[i] = "ERROR:" + i;
}
tokenNames[POST_INC]="++";
tokenNames[POST_DEC]="--";
tokenNames[UNARY_MINUS]="-";
tokenNames[UNARY_PLUS]="+";
tokenNames[STAR]="*";
tokenNames[ASSIGN]="=";
tokenNames[PLUS_ASSIGN]="+=";
tokenNames[MINUS_ASSIGN]="-=";
tokenNames[STAR_ASSIGN]="*=";
tokenNames[DIV_ASSIGN]="/=";
tokenNames[MOD_ASSIGN]="%=";
tokenNames[SR_ASSIGN]=">>=";
tokenNames[BSR_ASSIGN]=">>>=";
tokenNames[SL_ASSIGN]="<<=";
tokenNames[BAND_ASSIGN]="&=";
tokenNames[BXOR_ASSIGN]="^=";
tokenNames[BOR_ASSIGN]="|=";
tokenNames[QUESTION]="?";
tokenNames[LOR]="||";
tokenNames[LAND]="&&";
tokenNames[BOR]="|";
tokenNames[BXOR]="^";
tokenNames[BAND]="&";
tokenNames[NOT_EQUAL]="!=";
tokenNames[EQUAL]="==";
tokenNames[LT]="<";
tokenNames[GT]=">";
tokenNames[LE]="<=";
tokenNames[GE]=">=";
tokenNames[SL]="<<";
tokenNames[SR]=">>";
tokenNames[BSR]=">>>";
tokenNames[PLUS]="+";
tokenNames[MINUS]="-";
tokenNames[DIV]="/";
tokenNames[MOD]="%";
tokenNames[INC]="++";
tokenNames[DEC]="--";
tokenNames[BNOT]="~";
tokenNames[LNOT]="!";
tokenNames[FINAL]="final";
tokenNames[ABSTRACT]="abstract";
tokenNames[LITERAL_package]="package";
tokenNames[LITERAL_import]="import";
tokenNames[LITERAL_void]="void";
tokenNames[LITERAL_boolean]="boolean";
tokenNames[LITERAL_byte]="byte";
tokenNames[LITERAL_char]="char";
tokenNames[LITERAL_short]="short";
tokenNames[LITERAL_int]="int";
tokenNames[LITERAL_float]="float";
tokenNames[LITERAL_long]="long";
tokenNames[LITERAL_double]="double";
tokenNames[LITERAL_private]="private";
tokenNames[LITERAL_public]="public";
tokenNames[LITERAL_protected]="protected";
tokenNames[LITERAL_static]="static";
tokenNames[LITERAL_transient]="transient";
tokenNames[LITERAL_native]="native";
tokenNames[LITERAL_threadsafe]="threadsafe";
tokenNames[LITERAL_synchronized]="synchronized";
tokenNames[LITERAL_volatile]="volatile";
tokenNames[LITERAL_class]="class";
tokenNames[LITERAL_extends]="extends";
tokenNames[LITERAL_interface]="interface";
tokenNames[LITERAL_implements]="implements";
tokenNames[LITERAL_throws]="throws";
tokenNames[LITERAL_if]="if";
tokenNames[LITERAL_else]="else";
tokenNames[LITERAL_for]="for";
tokenNames[LITERAL_while]="while";
tokenNames[LITERAL_do]="do";
tokenNames[LITERAL_break]="break";
tokenNames[LITERAL_continue]="continue";
tokenNames[LITERAL_return]="return";
tokenNames[LITERAL_switch]="switch";
tokenNames[LITERAL_throw]="throw";
tokenNames[LITERAL_case]="case";
tokenNames[LITERAL_default]="default";
tokenNames[LITERAL_try]="try";
tokenNames[LITERAL_finally]="finally";
tokenNames[LITERAL_catch]="catch";
tokenNames[LITERAL_instanceof]="instanceof";
tokenNames[LITERAL_this]="this";
tokenNames[LITERAL_super]="super";
tokenNames[LITERAL_true]="true";
tokenNames[LITERAL_false]="false";
tokenNames[LITERAL_null]="null";
tokenNames[LITERAL_new]="new";
tokenNames[LITERAL_color]="int"; // PDE specific alias
}
/**
* Specify a PrintStream to print to. System.out is the default.
* @param out the PrintStream to print to
*/
public void setOut(PrintStream out) {
this.out = out;
}
private String name(AST ast) {
return tokenNames[ast.getType()];
}
private String name(int type) {
return tokenNames[type];
}
/**
* Find a child of the given AST that has the given type
* @returns a child AST of the given type. If it can't find a child of the
* given type, return null.
*/
private AST getChild(AST ast, int childType) {
AST child = ast.getFirstChild();
while (child != null) {
if (child.getType() == childType) {
// debug.println("getChild: found:" + name(ast));
return child;
}
child = child.getNextSibling();
}
return null;
}
/**
* Dump the list of hidden tokens linked to after the AST node passed in.
* Most hidden tokens are dumped from this function.
*/
private void dumpHiddenAfter(AST ast) {
dumpHiddenTokens(((antlr.CommonASTWithHiddenTokens)ast).getHiddenAfter());
}
/**
* Dump the list of hidden tokens linked to before the AST node passed in.
* The only time hidden tokens need to be dumped with this function is when
* dealing parts of the tree where automatic tree construction was
* turned off with the ! operator in the grammar file and the nodes were
* manually constructed in such a way that the usual tokens don't have the
* necessary hiddenAfter links.
*/
private void dumpHiddenBefore(AST ast) {
antlr.CommonHiddenStreamToken
child = null,
parent = ((antlr.CommonASTWithHiddenTokens)ast).getHiddenBefore();
// if there aren't any hidden tokens here, quietly return
//
if (parent == null) {
return;
}
// traverse back to the head of the list of tokens before this node
do {
child = parent;
parent = child.getHiddenBefore();
} while (parent != null);
// dump that list
dumpHiddenTokens(child);
}
/**
* Dump the list of hidden tokens linked to from the token passed in.
*/
private void dumpHiddenTokens(antlr.CommonHiddenStreamToken t) {
for ( ; t != null ; t=PdePreprocessor.filter.getHiddenAfter(t) ) {
out.print(t.getText());
}
}
/**
* Print the children of the given AST
* @param ast The AST to print
* @returns true iff anything was printed
*/
private boolean printChildren(AST ast) throws RunnerException {
boolean ret = false;
AST child = ast.getFirstChild();
while (child != null) {
ret = true;
print(child);
child = child.getNextSibling();
}
return ret;
}
/**
* Tells whether an AST has any children or not.
* @return true iff the AST has at least one child
*/
private boolean hasChildren(AST ast) {
return (ast.getFirstChild() != null);
}
/**
* Gets the best node in the subtree for printing. This really means
* the next node which could potentially have hiddenBefore data. It's
* usually the first printable leaf, but not always.
*
* @param includeThisNode Should this node be included in the search?
* If false, only descendants are searched.
*
* @return the first printable leaf node in an AST
*/
private AST getBestPrintableNode(AST ast, boolean includeThisNode) {
AST child;
if (includeThisNode) {
child = ast;
} else {
child = ast.getFirstChild();
}
if (child != null) {
switch (child.getType()) {
// the following node types are printing nodes that print before
// any children, but then also recurse over children. So they
// may have hiddenBefore chains that need to be printed first. Many
// statements and all unary expression types qualify. Return these
// nodes directly
case CLASS_DEF:
case LITERAL_if:
case LITERAL_for:
case LITERAL_while:
case LITERAL_do:
case LITERAL_break:
case LITERAL_continue:
case LITERAL_return:
case LITERAL_switch:
case LITERAL_try:
case LITERAL_throw:
case LITERAL_synchronized:
case LITERAL_assert:
case BNOT:
case LNOT:
case INC:
case DEC:
case UNARY_MINUS:
case UNARY_PLUS:
return child;
// Some non-terminal node types (at the moment, I only know of
// MODIFIERS, but there may be other such types), can be
// leaves in the tree but not have any children. If this is
// such a node, move on to the next sibling.
case MODIFIERS:
if (child.getFirstChild() == null ) {
return getBestPrintableNode(child.getNextSibling(), false);
}
// new jikes doesn't like fallthrough, so just duplicated here:
return getBestPrintableNode(child, false);
default:
return getBestPrintableNode(child, false);
}
}
return ast;
}
/**
* Prints a binary operator
*/
private void printBinaryOperator(AST ast) throws RunnerException {
print(ast.getFirstChild());
out.print(name(ast));
dumpHiddenAfter(ast);
print(ast.getFirstChild().getNextSibling());
}
/**
* Print the given AST. Call this function to print your PDE code.
*
* It works by making recursive calls to print children.
* So the code below is one big "switch" statement on the passed AST type.
*/
public void print (AST ast) throws RunnerException {
if (ast == null) {
return;
}
AST parent = null;
if (!stack.isEmpty()) {
parent = (AST) stack.peek();
}
stack.push(ast);
AST child1 = ast.getFirstChild();
AST child2 = null;
AST child3 = null;
if (child1 != null) {
child2 = child1.getNextSibling();
if (child2 != null) {
child3 = child2.getNextSibling();
}
}
switch(ast.getType()) {
// The top of the tree looks like this:
// ROOT_ID "Whatever.java"
// package
// imports
// class definition
case ROOT_ID:
dumpHiddenTokens(PdePreprocessor.filter.getInitialHiddenToken());
printChildren(ast);
break;
// supporting a "package" statement in a PDE program has
// a bunch of issues with it that need to dealt in the compilation
// code too, so this isn't actually tested.
case PACKAGE_DEF:
out.print("package");
dumpHiddenAfter(ast);
print(ast.getFirstChild());
break;
// IMPORT has exactly one child
case IMPORT:
out.print("import");
dumpHiddenAfter(ast);
print(ast.getFirstChild());
break;
case CLASS_DEF:
case INTERFACE_DEF:
print(getChild(ast, MODIFIERS));
if (ast.getType() == CLASS_DEF) {
out.print("class");
} else {
out.print("interface");
}
dumpHiddenBefore(getChild(ast, IDENT));
print(getChild(ast, IDENT));
print(getChild(ast, EXTENDS_CLAUSE));
print(getChild(ast, IMPLEMENTS_CLAUSE));
print(getChild(ast, OBJBLOCK));
break;
case EXTENDS_CLAUSE:
if (hasChildren(ast)) {
out.print("extends");
dumpHiddenBefore(getBestPrintableNode(ast, false));
printChildren(ast);
}
break;
case IMPLEMENTS_CLAUSE:
if (hasChildren(ast)) {
out.print("implements");
dumpHiddenBefore(getBestPrintableNode(ast, false));
printChildren(ast);
}
break;
// DOT always has exactly two children.
case DOT:
print(child1);
out.print(".");
dumpHiddenAfter(ast);
print(child2);
break;
case MODIFIERS:
case OBJBLOCK:
case CTOR_DEF:
//case METHOD_DEF:
case PARAMETERS:
case PARAMETER_DEF:
case VARIABLE_DEF:
case TYPE:
case SLIST:
case ELIST:
case ARRAY_DECLARATOR:
case TYPECAST:
case EXPR:
case ARRAY_INIT:
case FOR_INIT:
case FOR_CONDITION:
case FOR_ITERATOR:
case METHOD_CALL:
case INSTANCE_INIT:
case INDEX_OP:
case SUPER_CTOR_CALL:
case CTOR_CALL:
printChildren(ast);
break;
case METHOD_DEF:
// kids seem to be: MODIFIERS TYPE setup PARAMETERS
//AST parent = (AST) stack.peek();
AST modifiersChild = ast.getFirstChild();
AST typeChild = modifiersChild.getNextSibling();
AST methodNameChild = typeChild.getNextSibling();
AST parametersChild = methodNameChild.getNextSibling();
// to output, use print(child) on each of the four
/*
// 1. figure out if this is setup, draw, or loop
String methodName = methodNameChild.getText();
if (publicMethods.get(methodName) != null) {
// make sure this feller is public
boolean foundPublic = false;
AST child = modifiersChild.getFirstChild();
while (child != null) {
if (child.getText().equals("public")) {
foundPublic = true;
child = null;
} else {
//out.print("." + child.getText() + ".");
child = child.getNextSibling();
}
}
if (!foundPublic) {
out.print("public ");
}
*/
// if this method doesn't have a specifier, make it public
// (useful for setup/keyPressed/etc)
boolean foundSpecifier = false;
AST child = modifiersChild.getFirstChild();
while (child != null) {
String childText = child.getText();
if (childText.equals("public") ||
childText.equals("protected") ||
childText.equals("private")) {
foundSpecifier = true;
child = null;
} else {
//out.print("." + child.getText() + ".");
child = child.getNextSibling();
}
}
if (!foundSpecifier) {
out.print("public ");
}
printChildren(ast); // everything is fine
break;
// if we have two children, it's of the form "a=0"
// if just one child, it's of the form "=0" (where the
// lhs is above this AST).
case ASSIGN:
if (child2 != null) {
print(child1);
out.print("=");
dumpHiddenAfter(ast);
print(child2);
}
else {
out.print("=");
dumpHiddenAfter(ast);
print(child1);
}
break;
// binary operators:
case PLUS:
case MINUS:
case DIV:
case MOD:
case NOT_EQUAL:
case EQUAL:
case LT:
case GT:
case LE:
case GE:
case LOR:
case LAND:
case BOR:
case BXOR:
case BAND:
case SL:
case SR:
case BSR:
case LITERAL_instanceof:
case PLUS_ASSIGN:
case MINUS_ASSIGN:
case STAR_ASSIGN:
case DIV_ASSIGN:
case MOD_ASSIGN:
case SR_ASSIGN:
case BSR_ASSIGN:
case SL_ASSIGN:
case BAND_ASSIGN:
case BXOR_ASSIGN:
case BOR_ASSIGN:
printBinaryOperator(ast);
break;
case LITERAL_for:
out.print(name(ast));
dumpHiddenAfter(ast);
printChildren(ast);
break;
case POST_INC:
case POST_DEC:
print(child1);
out.print(name(ast));
dumpHiddenAfter(ast);
break;
// unary operators:
case BNOT:
case LNOT:
case INC:
case DEC:
case UNARY_MINUS:
case UNARY_PLUS:
out.print(name(ast));
dumpHiddenAfter(ast);
print(child1);
break;
case LITERAL_new:
out.print("new");
dumpHiddenAfter(ast);
print(child1);
print(child2);
// "new String[] {...}": the stuff in {} is child3
if (child3 != null) {
print(child3);
}
break;
case LITERAL_return:
out.print("return");
dumpHiddenAfter(ast);
print(child1);
break;
case STATIC_INIT:
out.print("static");
dumpHiddenBefore(getBestPrintableNode(ast, false));
print(child1);
break;
case LITERAL_switch:
out.print("switch");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case CASE_GROUP:
printChildren(ast);
break;
case LITERAL_case:
out.print("case");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case LITERAL_default:
out.print("default");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case NUM_INT:
case CHAR_LITERAL:
case STRING_LITERAL:
case NUM_FLOAT:
out.print(ast.getText());
dumpHiddenAfter(ast);
break;
case LITERAL_private:
case LITERAL_public:
case LITERAL_protected:
case LITERAL_static:
case LITERAL_transient:
case LITERAL_native:
case LITERAL_threadsafe:
case LITERAL_synchronized:
case LITERAL_volatile:
case FINAL:
case ABSTRACT:
case LITERAL_package:
case LITERAL_void:
case LITERAL_boolean:
case LITERAL_byte:
case LITERAL_char:
case LITERAL_short:
case LITERAL_int:
case LITERAL_float:
case LITERAL_long:
case LITERAL_double:
case LITERAL_true:
case LITERAL_false:
case LITERAL_null:
case SEMI:
case LITERAL_this:
case LITERAL_super:
case LITERAL_continue:
case LITERAL_break:
out.print(name(ast));
dumpHiddenAfter(ast);
break;
case EMPTY_STAT:
case EMPTY_FIELD:
break;
// yuck: Distinguish between "import x.y.*" and "x = 1 * 3"
case STAR:
if (hasChildren(ast)) { // the binary mult. operator
printBinaryOperator(ast);
}
else { // the special "*" in import:
out.print("*");
dumpHiddenAfter(ast);
}
break;
case LITERAL_throws:
out.print("throws");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case LITERAL_if:
out.print("if");
dumpHiddenAfter(ast);
print(child1); // the "if" condition: an EXPR
print(child2); // the "then" clause is an SLIST
if (child3 != null) {
out.print("else");
dumpHiddenBefore(getBestPrintableNode(child3, true));
print(child3); // optional "else" clause: an SLIST
}
break;
case LITERAL_while:
out.print("while");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case LITERAL_do:
out.print("do");
dumpHiddenAfter(ast);
print(child1); // an SLIST
out.print("while");
dumpHiddenBefore(getBestPrintableNode(child2, false));
print(child2); // an EXPR
break;
case LITERAL_try:
out.print("try");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case LITERAL_catch:
out.print("catch");
dumpHiddenAfter(ast);
printChildren(ast);
break;
// the first child is the "try" and the second is the SLIST
case LITERAL_finally:
out.print("finally");
dumpHiddenAfter(ast);
printChildren(ast);
break;
case LITERAL_throw:
out.print("throw");
dumpHiddenAfter(ast);
print(child1);
break;
// the dreaded trinary operator
case QUESTION:
print(child1);
out.print("?");
dumpHiddenAfter(ast);
print(child2);
print(child3);
break;
// pde specific or modified tokens start here
// Image -> BImage, Font -> BFont as appropriate
case IDENT:
/*
if (ast.getText().equals("Image") &&
Preferences.getBoolean("preproc.substitute_image")) { //, true)) {
out.print("BImage");
} else if (ast.getText().equals("Font") &&
Preferences.getBoolean("preproc.substitute_font")) { //, true)) {
out.print("BFont");
} else {
*/
out.print(ast.getText());
//}
dumpHiddenAfter(ast);
break;
// the color datatype is just an alias for int
case LITERAL_color:
out.print("int");
dumpHiddenAfter(ast);
break;
case WEBCOLOR_LITERAL:
if (ast.getText().length() != 6) {
System.err.println("Internal error: incorrect length of webcolor " +
"literal should have been detected sooner.");
break;
}
out.print("0xff" + ast.getText());
dumpHiddenAfter(ast);
break;
// allow for stuff like int(43.2).
case CONSTRUCTOR_CAST:
AST nonTerminalTypeNode = child1;
AST terminalTypeNode = child1.getFirstChild();
AST exprToCast = child2;
/*
// if this is a string type, add .valueOf()
if (nonTerminalTypeNode.getType() == PdeRecognizer.TYPE &&
terminalTypeNode.getText().equals("String")) {
out.print(terminalTypeNode.getText() + ".valueOf");
dumpHiddenAfter(terminalTypeNode);
print(exprToCast);
// if the expresion to be cast is a string literal, try and parse it.
//
// ideally, we'd be able to do this for all expressions with a
// string type, not just string literals. however, the parser
// doesn't currently track expression type, and for full
// functionality, we'd need to do semantic analysis to handle
// imports so that we could know the return types of method calls.
//
} else if (exprToCast.getFirstChild().getType() == STRING_LITERAL ) {
switch (terminalTypeNode.getType()) {
case PdeRecognizer.LITERAL_byte:
out.print("Byte.parseByte");
dumpHiddenAfter(terminalTypeNode);
print(exprToCast);
break;
case PdeRecognizer.LITERAL_double:
out.print("(new Double");
dumpHiddenAfter(terminalTypeNode);
out.print(exprToCast.getFirstChild().getText() + ").doubleValue()");
dumpHiddenAfter(exprToCast.getFirstChild());
break;
case PdeRecognizer.LITERAL_float:
out.print("(new Float");
dumpHiddenAfter(terminalTypeNode);
out.print(exprToCast.getFirstChild().getText() + ").floatValue()");
dumpHiddenAfter(exprToCast.getFirstChild());
break;
case PdeRecognizer.LITERAL_int:
case PdeRecognizer.LITERAL_color:
out.print("Integer.parseInt");
dumpHiddenAfter(terminalTypeNode);
print(exprToCast);
break;
case PdeRecognizer.LITERAL_long:
out.print("Long.parseLong");
break;
case PdeRecognizer.LITERAL_short:
out.print("Short.parseShort");
break;
default:
throw new RunnerException(Compiler.SUPER_BADNESS);
}
// for builtin types, use regular casting syntax
} else {
*/
// result of below is (int)(4.0
//out.print("(");
//out.print(terminalTypeNode.getText() + ")"); // typename
//dumpHiddenAfter(terminalTypeNode);
//print(exprToCast);
//}
//out.print("(");
String pooType = terminalTypeNode.getText();
out.print("PApplet.to" +
Character.toUpperCase(pooType.charAt(0)) +
pooType.substring(1));
dumpHiddenAfter(terminalTypeNode); // the left paren
print(exprToCast);
//out.print("x)");
break;
// making floating point literals default to floats, not doubles
case NUM_DOUBLE:
out.print(ast.getText());
if (Preferences.getBoolean("preproc.substitute_floats")) { //, true) ) {
out.print("f");
}
dumpHiddenAfter(ast);
break;
default:
debug.println("Invalid type:" + ast.getType());
break;
/* The following are tokens, but I don't think JavaRecognizer
ever produces an AST with one of these types:
case COMMA:
case LITERAL_implements:
case LITERAL_class:
case LITERAL_extends:
case EOF:
case NULL_TREE_LOOKAHEAD:
case BLOCK:
case LABELED_STAT: // refuse to implement on moral grounds :)
case LITERAL_import:
case LBRACK:
case RBRACK:
case LCURLY:
case RCURLY:
case LPAREN:
case RPAREN:
case LITERAL_else: // else is a child of "if" AST
case COLON: // part of the trinary operator
case WS: // whitespace
case ESC:
case HEX_DIGIT:
case VOCAB:
case EXPONENT: // exponents and float suffixes are left in the NUM_FLOAT
case FLOAT_SUFFIX
*/
}
stack.pop();
}
}

View File

@ -1,163 +0,0 @@
// $ANTLR 2.7.2: "expandedpde.g" -> "PdeRecognizer.java"$
package processing.app.preproc;
import processing.app.*;
public interface PdePartialTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int BLOCK = 4;
int MODIFIERS = 5;
int OBJBLOCK = 6;
int SLIST = 7;
int CTOR_DEF = 8;
int METHOD_DEF = 9;
int VARIABLE_DEF = 10;
int INSTANCE_INIT = 11;
int STATIC_INIT = 12;
int TYPE = 13;
int CLASS_DEF = 14;
int INTERFACE_DEF = 15;
int PACKAGE_DEF = 16;
int ARRAY_DECLARATOR = 17;
int EXTENDS_CLAUSE = 18;
int IMPLEMENTS_CLAUSE = 19;
int PARAMETERS = 20;
int PARAMETER_DEF = 21;
int LABELED_STAT = 22;
int TYPECAST = 23;
int INDEX_OP = 24;
int POST_INC = 25;
int POST_DEC = 26;
int METHOD_CALL = 27;
int EXPR = 28;
int ARRAY_INIT = 29;
int IMPORT = 30;
int UNARY_MINUS = 31;
int UNARY_PLUS = 32;
int CASE_GROUP = 33;
int ELIST = 34;
int FOR_INIT = 35;
int FOR_CONDITION = 36;
int FOR_ITERATOR = 37;
int EMPTY_STAT = 38;
int FINAL = 39;
int ABSTRACT = 40;
int STRICTFP = 41;
int SUPER_CTOR_CALL = 42;
int CTOR_CALL = 43;
int LITERAL_package = 44;
int SEMI = 45;
int LITERAL_import = 46;
int LBRACK = 47;
int RBRACK = 48;
int LITERAL_void = 49;
int LITERAL_boolean = 50;
int LITERAL_byte = 51;
int LITERAL_char = 52;
int LITERAL_short = 53;
int LITERAL_int = 54;
int LITERAL_float = 55;
int LITERAL_long = 56;
int LITERAL_double = 57;
int IDENT = 58;
int DOT = 59;
int STAR = 60;
int LITERAL_private = 61;
int LITERAL_public = 62;
int LITERAL_protected = 63;
int LITERAL_static = 64;
int LITERAL_transient = 65;
int LITERAL_native = 66;
int LITERAL_threadsafe = 67;
int LITERAL_synchronized = 68;
int LITERAL_volatile = 69;
int LITERAL_class = 70;
int LITERAL_extends = 71;
int LITERAL_interface = 72;
int LCURLY = 73;
int RCURLY = 74;
int COMMA = 75;
int LITERAL_implements = 76;
int LPAREN = 77;
int RPAREN = 78;
int LITERAL_this = 79;
int LITERAL_super = 80;
int ASSIGN = 81;
int LITERAL_throws = 82;
int COLON = 83;
int LITERAL_if = 84;
int LITERAL_else = 85;
int LITERAL_for = 86;
int LITERAL_while = 87;
int LITERAL_do = 88;
int LITERAL_break = 89;
int LITERAL_continue = 90;
int LITERAL_return = 91;
int LITERAL_switch = 92;
int LITERAL_throw = 93;
int LITERAL_assert = 94;
int LITERAL_case = 95;
int LITERAL_default = 96;
int LITERAL_try = 97;
int LITERAL_finally = 98;
int LITERAL_catch = 99;
int PLUS_ASSIGN = 100;
int MINUS_ASSIGN = 101;
int STAR_ASSIGN = 102;
int DIV_ASSIGN = 103;
int MOD_ASSIGN = 104;
int SR_ASSIGN = 105;
int BSR_ASSIGN = 106;
int SL_ASSIGN = 107;
int BAND_ASSIGN = 108;
int BXOR_ASSIGN = 109;
int BOR_ASSIGN = 110;
int QUESTION = 111;
int LOR = 112;
int LAND = 113;
int BOR = 114;
int BXOR = 115;
int BAND = 116;
int NOT_EQUAL = 117;
int EQUAL = 118;
int LT = 119;
int GT = 120;
int LE = 121;
int GE = 122;
int LITERAL_instanceof = 123;
int SL = 124;
int SR = 125;
int BSR = 126;
int PLUS = 127;
int MINUS = 128;
int DIV = 129;
int MOD = 130;
int INC = 131;
int DEC = 132;
int BNOT = 133;
int LNOT = 134;
int LITERAL_true = 135;
int LITERAL_false = 136;
int LITERAL_null = 137;
int LITERAL_new = 138;
int NUM_INT = 139;
int CHAR_LITERAL = 140;
int STRING_LITERAL = 141;
int NUM_FLOAT = 142;
int NUM_LONG = 143;
int NUM_DOUBLE = 144;
int WS = 145;
int SL_COMMENT = 146;
int ML_COMMENT = 147;
int ESC = 148;
int HEX_DIGIT = 149;
int VOCAB = 150;
int EXPONENT = 151;
int FLOAT_SUFFIX = 152;
int CONSTRUCTOR_CAST = 153;
int EMPTY_FIELD = 154;
int WEBCOLOR_LITERAL = 155;
int LITERAL_color = 156;
}

View File

@ -1,155 +0,0 @@
// $ANTLR 2.7.2: expandedpde.g -> PdePartialTokenTypes.txt$
PdePartial // output token vocab name
BLOCK=4
MODIFIERS=5
OBJBLOCK=6
SLIST=7
CTOR_DEF=8
METHOD_DEF=9
VARIABLE_DEF=10
INSTANCE_INIT=11
STATIC_INIT=12
TYPE=13
CLASS_DEF=14
INTERFACE_DEF=15
PACKAGE_DEF=16
ARRAY_DECLARATOR=17
EXTENDS_CLAUSE=18
IMPLEMENTS_CLAUSE=19
PARAMETERS=20
PARAMETER_DEF=21
LABELED_STAT=22
TYPECAST=23
INDEX_OP=24
POST_INC=25
POST_DEC=26
METHOD_CALL=27
EXPR=28
ARRAY_INIT=29
IMPORT=30
UNARY_MINUS=31
UNARY_PLUS=32
CASE_GROUP=33
ELIST=34
FOR_INIT=35
FOR_CONDITION=36
FOR_ITERATOR=37
EMPTY_STAT=38
FINAL="final"=39
ABSTRACT="abstract"=40
STRICTFP="strictfp"=41
SUPER_CTOR_CALL=42
CTOR_CALL=43
LITERAL_package="package"=44
SEMI=45
LITERAL_import="import"=46
LBRACK=47
RBRACK=48
LITERAL_void="void"=49
LITERAL_boolean="boolean"=50
LITERAL_byte="byte"=51
LITERAL_char="char"=52
LITERAL_short="short"=53
LITERAL_int="int"=54
LITERAL_float="float"=55
LITERAL_long="long"=56
LITERAL_double="double"=57
IDENT=58
DOT=59
STAR=60
LITERAL_private="private"=61
LITERAL_public="public"=62
LITERAL_protected="protected"=63
LITERAL_static="static"=64
LITERAL_transient="transient"=65
LITERAL_native="native"=66
LITERAL_threadsafe="threadsafe"=67
LITERAL_synchronized="synchronized"=68
LITERAL_volatile="volatile"=69
LITERAL_class="class"=70
LITERAL_extends="extends"=71
LITERAL_interface="interface"=72
LCURLY=73
RCURLY=74
COMMA=75
LITERAL_implements="implements"=76
LPAREN=77
RPAREN=78
LITERAL_this="this"=79
LITERAL_super="super"=80
ASSIGN=81
LITERAL_throws="throws"=82
COLON=83
LITERAL_if="if"=84
LITERAL_else="else"=85
LITERAL_for="for"=86
LITERAL_while="while"=87
LITERAL_do="do"=88
LITERAL_break="break"=89
LITERAL_continue="continue"=90
LITERAL_return="return"=91
LITERAL_switch="switch"=92
LITERAL_throw="throw"=93
LITERAL_assert="assert"=94
LITERAL_case="case"=95
LITERAL_default="default"=96
LITERAL_try="try"=97
LITERAL_finally="finally"=98
LITERAL_catch="catch"=99
PLUS_ASSIGN=100
MINUS_ASSIGN=101
STAR_ASSIGN=102
DIV_ASSIGN=103
MOD_ASSIGN=104
SR_ASSIGN=105
BSR_ASSIGN=106
SL_ASSIGN=107
BAND_ASSIGN=108
BXOR_ASSIGN=109
BOR_ASSIGN=110
QUESTION=111
LOR=112
LAND=113
BOR=114
BXOR=115
BAND=116
NOT_EQUAL=117
EQUAL=118
LT=119
GT=120
LE=121
GE=122
LITERAL_instanceof="instanceof"=123
SL=124
SR=125
BSR=126
PLUS=127
MINUS=128
DIV=129
MOD=130
INC=131
DEC=132
BNOT=133
LNOT=134
LITERAL_true="true"=135
LITERAL_false="false"=136
LITERAL_null="null"=137
LITERAL_new="new"=138
NUM_INT=139
CHAR_LITERAL=140
STRING_LITERAL=141
NUM_FLOAT=142
NUM_LONG=143
NUM_DOUBLE=144
WS=145
SL_COMMENT=146
ML_COMMENT=147
ESC=148
HEX_DIGIT=149
VOCAB=150
EXPONENT=151
FLOAT_SUFFIX=152
CONSTRUCTOR_CAST=153
EMPTY_FIELD=154
WEBCOLOR_LITERAL=155
LITERAL_color="color"=156

135
app/preproc/PdePreprocessor.java Normal file → Executable file
View File

@ -2,9 +2,11 @@
/*
PdePreprocessor - wrapper for default ANTLR-generated parser
Part of the Processing project - http://processing.org
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-05 Ben Fry and Casey Reas
Copyright (c) 2004-05 Hernando Barragan
Processing version Copyright (c) 2004-05 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
ANTLR-generated parser and several supporting classes written
@ -68,26 +70,28 @@ public class PdePreprocessor {
// used for calling the ASTFactory to get the root node
private static final int ROOT_ID = 0;
// stores number of built user-defined function prototypes
public int prototypeCount = 0;
/**
* These may change in-between (if the prefs panel adds this option)
* so grab them here on construction.
*/
public PdePreprocessor() {
defaultImports[JDK11] =
/* defaultImports[JDK11] =
Base.split(Preferences.get("preproc.imports.jdk11"), ',');
defaultImports[JDK13] =
Base.split(Preferences.get("preproc.imports.jdk13"), ',');
defaultImports[JDK14] =
Base.split(Preferences.get("preproc.imports.jdk14"), ',');
}
*/ }
/**
* Used by PdeEmitter.dumpHiddenTokens()
*/
public static TokenStreamCopyingHiddenTokenFilter filter;
//public static TokenStreamCopyingHiddenTokenFilter filter;
/**
@ -159,6 +163,7 @@ public class PdePreprocessor {
return null;
}
/*
do {
PatternMatcherInput input = new PatternMatcherInput(program);
if (!matcher.contains(input, pattern)) break;
@ -179,6 +184,7 @@ public class PdePreprocessor {
//System.out.println("removing " + piece);
} while (true);
*/
extraImports = new String[imports.size()];
imports.copyInto(extraImports);
@ -215,43 +221,85 @@ public class PdePreprocessor {
// do this after the program gets re-combobulated
this.programReader = new StringReader(program);
this.buildPath = buildPath;
// create function prototypes
mess = "^(\\w+)\\s+(\\w+)\\s*\\(([^)]*)\\)\\s*{";
pattern = null;
try {
pattern = compiler.compile(mess);
} catch (MalformedPatternException e) {
e.printStackTrace();
return null;
}
PatternMatcherInput input = new PatternMatcherInput(program);
MatchResult result;
String returntype, functioname, parameterlist, prototype;
java.util.LinkedList prototypes = new java.util.LinkedList();
//System.out.println("prototypes:");
if (Preferences.get("build.extension").equals("cpp")) {
while(matcher.contains(input, pattern)){
result = matcher.getMatch();
//System.out.println(result);
returntype = result.group(1).toString();
functioname = result.group(2).toString();
parameterlist = result.group(3).toString().replace('\n', ' ');
prototype = returntype + " " + functioname + "(" + parameterlist + ");";
if(0 == functioname.compareTo("setup")){
continue;
}
if(0 == functioname.compareTo("loop")){
continue;
}
prototypes.add(prototype);
//System.out.println(prototype);
}
}
// store # of prototypes so that line number reporting can be adjusted
prototypeCount = prototypes.size();
// create a lexer with the stream reader, and tell it to handle
// hidden tokens (eg whitespace, comments) since we want to pass these
// through so that the line numbers when the compiler reports errors
// match those that will be highlighted in the PDE IDE
//
PdeLexer lexer = new PdeLexer(programReader);
lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
WLexer lexer = new WLexer(programReader);
//lexer.setTokenObjectClass("antlr.CommonHiddenStreamToken");
lexer.setTokenObjectClass("processing.app.preproc.CToken");
lexer.initialize();
// create the filter for hidden tokens and specify which tokens to
// hide and which to copy to the hidden text
//
filter = new TokenStreamCopyingHiddenTokenFilter(lexer);
filter.hide(PdeRecognizer.SL_COMMENT);
filter.hide(PdeRecognizer.ML_COMMENT);
filter.hide(PdeRecognizer.WS);
filter.copy(PdeRecognizer.SEMI);
filter.copy(PdeRecognizer.LPAREN);
filter.copy(PdeRecognizer.RPAREN);
filter.copy(PdeRecognizer.LCURLY);
filter.copy(PdeRecognizer.RCURLY);
filter.copy(PdeRecognizer.COMMA);
filter.copy(PdeRecognizer.RBRACK);
filter.copy(PdeRecognizer.LBRACK);
filter.copy(PdeRecognizer.COLON);
/*filter = new TokenStreamCopyingHiddenTokenFilter(lexer);
filter.hide(WParser.CPPComment);
filter.hide(WParser.Comment);
filter.hide(WParser.Whitespace);
filter.copy(WParser.SEMI);
filter.copy(WParser.LPAREN);
filter.copy(WParser.RPAREN);
filter.copy(WParser.LCURLY);
filter.copy(WParser.RCURLY);
filter.copy(WParser.COMMA);
filter.copy(WParser.RBRACK);
filter.copy(WParser.LBRACK);
filter.copy(WParser.COLON);
*/
// create a parser and set what sort of AST should be generated
//
PdeRecognizer parser = new PdeRecognizer(filter);
//PdeRecognizer parser = new PdeRecognizer(filter);
WParser parser = new WParser(lexer);
// use our extended AST class
//
parser.setASTNodeClass("antlr.ExtendedCommonASTWithHiddenTokens");
//parser.setASTNodeClass("antlr.ExtendedCommonASTWithHiddenTokens");
parser.setASTNodeType(TNode.class.getName());
TNode.setTokenVocabulary("processing.app.preproc.WTokenTypes");
// start parsing at the compilationUnit non-terminal
//
parser.pdeProgram();
//parser.pdeProgram();
parser.translationUnit();
// set up the AST for traversal by PdeEmitter
//
@ -280,15 +328,17 @@ public class PdePreprocessor {
// output the code
//
PdeEmitter emitter = new PdeEmitter();
File streamFile = new File(buildPath, name + ".java");
WEmitter emitter = new WEmitter(lexer.getPreprocessorInfoChannel());
File streamFile = new File(buildPath, name + "." + Preferences.get("build.extension"));
PrintStream stream = new PrintStream(new FileOutputStream(streamFile));
//writeHeader(stream, extraImports, name);
writeHeader(stream, name);
writeHeader(stream, name, prototypes);
emitter.setASTNodeType(TNode.class.getName());
emitter.setOut(stream);
emitter.print(rootNode);
emitter.printDeclarations(rootNode);
//emitter.print(rootNode);
emitter.translationUnit(parser.getAST());
writeFooter(stream);
stream.close();
@ -313,7 +363,6 @@ public class PdePreprocessor {
return name;
}
/**
* Write any required header material (eg imports, class decl stuff)
*
@ -321,15 +370,18 @@ public class PdePreprocessor {
* @param exporting Is this being exported from PDE?
* @param name Name of the class being created.
*/
void writeHeader(PrintStream out, String className) {
void writeHeader(PrintStream out, String className, java.util.LinkedList prototypes) {
out.print("#include \"WProgram.h\"\n");
// must include processing.core
out.print("import processing.core.*; ");
// print user defined prototypes
while(0 < prototypes.size()){
out.print(prototypes.removeFirst() + "\n");
}
// emit emports that are needed for classes from the code folder
if (extraImports != null) {
for (int i = 0; i < extraImports.length; i++) {
out.print("import " + extraImports[i] + "; ");
out.print("#include \"" + extraImports[i] + "\"\n");
}
}
@ -341,7 +393,7 @@ public class PdePreprocessor {
// emit standard imports (read from pde.properties)
// for each language level that's being used.
String jdkVersionStr = Preferences.get("preproc.jdk_version");
/* String jdkVersionStr = Preferences.get("preproc.jdk_version");
int jdkVersion = JDK11; // default
if (jdkVersionStr.equals("1.3")) { jdkVersion = JDK13; };
@ -357,8 +409,8 @@ public class PdePreprocessor {
//if (opengl) {
//out.println("import processing.opengl.*; ");
//}
if (programType < JAVA) {
*/
/* if (programType < JAVA) {
// open the class definition
out.print("public class " + className + " extends ");
//if (opengl) {
@ -377,7 +429,7 @@ public class PdePreprocessor {
out.print("public void setup() {");
}
}
}
*/ }
/**
* Write any necessary closing text.
@ -385,8 +437,9 @@ public class PdePreprocessor {
* @param out PrintStream to write it to.
*/
void writeFooter(PrintStream out) {
//out.print("}");
if (programType == STATIC) {
/* if (programType == STATIC) {
// close off draw() definition
out.print("noLoop(); ");
out.print("}");
@ -396,7 +449,7 @@ public class PdePreprocessor {
// close off the class definition
out.print("}");
}
}
*/ }
static String advClassName = "";

File diff suppressed because it is too large Load Diff

View File

@ -1,163 +0,0 @@
// $ANTLR 2.7.2: "expandedpde.g" -> "PdeRecognizer.java"$
package processing.app.preproc;
import processing.app.*;
public interface PdeTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int BLOCK = 4;
int MODIFIERS = 5;
int OBJBLOCK = 6;
int SLIST = 7;
int CTOR_DEF = 8;
int METHOD_DEF = 9;
int VARIABLE_DEF = 10;
int INSTANCE_INIT = 11;
int STATIC_INIT = 12;
int TYPE = 13;
int CLASS_DEF = 14;
int INTERFACE_DEF = 15;
int PACKAGE_DEF = 16;
int ARRAY_DECLARATOR = 17;
int EXTENDS_CLAUSE = 18;
int IMPLEMENTS_CLAUSE = 19;
int PARAMETERS = 20;
int PARAMETER_DEF = 21;
int LABELED_STAT = 22;
int TYPECAST = 23;
int INDEX_OP = 24;
int POST_INC = 25;
int POST_DEC = 26;
int METHOD_CALL = 27;
int EXPR = 28;
int ARRAY_INIT = 29;
int IMPORT = 30;
int UNARY_MINUS = 31;
int UNARY_PLUS = 32;
int CASE_GROUP = 33;
int ELIST = 34;
int FOR_INIT = 35;
int FOR_CONDITION = 36;
int FOR_ITERATOR = 37;
int EMPTY_STAT = 38;
int FINAL = 39;
int ABSTRACT = 40;
int STRICTFP = 41;
int SUPER_CTOR_CALL = 42;
int CTOR_CALL = 43;
int LITERAL_package = 44;
int SEMI = 45;
int LITERAL_import = 46;
int LBRACK = 47;
int RBRACK = 48;
int LITERAL_void = 49;
int LITERAL_boolean = 50;
int LITERAL_byte = 51;
int LITERAL_char = 52;
int LITERAL_short = 53;
int LITERAL_int = 54;
int LITERAL_float = 55;
int LITERAL_long = 56;
int LITERAL_double = 57;
int IDENT = 58;
int DOT = 59;
int STAR = 60;
int LITERAL_private = 61;
int LITERAL_public = 62;
int LITERAL_protected = 63;
int LITERAL_static = 64;
int LITERAL_transient = 65;
int LITERAL_native = 66;
int LITERAL_threadsafe = 67;
int LITERAL_synchronized = 68;
int LITERAL_volatile = 69;
int LITERAL_class = 70;
int LITERAL_extends = 71;
int LITERAL_interface = 72;
int LCURLY = 73;
int RCURLY = 74;
int COMMA = 75;
int LITERAL_implements = 76;
int LPAREN = 77;
int RPAREN = 78;
int LITERAL_this = 79;
int LITERAL_super = 80;
int ASSIGN = 81;
int LITERAL_throws = 82;
int COLON = 83;
int LITERAL_if = 84;
int LITERAL_else = 85;
int LITERAL_for = 86;
int LITERAL_while = 87;
int LITERAL_do = 88;
int LITERAL_break = 89;
int LITERAL_continue = 90;
int LITERAL_return = 91;
int LITERAL_switch = 92;
int LITERAL_throw = 93;
int LITERAL_assert = 94;
int LITERAL_case = 95;
int LITERAL_default = 96;
int LITERAL_try = 97;
int LITERAL_finally = 98;
int LITERAL_catch = 99;
int PLUS_ASSIGN = 100;
int MINUS_ASSIGN = 101;
int STAR_ASSIGN = 102;
int DIV_ASSIGN = 103;
int MOD_ASSIGN = 104;
int SR_ASSIGN = 105;
int BSR_ASSIGN = 106;
int SL_ASSIGN = 107;
int BAND_ASSIGN = 108;
int BXOR_ASSIGN = 109;
int BOR_ASSIGN = 110;
int QUESTION = 111;
int LOR = 112;
int LAND = 113;
int BOR = 114;
int BXOR = 115;
int BAND = 116;
int NOT_EQUAL = 117;
int EQUAL = 118;
int LT = 119;
int GT = 120;
int LE = 121;
int GE = 122;
int LITERAL_instanceof = 123;
int SL = 124;
int SR = 125;
int BSR = 126;
int PLUS = 127;
int MINUS = 128;
int DIV = 129;
int MOD = 130;
int INC = 131;
int DEC = 132;
int BNOT = 133;
int LNOT = 134;
int LITERAL_true = 135;
int LITERAL_false = 136;
int LITERAL_null = 137;
int LITERAL_new = 138;
int NUM_INT = 139;
int CHAR_LITERAL = 140;
int STRING_LITERAL = 141;
int NUM_FLOAT = 142;
int NUM_LONG = 143;
int NUM_DOUBLE = 144;
int WS = 145;
int SL_COMMENT = 146;
int ML_COMMENT = 147;
int ESC = 148;
int HEX_DIGIT = 149;
int VOCAB = 150;
int EXPONENT = 151;
int FLOAT_SUFFIX = 152;
int CONSTRUCTOR_CAST = 153;
int EMPTY_FIELD = 154;
int WEBCOLOR_LITERAL = 155;
int LITERAL_color = 156;
}

View File

@ -1,155 +0,0 @@
// $ANTLR 2.7.2: expandedpde.g -> PdeTokenTypes.txt$
Pde // output token vocab name
BLOCK=4
MODIFIERS=5
OBJBLOCK=6
SLIST=7
CTOR_DEF=8
METHOD_DEF=9
VARIABLE_DEF=10
INSTANCE_INIT=11
STATIC_INIT=12
TYPE=13
CLASS_DEF=14
INTERFACE_DEF=15
PACKAGE_DEF=16
ARRAY_DECLARATOR=17
EXTENDS_CLAUSE=18
IMPLEMENTS_CLAUSE=19
PARAMETERS=20
PARAMETER_DEF=21
LABELED_STAT=22
TYPECAST=23
INDEX_OP=24
POST_INC=25
POST_DEC=26
METHOD_CALL=27
EXPR=28
ARRAY_INIT=29
IMPORT=30
UNARY_MINUS=31
UNARY_PLUS=32
CASE_GROUP=33
ELIST=34
FOR_INIT=35
FOR_CONDITION=36
FOR_ITERATOR=37
EMPTY_STAT=38
FINAL="final"=39
ABSTRACT="abstract"=40
STRICTFP="strictfp"=41
SUPER_CTOR_CALL=42
CTOR_CALL=43
LITERAL_package="package"=44
SEMI=45
LITERAL_import="import"=46
LBRACK=47
RBRACK=48
LITERAL_void="void"=49
LITERAL_boolean="boolean"=50
LITERAL_byte="byte"=51
LITERAL_char="char"=52
LITERAL_short="short"=53
LITERAL_int="int"=54
LITERAL_float="float"=55
LITERAL_long="long"=56
LITERAL_double="double"=57
IDENT=58
DOT=59
STAR=60
LITERAL_private="private"=61
LITERAL_public="public"=62
LITERAL_protected="protected"=63
LITERAL_static="static"=64
LITERAL_transient="transient"=65
LITERAL_native="native"=66
LITERAL_threadsafe="threadsafe"=67
LITERAL_synchronized="synchronized"=68
LITERAL_volatile="volatile"=69
LITERAL_class="class"=70
LITERAL_extends="extends"=71
LITERAL_interface="interface"=72
LCURLY=73
RCURLY=74
COMMA=75
LITERAL_implements="implements"=76
LPAREN=77
RPAREN=78
LITERAL_this="this"=79
LITERAL_super="super"=80
ASSIGN=81
LITERAL_throws="throws"=82
COLON=83
LITERAL_if="if"=84
LITERAL_else="else"=85
LITERAL_for="for"=86
LITERAL_while="while"=87
LITERAL_do="do"=88
LITERAL_break="break"=89
LITERAL_continue="continue"=90
LITERAL_return="return"=91
LITERAL_switch="switch"=92
LITERAL_throw="throw"=93
LITERAL_assert="assert"=94
LITERAL_case="case"=95
LITERAL_default="default"=96
LITERAL_try="try"=97
LITERAL_finally="finally"=98
LITERAL_catch="catch"=99
PLUS_ASSIGN=100
MINUS_ASSIGN=101
STAR_ASSIGN=102
DIV_ASSIGN=103
MOD_ASSIGN=104
SR_ASSIGN=105
BSR_ASSIGN=106
SL_ASSIGN=107
BAND_ASSIGN=108
BXOR_ASSIGN=109
BOR_ASSIGN=110
QUESTION=111
LOR=112
LAND=113
BOR=114
BXOR=115
BAND=116
NOT_EQUAL=117
EQUAL=118
LT=119
GT=120
LE=121
GE=122
LITERAL_instanceof="instanceof"=123
SL=124
SR=125
BSR=126
PLUS=127
MINUS=128
DIV=129
MOD=130
INC=131
DEC=132
BNOT=133
LNOT=134
LITERAL_true="true"=135
LITERAL_false="false"=136
LITERAL_null="null"=137
LITERAL_new="new"=138
NUM_INT=139
CHAR_LITERAL=140
STRING_LITERAL=141
NUM_FLOAT=142
NUM_LONG=143
NUM_DOUBLE=144
WS=145
SL_COMMENT=146
ML_COMMENT=147
ESC=148
HEX_DIGIT=149
VOCAB=150
EXPONENT=151
FLOAT_SUFFIX=152
CONSTRUCTOR_CAST=153
EMPTY_FIELD=154
WEBCOLOR_LITERAL=155
LITERAL_color="color"=156

View File

@ -0,0 +1,73 @@
package processing.app.preproc;
import java.util.*;
public class PreprocessorInfoChannel
{
Hashtable lineLists = new Hashtable(); // indexed by Token number
int firstValidTokenNumber = 0;
int maxTokenNumber = 0;
public void addLineForTokenNumber( Object line, Integer toknum )
{
if ( lineLists.containsKey( toknum ) ) {
Vector lines = (Vector) lineLists.get( toknum );
lines.addElement(line);
}
else {
Vector lines = new Vector();
lines.addElement(line);
lineLists.put(toknum, lines);
if ( maxTokenNumber < toknum.intValue() ) {
maxTokenNumber = toknum.intValue();
}
}
}
public int getMaxTokenNumber()
{
return maxTokenNumber;
}
public Vector extractLinesPrecedingTokenNumber( Integer toknum )
{
Vector lines = new Vector();
if (toknum == null) return lines;
for (int i = firstValidTokenNumber; i < toknum.intValue(); i++){
Integer inti = new Integer(i);
if ( lineLists.containsKey( inti ) ) {
Vector tokenLineVector = (Vector) lineLists.get( inti );
if ( tokenLineVector != null) {
Enumeration tokenLines = tokenLineVector.elements();
while ( tokenLines.hasMoreElements() ) {
lines.addElement( tokenLines.nextElement() );
}
lineLists.remove(inti);
}
}
}
firstValidTokenNumber = toknum.intValue();
return lines;
}
public String toString()
{
StringBuffer sb = new StringBuffer("PreprocessorInfoChannel:\n");
for (int i = 0; i <= maxTokenNumber + 1; i++){
Integer inti = new Integer(i);
if ( lineLists.containsKey( inti ) ) {
Vector tokenLineVector = (Vector) lineLists.get( inti );
if ( tokenLineVector != null) {
Enumeration tokenLines = tokenLineVector.elements();
while ( tokenLines.hasMoreElements() ) {
sb.append(inti + ":" + tokenLines.nextElement() + '\n');
}
}
}
}
return sb.toString();
}
}

View File

@ -1,106 +0,0 @@
The PDE Preprocessor is based on the Java Grammar that comes with
ANTLR 2.7.2. Moving it forward to a new version of the grammar
shouldn't be too difficult.
Here's some info about the various files in this directory:
java.g: this is the ANTLR grammar for Java 1.3/1.4 from the ANTLR
distribution. It is in the public domain. The only change to this
file from the original this file is the uncommenting of the clauses
required to support assert().
java.tree.g: this describes the Abstract Syntax Tree (AST) generated
by java.g. It is only here as a reference for coders hacking on the
preprocessor, it is not built or used at all. Note that pde.g
overrides some of the java.g rules so that in PDE ASTs, there are a
few minor differences. Also in the public domain.
pde.g: this is the grammar and lexer for the PDE language itself. It
subclasses the java.g grammar and lexer. There are a couple of
overrides to java.g that I hope to convince the ANTLR folks to fold
back into their grammar, but most of this file is highly specific to
PDE itself.
PdeEmitter.java: this class traverses the AST generated by the PDE
Recognizer, and emits it as Java code, doing any necessary
transformations along the way. It is based on JavaEmitter.java,
available from antlr.org, written by Andy Tripp <atripp@comcast.net>,
who has given permission for it to be distributed under the GPL.
ExtendedCommonASTWithHiddenTokens.java: this adds a necessary
initialize() method, as well as a number of methods to allow for XML
serialization of the parse tree in a such a way that the hidden tokens
are visible. Much of the code is taken from the original
CommonASTWithHiddenTokens class. I hope to convince the ANTLR folks
to fold these changes back into that class so that this file will be
unnecessary.
TokenStreamCopyingHiddenTokenFilter.java: this class provides
TokenStreamHiddenTokenFilters with the concept of tokens which can be
copied so that they are seen by both the hidden token stream as well
as the parser itself. This is useful when one wants to use an
existing parser (like the Java parser included with ANTLR) that throws
away some tokens to create a parse tree which can be used to spit out
a copy of the code with only minor modifications. Partially derived
from ANTLR code. I hope to convince the ANTLR folks to fold this
functionality back into ANTLR proper as well.
whitespace_test.pde: a torture test to ensure that the preprocessor is
correctly preserving whitespace, comments, and other hidden tokens
correctly. See the comments in the code for details about how to run
the test.
All other files in this directory are generated at build time by ANTLR
itself. The ANTLR manual goes into a fair amount of detail about the
what each type of file is for.
....
Current Preprocessor Subsitutions:
"compiler.substitute_floats" (currently "substitute_f")
- treat doubles as floats, i.e. 12.3 becomes 12.3f so that people
don't have to add f after their numbers all the time. this is
confusing for beginners.
"compiler.enhanced_casting"
- byte(), char(), int(), float() works for casting. this is basic in
the current implementation, but should be expanded as described
above. color() works similarly to int(), however there is also a
*function* called color(r, g, b) in p5. will this cause trouble?
"compiler.color_datattype"
- 'color' is aliased to 'int' as a datatype to represent ARGB packed
into a single int, commonly used in p5 for pixels[] and other color
operations. this is just a search/replace type thing, and it can be
used interchangeably with int.
"compiler.web_colors" (currently "inline_web_colors")
- color c = #cc0080; should unpack to 0xffcc0080 (the ff at the top is
so that the color is opaque), which is just an int.
Other preprocessor functionality
- detects what 'mode' the program is in: static (no function brackets
at all, just assumes everything is in draw), active (setup plus draw
or loop), and java mode (full java support).
http://proce55ing.net/reference/environment/index.html
- size and background are pulled from draw mode programs and placed
into setup(). this has a problem if size() is based on a variable,
which we try to avoid people doing, but would like to be able to
support it (perhaps by requiring the size() to be final?)
- currently does a godawful scrambling of the comments so that the
substitution doesn't try to run on them. this also causes lots of
bizarro bugs.
Possible?
- would be nice to just type code wherever, mixing a 'static' style
app with a few functions. would be simpler for starting out. but it
seems that the declarations would have to be pulled out, but that
all seems problematic. or maybe it could all be inside a static { }
block. but that wouldn't seem to work either.

View File

@ -0,0 +1,149 @@
// $ANTLR 2.7.2: "StdCParser.g" -> "StdCLexer.java"$
package processing.app.preproc;
import java.io.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
public interface STDCTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int LITERAL_typedef = 4;
int LITERAL_asm = 5;
int LITERAL_volatile = 6;
int LCURLY = 7;
int RCURLY = 8;
int SEMI = 9;
int LITERAL_struct = 10;
int LITERAL_union = 11;
int LITERAL_enum = 12;
int LITERAL_auto = 13;
int LITERAL_register = 14;
int LITERAL_extern = 15;
int LITERAL_static = 16;
int LITERAL_const = 17;
int LITERAL_void = 18;
int LITERAL_char = 19;
int LITERAL_short = 20;
int LITERAL_int = 21;
int LITERAL_long = 22;
int LITERAL_float = 23;
int LITERAL_double = 24;
int LITERAL_signed = 25;
int LITERAL_unsigned = 26;
int ID = 27;
int COMMA = 28;
int COLON = 29;
int ASSIGN = 30;
int STAR = 31;
int LPAREN = 32;
int RPAREN = 33;
int LBRACKET = 34;
int RBRACKET = 35;
int VARARGS = 36;
int LITERAL_while = 37;
int LITERAL_do = 38;
int LITERAL_for = 39;
int LITERAL_goto = 40;
int LITERAL_continue = 41;
int LITERAL_break = 42;
int LITERAL_return = 43;
int LITERAL_case = 44;
int LITERAL_default = 45;
int LITERAL_if = 46;
int LITERAL_else = 47;
int LITERAL_switch = 48;
int DIV_ASSIGN = 49;
int PLUS_ASSIGN = 50;
int MINUS_ASSIGN = 51;
int STAR_ASSIGN = 52;
int MOD_ASSIGN = 53;
int RSHIFT_ASSIGN = 54;
int LSHIFT_ASSIGN = 55;
int BAND_ASSIGN = 56;
int BOR_ASSIGN = 57;
int BXOR_ASSIGN = 58;
int QUESTION = 59;
int LOR = 60;
int LAND = 61;
int BOR = 62;
int BXOR = 63;
int BAND = 64;
int EQUAL = 65;
int NOT_EQUAL = 66;
int LT = 67;
int LTE = 68;
int GT = 69;
int GTE = 70;
int LSHIFT = 71;
int RSHIFT = 72;
int PLUS = 73;
int MINUS = 74;
int DIV = 75;
int MOD = 76;
int INC = 77;
int DEC = 78;
int LITERAL_sizeof = 79;
int BNOT = 80;
int LNOT = 81;
int PTR = 82;
int DOT = 83;
int CharLiteral = 84;
int StringLiteral = 85;
int IntOctalConst = 86;
int LongOctalConst = 87;
int UnsignedOctalConst = 88;
int IntIntConst = 89;
int LongIntConst = 90;
int UnsignedIntConst = 91;
int IntHexConst = 92;
int LongHexConst = 93;
int UnsignedHexConst = 94;
int FloatDoubleConst = 95;
int DoubleDoubleConst = 96;
int LongDoubleConst = 97;
int NTypedefName = 98;
int NInitDecl = 99;
int NDeclarator = 100;
int NStructDeclarator = 101;
int NDeclaration = 102;
int NCast = 103;
int NPointerGroup = 104;
int NExpressionGroup = 105;
int NFunctionCallArgs = 106;
int NNonemptyAbstractDeclarator = 107;
int NInitializer = 108;
int NStatementExpr = 109;
int NEmptyExpression = 110;
int NParameterTypeList = 111;
int NFunctionDef = 112;
int NCompoundStatement = 113;
int NParameterDeclaration = 114;
int NCommaExpr = 115;
int NUnaryExpr = 116;
int NLabel = 117;
int NPostfixExpr = 118;
int NRangeExpr = 119;
int NStringSeq = 120;
int NInitializerElementLabel = 121;
int NLcurlyInitializer = 122;
int NAsmAttribute = 123;
int NGnuAsmExpr = 124;
int NTypeMissing = 125;
int Vocabulary = 126;
int Whitespace = 127;
int Comment = 128;
int CPPComment = 129;
int PREPROC_DIRECTIVE = 130;
int Space = 131;
int LineDirective = 132;
int BadStringLiteral = 133;
int Escape = 134;
int Digit = 135;
int LongSuffix = 136;
int UnsignedSuffix = 137;
int FloatSuffix = 138;
int Exponent = 139;
int Number = 140;
}

View File

@ -0,0 +1,139 @@
// $ANTLR 2.7.2: StdCParser.g -> STDCTokenTypes.txt$
STDC // output token vocab name
LITERAL_typedef="typedef"=4
LITERAL_asm="asm"=5
LITERAL_volatile="volatile"=6
LCURLY=7
RCURLY=8
SEMI=9
LITERAL_struct="struct"=10
LITERAL_union="union"=11
LITERAL_enum="enum"=12
LITERAL_auto="auto"=13
LITERAL_register="register"=14
LITERAL_extern="extern"=15
LITERAL_static="static"=16
LITERAL_const="const"=17
LITERAL_void="void"=18
LITERAL_char="char"=19
LITERAL_short="short"=20
LITERAL_int="int"=21
LITERAL_long="long"=22
LITERAL_float="float"=23
LITERAL_double="double"=24
LITERAL_signed="signed"=25
LITERAL_unsigned="unsigned"=26
ID=27
COMMA=28
COLON=29
ASSIGN=30
STAR=31
LPAREN=32
RPAREN=33
LBRACKET=34
RBRACKET=35
VARARGS=36
LITERAL_while="while"=37
LITERAL_do="do"=38
LITERAL_for="for"=39
LITERAL_goto="goto"=40
LITERAL_continue="continue"=41
LITERAL_break="break"=42
LITERAL_return="return"=43
LITERAL_case="case"=44
LITERAL_default="default"=45
LITERAL_if="if"=46
LITERAL_else="else"=47
LITERAL_switch="switch"=48
DIV_ASSIGN=49
PLUS_ASSIGN=50
MINUS_ASSIGN=51
STAR_ASSIGN=52
MOD_ASSIGN=53
RSHIFT_ASSIGN=54
LSHIFT_ASSIGN=55
BAND_ASSIGN=56
BOR_ASSIGN=57
BXOR_ASSIGN=58
QUESTION=59
LOR=60
LAND=61
BOR=62
BXOR=63
BAND=64
EQUAL=65
NOT_EQUAL=66
LT=67
LTE=68
GT=69
GTE=70
LSHIFT=71
RSHIFT=72
PLUS=73
MINUS=74
DIV=75
MOD=76
INC=77
DEC=78
LITERAL_sizeof="sizeof"=79
BNOT=80
LNOT=81
PTR=82
DOT=83
CharLiteral=84
StringLiteral=85
IntOctalConst=86
LongOctalConst=87
UnsignedOctalConst=88
IntIntConst=89
LongIntConst=90
UnsignedIntConst=91
IntHexConst=92
LongHexConst=93
UnsignedHexConst=94
FloatDoubleConst=95
DoubleDoubleConst=96
LongDoubleConst=97
NTypedefName=98
NInitDecl=99
NDeclarator=100
NStructDeclarator=101
NDeclaration=102
NCast=103
NPointerGroup=104
NExpressionGroup=105
NFunctionCallArgs=106
NNonemptyAbstractDeclarator=107
NInitializer=108
NStatementExpr=109
NEmptyExpression=110
NParameterTypeList=111
NFunctionDef=112
NCompoundStatement=113
NParameterDeclaration=114
NCommaExpr=115
NUnaryExpr=116
NLabel=117
NPostfixExpr=118
NRangeExpr=119
NStringSeq=120
NInitializerElementLabel=121
NLcurlyInitializer=122
NAsmAttribute=123
NGnuAsmExpr=124
NTypeMissing=125
Vocabulary=126
Whitespace=127
Comment=128
CPPComment=129
PREPROC_DIRECTIVE("a line directive")=130
Space=131
LineDirective=132
BadStringLiteral=133
Escape=134
Digit=135
LongSuffix=136
UnsignedSuffix=137
FloatSuffix=138
Exponent=139
Number=140

File diff suppressed because it is too large Load Diff

1358
app/preproc/StdCParser.g Executable file

File diff suppressed because it is too large Load Diff

5886
app/preproc/StdCParser.java Normal file

File diff suppressed because it is too large Load Diff

434
app/preproc/TNode.java Executable file
View File

@ -0,0 +1,434 @@
package processing.app.preproc;
import antlr.collections.AST;
import antlr.CommonAST;
import antlr.Token;
import java.lang.reflect.*;
import java.util.Hashtable;
import java.util.Enumeration;
//import CToken;
/**
Class TNode is an implementation of the AST interface
and adds many useful features:
It is double-linked for reverse searching.
(this is currently incomplete, in that method doubleLink() must
be called after any changes to the tree to maintain the
reverse links).
It can store a definition node (defNode), so that nodes such
as scoped names can refer to the node that defines the name.
It stores line numbers for nodes.
Searches for parents and children of a tree can be done
based on their type.
The tree can be printed to System.out using a lisp-style syntax.
*/
public class TNode extends CommonAST {
protected int ttype;
protected String text;
protected int lineNum = 0;
protected TNode defNode;
protected TNode up;
protected TNode left;
protected boolean marker = false;
protected Hashtable attributes = null;
static String tokenVocabulary;
/** Set the token vocabulary to a tokentypes class
generated by antlr.
*/
public static void setTokenVocabulary(String s) {
tokenVocabulary = s;
}
public void initialize(Token token) {
CToken tok = (CToken) token;
setText(tok.getText());
setType(tok.getType());
setLineNum(tok.getLine());
setAttribute("source", tok.getSource());
setAttribute("tokenNumber", new Integer(tok.getTokenNumber()));
}
public void initialize(AST tr) {
TNode t = (TNode) tr;
setText(t.getText());
setType(t.getType());
setLineNum(t.getLineNum());
setDefNode(t.getDefNode());
this.attributes = t.getAttributesTable();
}
/** Get the token type for this node */
public int getType() { return ttype; }
/** Set the token type for this node */
public void setType(int ttype_) {
ttype = ttype_;
}
/** Get the marker value for this node.
This member is a general-use marker.
*/
public boolean getMarker() { return marker; }
/** Set the marker value for this node.
This property is a general-use boolean marker.
*/
public void setMarker(boolean marker_) {
marker = marker_;
}
/** get the hashtable that holds attribute values.
*/
public Hashtable getAttributesTable() {
if(attributes == null)
attributes = new Hashtable(7);
return attributes;
}
/** set an attribute in the attribute table.
*/
public void setAttribute(String attrName, Object value) {
if(attributes == null)
attributes = new Hashtable(7);
attributes.put(attrName,value);
}
/** lookup the attribute name in the attribute table.
If the value does not exist, it returns null.
*/
public Object getAttribute(String attrName) {
if(attributes == null)
return null;
else
return attributes.get(attrName);
}
/** Get the line number for this node.
If the line number is 0, search for a non-zero line num among children */
public int getLineNum() {
if(lineNum != 0)
return lineNum;
else
if(down == null)
return lineNum;
else
return ((TNode)down).getLocalLineNum();
}
public int getLocalLineNum() {
if(lineNum != 0)
return lineNum;
else
if(down == null)
if(right == null)
return lineNum;
else
return ((TNode)right).getLocalLineNum();
else
return ((TNode)down).getLocalLineNum();
}
/** Set the line number for this node */
public void setLineNum(int lineNum_) {
lineNum = lineNum_;
}
/** Get the token text for this node */
public String getText() { return text; }
/** Set the token text for this node */
public void setText(String text_) {
text = text_;
}
/** return the last child of this node, or null if there is none */
public TNode getLastChild() {
TNode down = (TNode)getFirstChild();
if(down != null)
return down.getLastSibling();
else
return null;
}
/** return the last sibling of this node, which is
this if the next sibling is null */
public TNode getLastSibling() {
TNode next = (TNode)getNextSibling();
if(next != null)
return next.getLastSibling();
else
return this;
}
/** return the first sibling of this node, which is
this if the prev sibling is null */
public TNode getFirstSibling() {
TNode prev = (TNode)left;
if(prev != null)
return prev.getFirstSibling();
else
return this;
}
/** return the parent node of this node */
public TNode getParent() {
return (TNode)getFirstSibling().up;
}
/** add the new node as a new sibling, inserting it ahead of any
existing next sibling. This method maintains double-linking.
if node is null, nothing happens. If the node has siblings,
then they are added in as well.
*/
public void addSibling(AST node) {
if(node == null) return;
TNode next = (TNode)right;
right = (TNode)node;
((TNode)node).left = this;
TNode nodeLastSib = ((TNode)node).getLastSibling();
nodeLastSib.right = next;
if(next != null)
next.left = nodeLastSib;
}
/** return the number of children of this node */
public int numberOfChildren() {
int count = 0;
AST child = getFirstChild();
while(child != null) {
count++;
child = child.getNextSibling();
}
return count;
}
/** remove this node from the tree, resetting sibling and parent
pointers as necessary. This method maintains double-linking */
public void removeSelf() {
TNode parent = (TNode)up;
TNode prev = (TNode)left;
TNode next = (TNode)right;
if(parent != null) {
parent.down = next;
if(next != null) {
next.up = parent;
next.left = prev; // which should be null
}
}
else {
if(prev != null)
prev.right = next;
if(next != null)
next.left = prev;
}
}
/** return the def node for this node */
public TNode getDefNode() {
return defNode;
}
/** set the def node for this node */
public void setDefNode(TNode n) {
defNode = n;
}
/** return a deep copy of this node, and all sub nodes.
New tree is doubleLinked, with no parent or siblings.
Marker value is not copied!
*/
public TNode deepCopy() {
TNode copy = new TNode();
copy.ttype = ttype;
copy.text = text;
copy.lineNum = lineNum;
copy.defNode = defNode;
if(attributes != null)
copy.attributes = (Hashtable)attributes.clone();
if(down != null)
copy.down = ((TNode)down).deepCopyWithRightSiblings();
copy.doubleLink();
return copy;
}
/** return a deep copy of this node, all sub nodes,
and right siblings.
New tree is doubleLinked, with no parent or left siblings.
defNode is not copied */
public TNode deepCopyWithRightSiblings() {
TNode copy = new TNode();
copy.ttype = ttype;
copy.text = text;
copy.lineNum = lineNum;
copy.defNode = defNode;
if(attributes != null)
copy.attributes = (Hashtable)attributes.clone();
if(down != null)
copy.down = ((TNode)down).deepCopyWithRightSiblings();
if(right != null)
copy.right = ((TNode)right).deepCopyWithRightSiblings();
copy.doubleLink();
return copy;
}
/** return a short string representation of the node */
public String toString() {
StringBuffer str = new StringBuffer( getNameForType(getType()) +
"[" + getText() + ", " + "]");
if(this.getLineNum() != 0)
str.append(" line:" + (this.getLineNum() ) );
Enumeration keys = (this.getAttributesTable().keys());
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
str.append(" " + key + ":" + (this.getAttribute(key)));
}
return str.toString();
}
/** print given tree to System.out */
public static void printTree(AST t) {
if (t == null) return;
printASTNode(t,0);
System.out.print("\n");
}
/** protected method that does the work of printing */
protected static void printASTNode(AST t, int indent) {
AST child1, next;
child1 = t.getFirstChild();
System.out.print("\n");
for(int i = 0; i < indent; i++)
System.out.print(" ");
if(child1 != null)
System.out.print("(");
String s = t.getText();
if(s != null && s.length() > 0) {
System.out.print(getNameForType(t.getType()));
System.out.print(": \"" + s + "\"");
}
else
System.out.print(getNameForType(t.getType()));
if(((TNode)t).getLineNum() != 0)
System.out.print(" line:" + ((TNode)t).getLineNum() );
Enumeration keys = ((TNode)t).getAttributesTable().keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
System.out.print(" " + key + ":" + ((TNode)t).getAttribute(key));
}
TNode def = ((TNode)t).getDefNode();
if(def != null)
System.out.print("[" + getNameForType(def.getType()) + "]");
if(child1 != null) {
printASTNode(child1,indent + 1);
System.out.print("\n");
for(int i = 0; i < indent; i++)
System.out.print(" ");
System.out.print(")");
}
next = t.getNextSibling();
if(next != null) {
printASTNode(next,indent);
}
}
/** converts an int tree token type to a name.
Does this by reflecting on nsdidl.IDLTreeTokenTypes,
and is dependent on how ANTLR 2.00 outputs that class. */
public static String getNameForType(int t) {
try{
Class c = Class.forName(tokenVocabulary);
Field[] fields = c.getDeclaredFields();
if(t-2 < fields.length)
return fields[t-2].getName();
} catch (Exception e) { System.out.println(e); }
return "unfoundtype: " + t;
}
/** set up reverse links between this node and its first
child and its first sibling, and link those as well */
public void doubleLink() {
TNode right = (TNode)getNextSibling();
if(right != null) {
right.left = this;
right.doubleLink();
}
TNode down = (TNode)getFirstChild();
if(down != null) {
down.up = this;
down.doubleLink();
}
}
/** find first parent of the given type,
return null on failure */
public TNode parentOfType(int type) {
if(up == null) {
if(left == null)
return null;
else
return left.parentOfType(type);
}
if(up.getType() == type)
return up;
return up.parentOfType(type);
}
/** find the first child of the node
of the given type, return null on failure */
public TNode firstChildOfType(int type) {
TNode down = (TNode)getFirstChild();
if(down == null)
return null;
if(down.getType() == type)
return down;
return down.firstSiblingOfType(type);
}
/** find the first sibling of the node
of the given type, return null on failure */
public TNode firstSiblingOfType(int type) {
TNode right = (TNode)getNextSibling();
if(right == null)
return null;
if(right.getType() == type)
return right;
return right.firstSiblingOfType(type);
}
}

33
app/preproc/TNodeFactory.java Executable file
View File

@ -0,0 +1,33 @@
package processing.app.preproc;
import antlr.Token;
import antlr.ASTFactory;
import antlr.collections.AST;
/** This class extends ASTFactory to build instances
of class TNode */
public class TNodeFactory extends ASTFactory {
/** Create a new ampty AST node */
public AST create() {
return new TNode();
}
/** Create a new AST node from type and text */
public AST create(int ttype, String text) {
AST ast = new TNode();
ast.setType(ttype);
ast.setText(text);
return ast;
}
/** Create a new AST node from an existing AST node */
public AST create(AST ast) {
AST newast = new TNode();
newast.setType(ast.getType());
newast.setText(ast.getText());
return newast;
}
}

View File

@ -1,221 +0,0 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
package antlr;
//package processing.app.preproc;
import antlr.*;
import antlr.collections.impl.BitSet;
/**
* This class provides TokenStreamHiddenTokenFilters with the concept of
* tokens which can be copied so that they are seen by both the hidden token
* stream as well as the parser itself. This is useful when one wants to use
* an existing parser (like the Java parser included with ANTLR) that throws
* away some tokens to create a parse tree which can be used to spit out
* a copy of the code with only minor modifications.
*
* This code is partially derived from the public domain ANLTR TokenStream
*/
public class TokenStreamCopyingHiddenTokenFilter
extends TokenStreamHiddenTokenFilter
implements TokenStream {
protected BitSet copyMask;
CommonHiddenStreamToken hiddenCopy = null;
public TokenStreamCopyingHiddenTokenFilter(TokenStream input) {
super(input);
copyMask = new BitSet();
}
/**
* Indicate that all tokens of type tokenType should be copied. The copy
* is put in the stream of hidden tokens, and the original is returned in the
* stream of normal tokens.
*
* @param tokenType integer representing the token type to copied
*/
public void copy(int tokenType) {
copyMask.add(tokenType);
}
/**
* Create a clone of the important parts of the given token. Note that this
* does NOT copy the hiddenBefore and hiddenAfter fields.
*
* @param t token to partially clone
* @return newly created partial clone
*/
public CommonHiddenStreamToken partialCloneToken(CommonHiddenStreamToken t) {
CommonHiddenStreamToken u = new CommonHiddenStreamToken(t.getType(),
t.getText());
u.setColumn(t.getColumn());
u.setLine(t.getLine());
u.setFilename(t.getFilename());
return u;
}
public void linkAndCopyToken(CommonHiddenStreamToken prev,
CommonHiddenStreamToken monitored) {
// create a copy of the token in the lookahead for use as hidden token
hiddenCopy = partialCloneToken(LA(1));
// attach copy to the previous token, whether hidden or monitored
prev.setHiddenAfter(hiddenCopy);
// if previous token was hidden, set the hiddenBefore pointer of the
// copy to point back to it
if (prev != monitored) {
hiddenCopy.setHiddenBefore(prev);
}
// we don't want the non-hidden copy to link back to the hidden
// copy on the next pass through this function, so we leave
// lastHiddenToken alone
//System.err.println("hidden copy: " + hiddenCopy.toString());
return;
}
private void consumeFirst() throws TokenStreamException {
consume(); // get first token of input stream
// Handle situation where hidden or discarded tokens
// appear first in input stream
CommonHiddenStreamToken p=null;
// while hidden, copied, or discarded scarf tokens
while ( hideMask.member(LA(1).getType()) ||
discardMask.member(LA(1).getType()) ||
copyMask.member(LA(1).getType()) ) {
// if we've hit one of the tokens that needs to be copied, we copy it
// and then break out of the loop, because the parser needs to see it
// too
//
if (copyMask.member(LA(1).getType())) {
// copy the token in the lookahead
hiddenCopy = partialCloneToken(LA(1));
// if there's an existing token before this, link that and the
// copy together
if (p != null) {
p.setHiddenAfter(hiddenCopy);
hiddenCopy.setHiddenBefore(p); // double-link
}
lastHiddenToken = hiddenCopy;
if (firstHidden == null) {
firstHidden = hiddenCopy;
}
// we don't want to consume this token, because it also needs to
// be passed through to the parser, so break out of the while look
// entirely
//
break;
} else if (hideMask.member(LA(1).getType())) {
if (p != null) {
p.setHiddenAfter(LA(1));
LA(1).setHiddenBefore(p); // double-link
}
p = LA(1);
lastHiddenToken = p;
if (firstHidden == null) {
firstHidden = p; // record hidden token if first
}
}
consume();
}
}
/** Return the next monitored token.
* Test the token following the monitored token.
* If following is another monitored token, save it
* for the next invocation of nextToken (like a single
* lookahead token) and return it then.
* If following is unmonitored, nondiscarded (hidden)
* channel token, add it to the monitored token.
*
* Note: EOF must be a monitored Token.
*/
public Token nextToken() throws TokenStreamException {
// handle an initial condition; don't want to get lookahead
// token of this splitter until first call to nextToken
if (LA(1) == null) {
consumeFirst();
}
//System.err.println();
// we always consume hidden tokens after monitored, thus,
// upon entry LA(1) is a monitored token.
CommonHiddenStreamToken monitored = LA(1);
// point to hidden tokens found during last invocation
monitored.setHiddenBefore(lastHiddenToken);
lastHiddenToken = null;
// Look for hidden tokens, hook them into list emanating
// from the monitored tokens.
consume();
CommonHiddenStreamToken prev = monitored;
// deal with as many not-purely-monitored tokens as possible
while ( hideMask.member(LA(1).getType()) ||
discardMask.member(LA(1).getType()) ||
copyMask.member(LA(1).getType()) ) {
if (copyMask.member(LA(1).getType())) {
// copy the token and link it backwards
if (hiddenCopy != null) {
linkAndCopyToken(hiddenCopy, monitored);
} else {
linkAndCopyToken(prev, monitored);
}
// we now need to parse it as a monitored token, so we return, which
// avoids the consume() call at the end of this loop. the next call
// will parse it as a monitored token.
//System.err.println("returned: " + monitored.toString());
return monitored;
} else if (hideMask.member(LA(1).getType())) {
// attach the hidden token to the monitored in a chain
// link forwards
prev.setHiddenAfter(LA(1));
// link backwards
if (prev != monitored) { //hidden cannot point to monitored tokens
LA(1).setHiddenBefore(prev);
} else if (hiddenCopy != null) {
hiddenCopy.setHiddenAfter(LA(1));
LA(1).setHiddenBefore(hiddenCopy);
hiddenCopy = null;
}
//System.err.println("hidden: " + prev.getHiddenAfter().toString() + "\" after: " + prev.toString());
prev = lastHiddenToken = LA(1);
}
consume();
}
// remember the last hidden token for next time around
if (hiddenCopy != null) {
lastHiddenToken = hiddenCopy;
hiddenCopy = null;
}
//System.err.println("returned: " + monitored.toString());
return monitored;
}
}

1191
app/preproc/WEmitter.g Executable file

File diff suppressed because it is too large Load Diff

6689
app/preproc/WEmitter.java Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,163 @@
// $ANTLR 2.7.2: "expandedWEmitter.g" -> "WEmitter.java"$
package processing.app.preproc;
import processing.app.*;
import java.io.*;
import java.util.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
public interface WEmitterTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int LITERAL_typedef = 4;
int LITERAL_asm = 5;
int LITERAL_volatile = 6;
int LCURLY = 7;
int RCURLY = 8;
int SEMI = 9;
int LITERAL_struct = 10;
int LITERAL_union = 11;
int LITERAL_enum = 12;
int LITERAL_auto = 13;
int LITERAL_register = 14;
int LITERAL_extern = 15;
int LITERAL_static = 16;
int LITERAL_const = 17;
int LITERAL_void = 18;
int LITERAL_char = 19;
int LITERAL_short = 20;
int LITERAL_int = 21;
int LITERAL_long = 22;
int LITERAL_float = 23;
int LITERAL_double = 24;
int LITERAL_signed = 25;
int LITERAL_unsigned = 26;
int ID = 27;
int COMMA = 28;
int COLON = 29;
int ASSIGN = 30;
int STAR = 31;
int LPAREN = 32;
int RPAREN = 33;
int LBRACKET = 34;
int RBRACKET = 35;
int VARARGS = 36;
int LITERAL_while = 37;
int LITERAL_do = 38;
int LITERAL_for = 39;
int LITERAL_goto = 40;
int LITERAL_continue = 41;
int LITERAL_break = 42;
int LITERAL_return = 43;
int LITERAL_case = 44;
int LITERAL_default = 45;
int LITERAL_if = 46;
int LITERAL_else = 47;
int LITERAL_switch = 48;
int DIV_ASSIGN = 49;
int PLUS_ASSIGN = 50;
int MINUS_ASSIGN = 51;
int STAR_ASSIGN = 52;
int MOD_ASSIGN = 53;
int RSHIFT_ASSIGN = 54;
int LSHIFT_ASSIGN = 55;
int BAND_ASSIGN = 56;
int BOR_ASSIGN = 57;
int BXOR_ASSIGN = 58;
int QUESTION = 59;
int LOR = 60;
int LAND = 61;
int BOR = 62;
int BXOR = 63;
int BAND = 64;
int EQUAL = 65;
int NOT_EQUAL = 66;
int LT = 67;
int LTE = 68;
int GT = 69;
int GTE = 70;
int LSHIFT = 71;
int RSHIFT = 72;
int PLUS = 73;
int MINUS = 74;
int DIV = 75;
int MOD = 76;
int INC = 77;
int DEC = 78;
int LITERAL_sizeof = 79;
int BNOT = 80;
int LNOT = 81;
int PTR = 82;
int DOT = 83;
int CharLiteral = 84;
int StringLiteral = 85;
int IntOctalConst = 86;
int LongOctalConst = 87;
int UnsignedOctalConst = 88;
int IntIntConst = 89;
int LongIntConst = 90;
int UnsignedIntConst = 91;
int IntHexConst = 92;
int LongHexConst = 93;
int UnsignedHexConst = 94;
int FloatDoubleConst = 95;
int DoubleDoubleConst = 96;
int LongDoubleConst = 97;
int NTypedefName = 98;
int NInitDecl = 99;
int NDeclarator = 100;
int NStructDeclarator = 101;
int NDeclaration = 102;
int NCast = 103;
int NPointerGroup = 104;
int NExpressionGroup = 105;
int NFunctionCallArgs = 106;
int NNonemptyAbstractDeclarator = 107;
int NInitializer = 108;
int NStatementExpr = 109;
int NEmptyExpression = 110;
int NParameterTypeList = 111;
int NFunctionDef = 112;
int NCompoundStatement = 113;
int NParameterDeclaration = 114;
int NCommaExpr = 115;
int NUnaryExpr = 116;
int NLabel = 117;
int NPostfixExpr = 118;
int NRangeExpr = 119;
int NStringSeq = 120;
int NInitializerElementLabel = 121;
int NLcurlyInitializer = 122;
int NAsmAttribute = 123;
int NGnuAsmExpr = 124;
int NTypeMissing = 125;
int Vocabulary = 126;
int Whitespace = 127;
int Comment = 128;
int CPPComment = 129;
int PREPROC_DIRECTIVE = 130;
int Space = 131;
int LineDirective = 132;
int BadStringLiteral = 133;
int Escape = 134;
int Digit = 135;
int LongSuffix = 136;
int UnsignedSuffix = 137;
int FloatSuffix = 138;
int Exponent = 139;
int Number = 140;
int LITERAL___label__ = 141;
int LITERAL_inline = 142;
int LITERAL_byte = 143;
int LITERAL_boolean = 144;
int LITERAL_Servo = 145;
int LITERAL_Wire = 146;
int LITERAL_typeof = 147;
int LITERAL___complex = 148;
int LITERAL___attribute = 149;
int LITERAL___alignof = 150;
int LITERAL___real = 151;
int LITERAL___imag = 152;
}

View File

@ -0,0 +1,151 @@
// $ANTLR 2.7.2: expandedWEmitter.g -> WEmitterTokenTypes.txt$
WEmitter // output token vocab name
LITERAL_typedef="typedef"=4
LITERAL_asm="asm"=5
LITERAL_volatile="volatile"=6
LCURLY=7
RCURLY=8
SEMI=9
LITERAL_struct="struct"=10
LITERAL_union="union"=11
LITERAL_enum="enum"=12
LITERAL_auto="auto"=13
LITERAL_register="register"=14
LITERAL_extern="extern"=15
LITERAL_static="static"=16
LITERAL_const="const"=17
LITERAL_void="void"=18
LITERAL_char="char"=19
LITERAL_short="short"=20
LITERAL_int="int"=21
LITERAL_long="long"=22
LITERAL_float="float"=23
LITERAL_double="double"=24
LITERAL_signed="signed"=25
LITERAL_unsigned="unsigned"=26
ID=27
COMMA=28
COLON=29
ASSIGN=30
STAR=31
LPAREN=32
RPAREN=33
LBRACKET=34
RBRACKET=35
VARARGS=36
LITERAL_while="while"=37
LITERAL_do="do"=38
LITERAL_for="for"=39
LITERAL_goto="goto"=40
LITERAL_continue="continue"=41
LITERAL_break="break"=42
LITERAL_return="return"=43
LITERAL_case="case"=44
LITERAL_default="default"=45
LITERAL_if="if"=46
LITERAL_else="else"=47
LITERAL_switch="switch"=48
DIV_ASSIGN=49
PLUS_ASSIGN=50
MINUS_ASSIGN=51
STAR_ASSIGN=52
MOD_ASSIGN=53
RSHIFT_ASSIGN=54
LSHIFT_ASSIGN=55
BAND_ASSIGN=56
BOR_ASSIGN=57
BXOR_ASSIGN=58
QUESTION=59
LOR=60
LAND=61
BOR=62
BXOR=63
BAND=64
EQUAL=65
NOT_EQUAL=66
LT=67
LTE=68
GT=69
GTE=70
LSHIFT=71
RSHIFT=72
PLUS=73
MINUS=74
DIV=75
MOD=76
INC=77
DEC=78
LITERAL_sizeof="sizeof"=79
BNOT=80
LNOT=81
PTR=82
DOT=83
CharLiteral=84
StringLiteral=85
IntOctalConst=86
LongOctalConst=87
UnsignedOctalConst=88
IntIntConst=89
LongIntConst=90
UnsignedIntConst=91
IntHexConst=92
LongHexConst=93
UnsignedHexConst=94
FloatDoubleConst=95
DoubleDoubleConst=96
LongDoubleConst=97
NTypedefName=98
NInitDecl=99
NDeclarator=100
NStructDeclarator=101
NDeclaration=102
NCast=103
NPointerGroup=104
NExpressionGroup=105
NFunctionCallArgs=106
NNonemptyAbstractDeclarator=107
NInitializer=108
NStatementExpr=109
NEmptyExpression=110
NParameterTypeList=111
NFunctionDef=112
NCompoundStatement=113
NParameterDeclaration=114
NCommaExpr=115
NUnaryExpr=116
NLabel=117
NPostfixExpr=118
NRangeExpr=119
NStringSeq=120
NInitializerElementLabel=121
NLcurlyInitializer=122
NAsmAttribute=123
NGnuAsmExpr=124
NTypeMissing=125
Vocabulary=126
Whitespace=127
Comment=128
CPPComment=129
PREPROC_DIRECTIVE("a line directive")=130
Space=131
LineDirective=132
BadStringLiteral=133
Escape=134
Digit=135
LongSuffix=136
UnsignedSuffix=137
FloatSuffix=138
Exponent=139
Number=140
LITERAL___label__="__label__"=141
LITERAL_inline="inline"=142
LITERAL_byte="byte"=143
LITERAL_boolean="boolean"=144
LITERAL_Servo="Servo"=145
LITERAL_Wire="Wire"=146
LITERAL_typeof="typeof"=147
LITERAL___complex="__complex"=148
LITERAL___attribute="__attribute"=149
LITERAL___alignof="__alignof"=150
LITERAL___real="__real"=151
LITERAL___imag="__imag"=152

2810
app/preproc/WLexer.java Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,168 @@
// $ANTLR 2.7.2: "expandedWParser.g" -> "WLexer.java"$
package processing.app.preproc;
import java.io.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
public interface WLexerTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int LITERAL_typedef = 4;
int LITERAL_asm = 5;
int LITERAL_volatile = 6;
int LCURLY = 7;
int RCURLY = 8;
int SEMI = 9;
int LITERAL_struct = 10;
int LITERAL_union = 11;
int LITERAL_enum = 12;
int LITERAL_auto = 13;
int LITERAL_register = 14;
int LITERAL_extern = 15;
int LITERAL_static = 16;
int LITERAL_const = 17;
int LITERAL_void = 18;
int LITERAL_char = 19;
int LITERAL_short = 20;
int LITERAL_int = 21;
int LITERAL_long = 22;
int LITERAL_float = 23;
int LITERAL_double = 24;
int LITERAL_signed = 25;
int LITERAL_unsigned = 26;
int ID = 27;
int COMMA = 28;
int COLON = 29;
int ASSIGN = 30;
int STAR = 31;
int LPAREN = 32;
int RPAREN = 33;
int LBRACKET = 34;
int RBRACKET = 35;
int VARARGS = 36;
int LITERAL_while = 37;
int LITERAL_do = 38;
int LITERAL_for = 39;
int LITERAL_goto = 40;
int LITERAL_continue = 41;
int LITERAL_break = 42;
int LITERAL_return = 43;
int LITERAL_case = 44;
int LITERAL_default = 45;
int LITERAL_if = 46;
int LITERAL_else = 47;
int LITERAL_switch = 48;
int DIV_ASSIGN = 49;
int PLUS_ASSIGN = 50;
int MINUS_ASSIGN = 51;
int STAR_ASSIGN = 52;
int MOD_ASSIGN = 53;
int RSHIFT_ASSIGN = 54;
int LSHIFT_ASSIGN = 55;
int BAND_ASSIGN = 56;
int BOR_ASSIGN = 57;
int BXOR_ASSIGN = 58;
int QUESTION = 59;
int LOR = 60;
int LAND = 61;
int BOR = 62;
int BXOR = 63;
int BAND = 64;
int EQUAL = 65;
int NOT_EQUAL = 66;
int LT = 67;
int LTE = 68;
int GT = 69;
int GTE = 70;
int LSHIFT = 71;
int RSHIFT = 72;
int PLUS = 73;
int MINUS = 74;
int DIV = 75;
int MOD = 76;
int INC = 77;
int DEC = 78;
int LITERAL_sizeof = 79;
int BNOT = 80;
int LNOT = 81;
int PTR = 82;
int DOT = 83;
int CharLiteral = 84;
int StringLiteral = 85;
int IntOctalConst = 86;
int LongOctalConst = 87;
int UnsignedOctalConst = 88;
int IntIntConst = 89;
int LongIntConst = 90;
int UnsignedIntConst = 91;
int IntHexConst = 92;
int LongHexConst = 93;
int UnsignedHexConst = 94;
int FloatDoubleConst = 95;
int DoubleDoubleConst = 96;
int LongDoubleConst = 97;
int NTypedefName = 98;
int NInitDecl = 99;
int NDeclarator = 100;
int NStructDeclarator = 101;
int NDeclaration = 102;
int NCast = 103;
int NPointerGroup = 104;
int NExpressionGroup = 105;
int NFunctionCallArgs = 106;
int NNonemptyAbstractDeclarator = 107;
int NInitializer = 108;
int NStatementExpr = 109;
int NEmptyExpression = 110;
int NParameterTypeList = 111;
int NFunctionDef = 112;
int NCompoundStatement = 113;
int NParameterDeclaration = 114;
int NCommaExpr = 115;
int NUnaryExpr = 116;
int NLabel = 117;
int NPostfixExpr = 118;
int NRangeExpr = 119;
int NStringSeq = 120;
int NInitializerElementLabel = 121;
int NLcurlyInitializer = 122;
int NAsmAttribute = 123;
int NGnuAsmExpr = 124;
int NTypeMissing = 125;
int Vocabulary = 126;
int Whitespace = 127;
int Comment = 128;
int CPPComment = 129;
int PREPROC_DIRECTIVE = 130;
int Space = 131;
int LineDirective = 132;
int BadStringLiteral = 133;
int Escape = 134;
int Digit = 135;
int LongSuffix = 136;
int UnsignedSuffix = 137;
int FloatSuffix = 138;
int Exponent = 139;
int Number = 140;
int LITERAL___label__ = 141;
int LITERAL_inline = 142;
int LITERAL_byte = 143;
int LITERAL_boolean = 144;
int LITERAL_Servo = 145;
int LITERAL_Wire = 146;
int LITERAL_typeof = 147;
int LITERAL___complex = 148;
int LITERAL___attribute = 149;
int LITERAL___alignof = 150;
int LITERAL___real = 151;
int LITERAL___imag = 152;
int LITERAL___extension__ = 153;
int IntSuffix = 154;
int NumberSuffix = 155;
int IDMEAT = 156;
int WideCharLiteral = 157;
int WideStringLiteral = 158;
}

View File

@ -0,0 +1,157 @@
// $ANTLR 2.7.2: expandedWParser.g -> WLexerTokenTypes.txt$
WLexer // output token vocab name
LITERAL_typedef="typedef"=4
LITERAL_asm="asm"=5
LITERAL_volatile="volatile"=6
LCURLY=7
RCURLY=8
SEMI=9
LITERAL_struct="struct"=10
LITERAL_union="union"=11
LITERAL_enum="enum"=12
LITERAL_auto="auto"=13
LITERAL_register="register"=14
LITERAL_extern="extern"=15
LITERAL_static="static"=16
LITERAL_const="const"=17
LITERAL_void="void"=18
LITERAL_char="char"=19
LITERAL_short="short"=20
LITERAL_int="int"=21
LITERAL_long="long"=22
LITERAL_float="float"=23
LITERAL_double="double"=24
LITERAL_signed="signed"=25
LITERAL_unsigned="unsigned"=26
ID=27
COMMA=28
COLON=29
ASSIGN=30
STAR=31
LPAREN=32
RPAREN=33
LBRACKET=34
RBRACKET=35
VARARGS=36
LITERAL_while="while"=37
LITERAL_do="do"=38
LITERAL_for="for"=39
LITERAL_goto="goto"=40
LITERAL_continue="continue"=41
LITERAL_break="break"=42
LITERAL_return="return"=43
LITERAL_case="case"=44
LITERAL_default="default"=45
LITERAL_if="if"=46
LITERAL_else="else"=47
LITERAL_switch="switch"=48
DIV_ASSIGN=49
PLUS_ASSIGN=50
MINUS_ASSIGN=51
STAR_ASSIGN=52
MOD_ASSIGN=53
RSHIFT_ASSIGN=54
LSHIFT_ASSIGN=55
BAND_ASSIGN=56
BOR_ASSIGN=57
BXOR_ASSIGN=58
QUESTION=59
LOR=60
LAND=61
BOR=62
BXOR=63
BAND=64
EQUAL=65
NOT_EQUAL=66
LT=67
LTE=68
GT=69
GTE=70
LSHIFT=71
RSHIFT=72
PLUS=73
MINUS=74
DIV=75
MOD=76
INC=77
DEC=78
LITERAL_sizeof="sizeof"=79
BNOT=80
LNOT=81
PTR=82
DOT=83
CharLiteral=84
StringLiteral=85
IntOctalConst=86
LongOctalConst=87
UnsignedOctalConst=88
IntIntConst=89
LongIntConst=90
UnsignedIntConst=91
IntHexConst=92
LongHexConst=93
UnsignedHexConst=94
FloatDoubleConst=95
DoubleDoubleConst=96
LongDoubleConst=97
NTypedefName=98
NInitDecl=99
NDeclarator=100
NStructDeclarator=101
NDeclaration=102
NCast=103
NPointerGroup=104
NExpressionGroup=105
NFunctionCallArgs=106
NNonemptyAbstractDeclarator=107
NInitializer=108
NStatementExpr=109
NEmptyExpression=110
NParameterTypeList=111
NFunctionDef=112
NCompoundStatement=113
NParameterDeclaration=114
NCommaExpr=115
NUnaryExpr=116
NLabel=117
NPostfixExpr=118
NRangeExpr=119
NStringSeq=120
NInitializerElementLabel=121
NLcurlyInitializer=122
NAsmAttribute=123
NGnuAsmExpr=124
NTypeMissing=125
Vocabulary=126
Whitespace=127
Comment=128
CPPComment=129
PREPROC_DIRECTIVE("a line directive")=130
Space=131
LineDirective=132
BadStringLiteral=133
Escape=134
Digit=135
LongSuffix=136
UnsignedSuffix=137
FloatSuffix=138
Exponent=139
Number=140
LITERAL___label__="__label__"=141
LITERAL_inline="inline"=142
LITERAL_byte="byte"=143
LITERAL_boolean="boolean"=144
LITERAL_Servo="Servo"=145
LITERAL_Wire="Wire"=146
LITERAL_typeof="typeof"=147
LITERAL___complex="__complex"=148
LITERAL___attribute="__attribute"=149
LITERAL___alignof="__alignof"=150
LITERAL___real="__real"=151
LITERAL___imag="__imag"=152
LITERAL___extension__="__extension__"=153
IntSuffix=154
NumberSuffix=155
IDMEAT=156
WideCharLiteral=157
WideStringLiteral=158

856
app/preproc/WParser.g Executable file
View File

@ -0,0 +1,856 @@
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) Non, Inc. 1998 -- All Rights Reserved
PROJECT: C Compiler
MODULE: WParser
FILE: WParser.g
AUTHOR: Monty Zukowski (jamz@cdsnet.net) April 28, 1998
MODIFICATIONS: Hernando Barragan added support for the Wiring language
DESCRIPTION:
This is a grammar for the GNU C compiler. It is a
grammar subclass of StdCParser, overriding only those
rules which are different from Standard C.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
header {
package processing.app.preproc;
import java.io.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
}
class WParser extends StdCParser;
options
{
k = 2;
exportVocab = W;
buildAST = true;
ASTLabelType = "TNode";
defaultErrorHandler = false;
// Copied following options from java grammar.
codeGenMakeSwitchThreshold = 2;
codeGenBitsetTestThreshold = 3;
}
{
// Suppport C++-style single-line comments?
public static boolean CPPComments = true;
// access to symbol table
public CSymbolTable symbolTable = new CSymbolTable();
// source for names to unnamed scopes
protected int unnamedScopeCounter = 0;
public boolean isTypedefName(String name) {
boolean returnValue = false;
TNode node = symbolTable.lookupNameInCurrentScope(name);
for (; node != null; node = (TNode) node.getNextSibling() ) {
if(node.getType() == LITERAL_typedef) {
returnValue = true;
break;
}
}
return returnValue;
}
public String getAScopeName() {
return "" + (unnamedScopeCounter++);
}
public void pushScope(String scopeName) {
symbolTable.pushScope(scopeName);
}
public void popScope() {
symbolTable.popScope();
}
int traceDepth = 0;
public void reportError(RecognitionException ex) {
try {
System.err.println("ANTLR Parsing Error: "+ex + " token name:" + tokenNames[LA(1)]);
ex.printStackTrace(System.err);
}
catch (TokenStreamException e) {
System.err.println("ANTLR Parsing Error: "+ex);
ex.printStackTrace(System.err);
}
}
public void reportError(String s) {
System.err.println("ANTLR Parsing Error from String: " + s);
}
public void reportWarning(String s) {
System.err.println("ANTLR Parsing Warning from String: " + s);
}
public void match(int t) throws MismatchedTokenException {
boolean debugging = false;
if ( debugging ) {
for (int x=0; x<traceDepth; x++) System.out.print(" ");
try {
System.out.println("Match("+tokenNames[t]+") with LA(1)="+
tokenNames[LA(1)] + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
}
catch (TokenStreamException e) {
System.out.println("Match("+tokenNames[t]+") " + ((inputState.guessing>0)?" [inputState.guessing "+ inputState.guessing + "]":""));
}
}
try {
if ( LA(1)!=t ) {
if ( debugging ){
for (int x=0; x<traceDepth; x++) System.out.print(" ");
System.out.println("token mismatch: "+tokenNames[LA(1)]
+ "!="+tokenNames[t]);
}
throw new MismatchedTokenException(tokenNames, LT(1), t, false, getFilename());
} else {
// mark token as consumed -- fetch next token deferred until LA/LT
consume();
}
}
catch (TokenStreamException e) {
}
}
public void traceIn(String rname) {
traceDepth += 1;
for (int x=0; x<traceDepth; x++) System.out.print(" ");
try {
System.out.println("> "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()]
+ ") " + LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
}
catch (TokenStreamException e) {
}
}
public void traceOut(String rname) {
for (int x=0; x<traceDepth; x++) System.out.print(" ");
try {
System.out.println("< "+rname+"; LA(1)==("+ tokenNames[LT(1).getType()]
+ ") "+LT(1).getText() + " [inputState.guessing "+ inputState.guessing + "]");
}
catch (TokenStreamException e) {
}
traceDepth -= 1;
}
}
translationUnit
: ( externalList )? /* Empty source files are allowed. */
;
asm_expr
: "asm"^
("volatile")? LCURLY expr RCURLY ( SEMI )+
;
idList
: ID ( options{warnWhenFollowAmbig=false;}: COMMA ID )*
;
externalDef
: ( "typedef" | declaration )=> declaration
| ( functionPrefix )=> functionDef
| typelessDeclaration
| asm_expr
| SEMI
;
/* these two are here because GCC allows "cat = 13;" as a valid program! */
functionPrefix
{ String declName; }
: ( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
| //epsilon
)
declName = d:declarator[true]
( declaration )* (VARARGS)? ( SEMI )*
LCURLY
;
typelessDeclaration
{ AST typeMissing = #[NTypeMissing]; }
: initDeclList[typeMissing] SEMI { ## = #( #[NTypeMissing], ##); }
;
initializer
: ( ( ( (initializerElementLabel)=> initializerElementLabel )?
( assignExpr | lcurlyInitializer ) { ## = #( #[NInitializer], ## ); }
)
| lcurlyInitializer
)
;
// GCC allows more specific initializers
initializerElementLabel
: ( ( LBRACKET ((constExpr VARARGS)=> rangeExpr | constExpr) RBRACKET (ASSIGN)? )
| ID COLON
| DOT ID ASSIGN
)
{ ## = #( #[NInitializerElementLabel], ##) ; }
;
// GCC allows empty initializer lists
lcurlyInitializer
:
LCURLY^ (initializerList ( COMMA! )? )? RCURLY
{ ##.setType( NLcurlyInitializer ); }
;
initializerList
: initializer ( options{warnWhenFollowAmbig=false;}:COMMA! initializer )*
;
declarator[boolean isFunctionDefinition] returns [String declName]
{ declName = ""; }
:
( pointerGroup )?
( id:ID { declName = id.getText(); }
| LPAREN declName = declarator[false] RPAREN
)
( declaratorParamaterList[isFunctionDefinition, declName]
| LBRACKET ( expr )? RBRACKET
)*
{ ## = #( #[NDeclarator], ## ); }
;
declaratorParamaterList[boolean isFunctionDefinition, String declName]
:
LPAREN^
{
if (isFunctionDefinition) {
pushScope(declName);
}
else {
pushScope("!"+declName);
}
}
(
(declSpecifiers)=> parameterTypeList
| (idList)?
)
{
popScope();
}
( COMMA! )?
RPAREN
{ ##.setType(NParameterTypeList); }
;
parameterTypeList
: parameterDeclaration
( options {
warnWhenFollowAmbig = false;
} :
( COMMA | SEMI )
parameterDeclaration
)*
( ( COMMA | SEMI )
VARARGS
)?
;
declarationList
: ( options { // this loop properly aborts when
// it finds a non-typedefName ID MBZ
warnWhenFollowAmbig = false;
} :
localLabelDeclaration
| ( declarationPredictor )=> declaration
)+
;
localLabelDeclaration
: ( //GNU note: any __label__ declarations must come before regular declarations.
"__label__"^ ID (options{warnWhenFollowAmbig=false;}: COMMA! ID)* ( COMMA! )? ( SEMI! )+
)
;
declaration
{ AST ds1 = null; }
: ds:declSpecifiers { ds1 = astFactory.dupList(#ds); }
(
initDeclList[ds1]
)?
( SEMI )+
{ ## = #( #[NDeclaration], ##); }
;
functionStorageClassSpecifier
: "extern"
| "static"
| "inline"
;
typeSpecifier [int specCount] returns [int retSpecCount]
{ retSpecCount = specCount + 1; }
:
( "void"
| "char"
| "short"
| "int"
| "long"
| "float"
| "double"
| "signed"
| "unsigned"
| "byte"
| "boolean"
| "Servo"
| "Wire"
| structOrUnionSpecifier ( options{warnWhenFollowAmbig=false;}: attributeDecl )*
| enumSpecifier
| { specCount==0 }? typedefName
| "typeof"^ LPAREN
( ( typeName )=> typeName
| expr
)
RPAREN
| "__complex"
)
;
structOrUnionSpecifier
{ String scopeName; }
: sou:structOrUnion!
( ( ID LCURLY )=> i:ID l:LCURLY
{
scopeName = #sou.getText() + " " + #i.getText();
#l.setText(scopeName);
pushScope(scopeName);
}
( structDeclarationList )?
{ popScope();}
RCURLY
| l1:LCURLY
{
scopeName = getAScopeName();
#l1.setText(scopeName);
pushScope(scopeName);
}
( structDeclarationList )?
{ popScope(); }
RCURLY
| ID
)
{
## = #( #sou, ## );
}
;
structDeclaration
: specifierQualifierList structDeclaratorList ( COMMA! )? ( SEMI! )+
;
structDeclaratorList
: structDeclarator ( options{warnWhenFollowAmbig=false;}: COMMA! structDeclarator )*
;
structDeclarator
: ( declarator[false] )?
( COLON constExpr )?
( attributeDecl )*
{ ## = #( #[NStructDeclarator], ##); }
;
enumSpecifier
: "enum"^
( ( ID LCURLY )=> i:ID LCURLY enumList[i.getText()] RCURLY
| LCURLY enumList["anonymous"] RCURLY
| ID
)
;
enumList[String enumName]
: enumerator[enumName] ( options{warnWhenFollowAmbig=false;}: COMMA! enumerator[enumName] )* ( COMMA! )?
;
initDeclList[AST declarationSpecifiers]
: initDecl[declarationSpecifiers]
( options{warnWhenFollowAmbig=false;}: COMMA! initDecl[declarationSpecifiers] )*
( COMMA! )?
;
initDecl[AST declarationSpecifiers]
{ String declName = ""; }
: declName = d:declarator[false]
{ AST ds1, d1;
ds1 = astFactory.dupList(declarationSpecifiers);
d1 = astFactory.dupList(#d);
symbolTable.add(declName, #(null, ds1, d1) );
}
( attributeDecl )*
( ASSIGN initializer
| COLON expr
)?
{ ## = #( #[NInitDecl], ## ); }
;
attributeDecl
: "__attribute"^ LPAREN LPAREN attributeList RPAREN RPAREN
| "asm"^ LPAREN stringConst RPAREN { ##.setType( NAsmAttribute ); }
;
attributeList
: attribute ( options{warnWhenFollowAmbig=false;}: COMMA attribute)* ( COMMA )?
;
attribute
: ( ~(LPAREN | RPAREN | COMMA)
| LPAREN attributeList RPAREN
)*
;
compoundStatement[String scopeName]
: LCURLY^
{
pushScope(scopeName);
}
( //this ambiguity is ok, declarationList and nestedFunctionDef end properly
options {
warnWhenFollowAmbig = false;
} :
( "typedef" | "__label__" | declaration )=> declarationList
| (nestedFunctionDef)=> nestedFunctionDef
)*
( statementList )?
{ popScope(); }
RCURLY
{ ##.setType( NCompoundStatement ); ##.setAttribute( "scopeName", scopeName ); }
;
nestedFunctionDef
{ String declName; }
: ( "auto" )? //only for nested functions
( (functionDeclSpecifiers)=> ds:functionDeclSpecifiers
)?
declName = d:declarator[false]
{
AST d2, ds2;
d2 = astFactory.dupList(#d);
ds2 = astFactory.dupList(#ds);
symbolTable.add(declName, #(null, ds2, d2));
pushScope(declName);
}
( declaration )*
{ popScope(); }
compoundStatement[declName]
{ ## = #( #[NFunctionDef], ## );}
;
statement
: SEMI // Empty statements
| compoundStatement[getAScopeName()] // Group of statements
| expr SEMI! { ## = #( #[NStatementExpr], ## );} // Expressions
// Iteration statements:
| "while"^ LPAREN! expr RPAREN! statement
| "do"^ statement "while"! LPAREN! expr RPAREN! SEMI!
|! "for"
LPAREN ( e1:expr )? SEMI ( e2:expr )? SEMI ( e3:expr )? RPAREN
s:statement
{
if ( #e1 == null) { #e1 = #[ NEmptyExpression ]; }
if ( #e2 == null) { #e2 = #[ NEmptyExpression ]; }
if ( #e3 == null) { #e3 = #[ NEmptyExpression ]; }
## = #( #[LITERAL_for, "for"], #e1, #e2, #e3, #s );
}
// Jump statements:
| "goto"^ expr SEMI!
| "continue" SEMI!
| "break" SEMI!
| "return"^ ( expr )? SEMI!
| ID COLON! (options {warnWhenFollowAmbig=false;}: statement)? { ## = #( #[NLabel], ## ); }
// GNU allows range expressions in case statements
| "case"^ ((constExpr VARARGS)=> rangeExpr | constExpr) COLON! ( options{warnWhenFollowAmbig=false;}:statement )?
| "default"^ COLON! ( options{warnWhenFollowAmbig=false;}: statement )?
// Selection statements:
| "if"^
LPAREN! expr RPAREN! statement
( //standard if-else ambiguity
options {
warnWhenFollowAmbig = false;
} :
"else" statement )?
| "switch"^ LPAREN! expr RPAREN! statement
;
conditionalExpr
: logicalOrExpr
( QUESTION^ (expr)? COLON conditionalExpr )?
;
rangeExpr //used in initializers only
: constExpr VARARGS constExpr
{ ## = #(#[NRangeExpr], ##); }
;
castExpr
: ( LPAREN typeName RPAREN )=>
LPAREN^ typeName RPAREN ( castExpr | lcurlyInitializer )
{ ##.setType(NCast); }
| unaryExpr
;
nonemptyAbstractDeclarator
: (
pointerGroup
( (LPAREN
( nonemptyAbstractDeclarator
| parameterTypeList
)?
( COMMA! )?
RPAREN)
| (LBRACKET (expr)? RBRACKET)
)*
| ( (LPAREN
( nonemptyAbstractDeclarator
| parameterTypeList
)?
( COMMA! )?
RPAREN)
| (LBRACKET (expr)? RBRACKET)
)+
)
{ ## = #( #[NNonemptyAbstractDeclarator], ## ); }
;
unaryExpr
: postfixExpr
| INC^ castExpr
| DEC^ castExpr
| u:unaryOperator castExpr { ## = #( #[NUnaryExpr], ## ); }
| "sizeof"^
( ( LPAREN typeName )=> LPAREN typeName RPAREN
| unaryExpr
)
| "__alignof"^
( ( LPAREN typeName )=> LPAREN typeName RPAREN
| unaryExpr
)
| gnuAsmExpr
;
unaryOperator
: BAND
| STAR
| PLUS
| MINUS
| BNOT //also stands for complex conjugation
| LNOT
| LAND //for label dereference (&&label)
| "__real"
| "__imag"
;
gnuAsmExpr
: "asm"^ ("volatile")?
LPAREN stringConst
( options { warnWhenFollowAmbig = false; }:
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
( options { warnWhenFollowAmbig = false; }:
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
)?
)?
( COLON stringConst ( COMMA stringConst)* )?
RPAREN
{ ##.setType(NGnuAsmExpr); }
;
//GCC requires the PARENs
strOptExprPair
: stringConst ( LPAREN expr RPAREN )?
;
primaryExpr
: ID
| Number
| charConst
| stringConst
// JTC:
// ID should catch the enumerator
// leaving it in gives ambiguous err
// | enumerator
| (LPAREN LCURLY) => LPAREN^ compoundStatement[getAScopeName()] RPAREN
| LPAREN^ expr RPAREN { ##.setType(NExpressionGroup); }
;
{
// import CToken;
import java.io.*;
// import LineObject;
import antlr.*;
}
class WLexer extends StdCLexer;
options
{
k = 3;
importVocab = W;
testLiterals = false;
}
tokens {
LITERAL___extension__ = "__extension__";
}
{
public void initialize(String src)
{
setOriginalSource(src);
initialize();
}
public void initialize()
{
literals.put(new ANTLRHashString("__alignof__", this), new Integer(LITERAL___alignof));
literals.put(new ANTLRHashString("__asm", this), new Integer(LITERAL_asm));
literals.put(new ANTLRHashString("__asm__", this), new Integer(LITERAL_asm));
literals.put(new ANTLRHashString("__attribute__", this), new Integer(LITERAL___attribute));
literals.put(new ANTLRHashString("__complex__", this), new Integer(LITERAL___complex));
literals.put(new ANTLRHashString("__const", this), new Integer(LITERAL_const));
literals.put(new ANTLRHashString("__const__", this), new Integer(LITERAL_const));
literals.put(new ANTLRHashString("__imag__", this), new Integer(LITERAL___imag));
literals.put(new ANTLRHashString("__inline", this), new Integer(LITERAL_inline));
literals.put(new ANTLRHashString("__inline__", this), new Integer(LITERAL_inline));
literals.put(new ANTLRHashString("__real__", this), new Integer(LITERAL___real));
literals.put(new ANTLRHashString("__signed", this), new Integer(LITERAL_signed));
literals.put(new ANTLRHashString("__signed__", this), new Integer(LITERAL_signed));
literals.put(new ANTLRHashString("__typeof", this), new Integer(LITERAL_typeof));
literals.put(new ANTLRHashString("__typeof__", this), new Integer(LITERAL_typeof));
literals.put(new ANTLRHashString("__volatile", this), new Integer(LITERAL_volatile));
literals.put(new ANTLRHashString("__volatile__", this), new Integer(LITERAL_volatile));
}
LineObject lineObject = new LineObject();
String originalSource = "";
PreprocessorInfoChannel preprocessorInfoChannel = new PreprocessorInfoChannel();
int tokenNumber = 0;
boolean countingTokens = true;
int deferredLineCount = 0;
public void setCountingTokens(boolean ct)
{
countingTokens = ct;
if ( countingTokens ) {
tokenNumber = 0;
}
else {
tokenNumber = 1;
}
}
public void setOriginalSource(String src)
{
originalSource = src;
lineObject.setSource(src);
}
public void setSource(String src)
{
lineObject.setSource(src);
}
public PreprocessorInfoChannel getPreprocessorInfoChannel()
{
return preprocessorInfoChannel;
}
public void setPreprocessingDirective(String pre)
{
preprocessorInfoChannel.addLineForTokenNumber( pre, new Integer(tokenNumber) );
}
protected Token makeToken(int t)
{
if ( t != Token.SKIP && countingTokens) {
tokenNumber++;
}
CToken tok = (CToken) super.makeToken(t);
tok.setLine(lineObject.line);
tok.setSource(lineObject.source);
tok.setTokenNumber(tokenNumber);
lineObject.line += deferredLineCount;
deferredLineCount = 0;
return tok;
}
public void deferredNewline() {
deferredLineCount++;
}
public void newline() {
lineObject.newline();
}
}
Whitespace
: ( ( ' ' | '\t' | '\014')
| "\r\n" { newline(); }
| ( '\n' | '\r' ) { newline(); }
) { _ttype = Token.SKIP; }
;
protected
Escape
: '\\'
( options{warnWhenFollowAmbig=false;}:
~('0'..'7' | 'x')
| ('0'..'3') ( options{warnWhenFollowAmbig=false;}: Digit )*
| ('4'..'7') ( options{warnWhenFollowAmbig=false;}: Digit )*
| 'x' ( options{warnWhenFollowAmbig=false;}: Digit | 'a'..'f' | 'A'..'F' )+
)
;
protected IntSuffix
: 'L'
| 'l'
| 'U'
| 'u'
| 'I'
| 'i'
| 'J'
| 'j'
;
protected NumberSuffix
:
IntSuffix
| 'F'
| 'f'
;
Number
: ( ( Digit )+ ( '.' | 'e' | 'E' ) )=> ( Digit )+
( '.' ( Digit )* ( Exponent )?
| Exponent
)
( NumberSuffix
)*
| ( "..." )=> "..." { _ttype = VARARGS; }
| '.' { _ttype = DOT; }
( ( Digit )+ ( Exponent )?
{ _ttype = Number; }
( NumberSuffix
)*
)?
| '0' ( '0'..'7' )*
( NumberSuffix
)*
| '1'..'9' ( Digit )*
( NumberSuffix
)*
| '0' ( 'x' | 'X' ) ( 'a'..'f' | 'A'..'F' | Digit )+
( IntSuffix
)*
;
IDMEAT
:
i:ID {
if ( i.getType() == LITERAL___extension__ ) {
$setType(Token.SKIP);
}
else {
$setType(i.getType());
}
}
;
protected ID
options
{
testLiterals = true;
}
: ( 'a'..'z' | 'A'..'Z' | '_' | '$')
( 'a'..'z' | 'A'..'Z' | '_' | '$' | '0'..'9' )*
;
WideCharLiteral
:
'L' CharLiteral
{ $setType(CharLiteral); }
;
WideStringLiteral
:
'L' StringLiteral
{ $setType(StringLiteral); }
;
StringLiteral
:
'"'
( ('\\' ~('\n'))=> Escape
| ( '\r' { newline(); }
| '\n' {
newline();
}
| '\\' '\n' {
newline();
}
)
| ~( '"' | '\r' | '\n' | '\\' )
)*
'"'
;

6718
app/preproc/WParser.java Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,162 @@
// $ANTLR 2.7.2: "expandedWParser.g" -> "WLexer.java"$
package processing.app.preproc;
import java.io.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
public interface WTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int LITERAL_typedef = 4;
int LITERAL_asm = 5;
int LITERAL_volatile = 6;
int LCURLY = 7;
int RCURLY = 8;
int SEMI = 9;
int LITERAL_struct = 10;
int LITERAL_union = 11;
int LITERAL_enum = 12;
int LITERAL_auto = 13;
int LITERAL_register = 14;
int LITERAL_extern = 15;
int LITERAL_static = 16;
int LITERAL_const = 17;
int LITERAL_void = 18;
int LITERAL_char = 19;
int LITERAL_short = 20;
int LITERAL_int = 21;
int LITERAL_long = 22;
int LITERAL_float = 23;
int LITERAL_double = 24;
int LITERAL_signed = 25;
int LITERAL_unsigned = 26;
int ID = 27;
int COMMA = 28;
int COLON = 29;
int ASSIGN = 30;
int STAR = 31;
int LPAREN = 32;
int RPAREN = 33;
int LBRACKET = 34;
int RBRACKET = 35;
int VARARGS = 36;
int LITERAL_while = 37;
int LITERAL_do = 38;
int LITERAL_for = 39;
int LITERAL_goto = 40;
int LITERAL_continue = 41;
int LITERAL_break = 42;
int LITERAL_return = 43;
int LITERAL_case = 44;
int LITERAL_default = 45;
int LITERAL_if = 46;
int LITERAL_else = 47;
int LITERAL_switch = 48;
int DIV_ASSIGN = 49;
int PLUS_ASSIGN = 50;
int MINUS_ASSIGN = 51;
int STAR_ASSIGN = 52;
int MOD_ASSIGN = 53;
int RSHIFT_ASSIGN = 54;
int LSHIFT_ASSIGN = 55;
int BAND_ASSIGN = 56;
int BOR_ASSIGN = 57;
int BXOR_ASSIGN = 58;
int QUESTION = 59;
int LOR = 60;
int LAND = 61;
int BOR = 62;
int BXOR = 63;
int BAND = 64;
int EQUAL = 65;
int NOT_EQUAL = 66;
int LT = 67;
int LTE = 68;
int GT = 69;
int GTE = 70;
int LSHIFT = 71;
int RSHIFT = 72;
int PLUS = 73;
int MINUS = 74;
int DIV = 75;
int MOD = 76;
int INC = 77;
int DEC = 78;
int LITERAL_sizeof = 79;
int BNOT = 80;
int LNOT = 81;
int PTR = 82;
int DOT = 83;
int CharLiteral = 84;
int StringLiteral = 85;
int IntOctalConst = 86;
int LongOctalConst = 87;
int UnsignedOctalConst = 88;
int IntIntConst = 89;
int LongIntConst = 90;
int UnsignedIntConst = 91;
int IntHexConst = 92;
int LongHexConst = 93;
int UnsignedHexConst = 94;
int FloatDoubleConst = 95;
int DoubleDoubleConst = 96;
int LongDoubleConst = 97;
int NTypedefName = 98;
int NInitDecl = 99;
int NDeclarator = 100;
int NStructDeclarator = 101;
int NDeclaration = 102;
int NCast = 103;
int NPointerGroup = 104;
int NExpressionGroup = 105;
int NFunctionCallArgs = 106;
int NNonemptyAbstractDeclarator = 107;
int NInitializer = 108;
int NStatementExpr = 109;
int NEmptyExpression = 110;
int NParameterTypeList = 111;
int NFunctionDef = 112;
int NCompoundStatement = 113;
int NParameterDeclaration = 114;
int NCommaExpr = 115;
int NUnaryExpr = 116;
int NLabel = 117;
int NPostfixExpr = 118;
int NRangeExpr = 119;
int NStringSeq = 120;
int NInitializerElementLabel = 121;
int NLcurlyInitializer = 122;
int NAsmAttribute = 123;
int NGnuAsmExpr = 124;
int NTypeMissing = 125;
int Vocabulary = 126;
int Whitespace = 127;
int Comment = 128;
int CPPComment = 129;
int PREPROC_DIRECTIVE = 130;
int Space = 131;
int LineDirective = 132;
int BadStringLiteral = 133;
int Escape = 134;
int Digit = 135;
int LongSuffix = 136;
int UnsignedSuffix = 137;
int FloatSuffix = 138;
int Exponent = 139;
int Number = 140;
int LITERAL___label__ = 141;
int LITERAL_inline = 142;
int LITERAL_byte = 143;
int LITERAL_boolean = 144;
int LITERAL_Servo = 145;
int LITERAL_Wire = 146;
int LITERAL_typeof = 147;
int LITERAL___complex = 148;
int LITERAL___attribute = 149;
int LITERAL___alignof = 150;
int LITERAL___real = 151;
int LITERAL___imag = 152;
}

151
app/preproc/WTokenTypes.txt Normal file
View File

@ -0,0 +1,151 @@
// $ANTLR 2.7.2: expandedWParser.g -> WTokenTypes.txt$
W // output token vocab name
LITERAL_typedef="typedef"=4
LITERAL_asm="asm"=5
LITERAL_volatile="volatile"=6
LCURLY=7
RCURLY=8
SEMI=9
LITERAL_struct="struct"=10
LITERAL_union="union"=11
LITERAL_enum="enum"=12
LITERAL_auto="auto"=13
LITERAL_register="register"=14
LITERAL_extern="extern"=15
LITERAL_static="static"=16
LITERAL_const="const"=17
LITERAL_void="void"=18
LITERAL_char="char"=19
LITERAL_short="short"=20
LITERAL_int="int"=21
LITERAL_long="long"=22
LITERAL_float="float"=23
LITERAL_double="double"=24
LITERAL_signed="signed"=25
LITERAL_unsigned="unsigned"=26
ID=27
COMMA=28
COLON=29
ASSIGN=30
STAR=31
LPAREN=32
RPAREN=33
LBRACKET=34
RBRACKET=35
VARARGS=36
LITERAL_while="while"=37
LITERAL_do="do"=38
LITERAL_for="for"=39
LITERAL_goto="goto"=40
LITERAL_continue="continue"=41
LITERAL_break="break"=42
LITERAL_return="return"=43
LITERAL_case="case"=44
LITERAL_default="default"=45
LITERAL_if="if"=46
LITERAL_else="else"=47
LITERAL_switch="switch"=48
DIV_ASSIGN=49
PLUS_ASSIGN=50
MINUS_ASSIGN=51
STAR_ASSIGN=52
MOD_ASSIGN=53
RSHIFT_ASSIGN=54
LSHIFT_ASSIGN=55
BAND_ASSIGN=56
BOR_ASSIGN=57
BXOR_ASSIGN=58
QUESTION=59
LOR=60
LAND=61
BOR=62
BXOR=63
BAND=64
EQUAL=65
NOT_EQUAL=66
LT=67
LTE=68
GT=69
GTE=70
LSHIFT=71
RSHIFT=72
PLUS=73
MINUS=74
DIV=75
MOD=76
INC=77
DEC=78
LITERAL_sizeof="sizeof"=79
BNOT=80
LNOT=81
PTR=82
DOT=83
CharLiteral=84
StringLiteral=85
IntOctalConst=86
LongOctalConst=87
UnsignedOctalConst=88
IntIntConst=89
LongIntConst=90
UnsignedIntConst=91
IntHexConst=92
LongHexConst=93
UnsignedHexConst=94
FloatDoubleConst=95
DoubleDoubleConst=96
LongDoubleConst=97
NTypedefName=98
NInitDecl=99
NDeclarator=100
NStructDeclarator=101
NDeclaration=102
NCast=103
NPointerGroup=104
NExpressionGroup=105
NFunctionCallArgs=106
NNonemptyAbstractDeclarator=107
NInitializer=108
NStatementExpr=109
NEmptyExpression=110
NParameterTypeList=111
NFunctionDef=112
NCompoundStatement=113
NParameterDeclaration=114
NCommaExpr=115
NUnaryExpr=116
NLabel=117
NPostfixExpr=118
NRangeExpr=119
NStringSeq=120
NInitializerElementLabel=121
NLcurlyInitializer=122
NAsmAttribute=123
NGnuAsmExpr=124
NTypeMissing=125
Vocabulary=126
Whitespace=127
Comment=128
CPPComment=129
PREPROC_DIRECTIVE("a line directive")=130
Space=131
LineDirective=132
BadStringLiteral=133
Escape=134
Digit=135
LongSuffix=136
UnsignedSuffix=137
FloatSuffix=138
Exponent=139
Number=140
LITERAL___label__="__label__"=141
LITERAL_inline="inline"=142
LITERAL_byte="byte"=143
LITERAL_boolean="boolean"=144
LITERAL_Servo="Servo"=145
LITERAL_Wire="Wire"=146
LITERAL_typeof="typeof"=147
LITERAL___complex="__complex"=148
LITERAL___attribute="__attribute"=149
LITERAL___alignof="__alignof"=150
LITERAL___real="__real"=151
LITERAL___imag="__imag"=152

857
app/preproc/WTreeParser.g Executable file
View File

@ -0,0 +1,857 @@
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) Non, Inc. 1998 -- All Rights Reserved
PROJECT: C Compiler
MODULE: WTreeParser
FILE: WTreeParser.g
AUTHOR: Monty Zukowski (jamz@cdsnet.net) April 28, 1998
MODIFICATIONS: Hernando Barragan added support for the Wiring language
DESCRIPTION:
This tree grammar is for a Gnu C AST. No actions in it,
subclass to do something useful.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
header {
package processing.app.preproc;
import java.io.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
}
class WTreeParser extends TreeParser;
options
{
importVocab = W;
buildAST = false;
ASTLabelType = "TNode";
// Copied following options from java grammar.
codeGenMakeSwitchThreshold = 2;
codeGenBitsetTestThreshold = 3;
}
{
int traceDepth = 0;
public void reportError(RecognitionException ex) {
if ( ex != null) {
System.err.println("ANTLR Tree Parsing RecognitionException Error: " + ex.getClass().getName() + " " + ex );
ex.printStackTrace(System.err);
}
}
public void reportError(NoViableAltException ex) {
System.err.println("ANTLR Tree Parsing NoViableAltException Error: " + ex.toString());
TNode.printTree( ex.node );
ex.printStackTrace(System.err);
}
public void reportError(MismatchedTokenException ex) {
if ( ex != null) {
TNode.printTree( ex.node );
System.err.println("ANTLR Tree Parsing MismatchedTokenException Error: " + ex );
ex.printStackTrace(System.err);
}
}
public void reportError(String s) {
System.err.println("ANTLR Error from String: " + s);
}
public void reportWarning(String s) {
System.err.println("ANTLR Warning from String: " + s);
}
protected void match(AST t, int ttype) throws MismatchedTokenException {
//System.out.println("match("+ttype+"); cursor is "+t);
super.match(t, ttype);
}
public void match(AST t, BitSet b) throws MismatchedTokenException {
//System.out.println("match("+b+"); cursor is "+t);
super.match(t, b);
}
protected void matchNot(AST t, int ttype) throws MismatchedTokenException {
//System.out.println("matchNot("+ttype+"); cursor is "+t);
super.matchNot(t, ttype);
}
public void traceIn(String rname, AST t) {
traceDepth += 1;
for (int x=0; x<traceDepth; x++) System.out.print(" ");
super.traceIn(rname, t);
}
public void traceOut(String rname, AST t) {
for (int x=0; x<traceDepth; x++) System.out.print(" ");
super.traceOut(rname, t);
traceDepth -= 1;
}
}
translationUnit options {
defaultErrorHandler=false;
}
: ( externalList )?
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
externalList
: ( externalDef )+
;
externalDef
: declaration
| functionDef
| asm_expr
| SEMI
| typelessDeclaration
;
typelessDeclaration
: #(NTypeMissing initDeclList SEMI)
;
asm_expr
: #( "asm" ( "volatile" )? LCURLY expr RCURLY ( SEMI )+ )
;
declaration
: #( NDeclaration
declSpecifiers
(
initDeclList
)?
( SEMI )+
)
;
declSpecifiers
: ( storageClassSpecifier
| typeQualifier
| typeSpecifier
)+
;
storageClassSpecifier
: "auto"
| "register"
| "typedef"
| functionStorageClassSpecifier
;
functionStorageClassSpecifier
: "extern"
| "static"
| "inline"
;
typeQualifier
: "const"
| "volatile"
;
typeSpecifier
: "void"
| "char"
| "short"
| "int"
| "long"
| "float"
| "double"
| "signed"
| "unsigned"
| "byte"
| "boolean"
| "Servo"
| "Wire"
| structSpecifier ( attributeDecl )*
| unionSpecifier ( attributeDecl )*
| enumSpecifier
| typedefName
| #("typeof" LPAREN
( (typeName )=> typeName
| expr
)
RPAREN
)
| "__complex"
;
typedefName
: #(NTypedefName ID)
;
structSpecifier
: #( "struct" structOrUnionBody )
;
unionSpecifier
: #( "union" structOrUnionBody )
;
structOrUnionBody
: ( (ID LCURLY) => ID LCURLY
( structDeclarationList )?
RCURLY
| LCURLY
( structDeclarationList )?
RCURLY
| ID
)
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
structDeclarationList
: ( structDeclaration )+
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
structDeclaration
: specifierQualifierList structDeclaratorList
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
specifierQualifierList
: (
typeSpecifier
| typeQualifier
)+
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
structDeclaratorList
: ( structDeclarator )+
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
structDeclarator
:
#( NStructDeclarator
( declarator )?
( COLON expr )?
( attributeDecl )*
)
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
enumSpecifier
: #( "enum"
( ID )?
( LCURLY enumList RCURLY )?
)
;
enumList
: ( enumerator )+
;
enumerator
: ID ( ASSIGN expr )?
;
attributeDecl:
#( "__attribute" (.)* )
| #( NAsmAttribute LPAREN expr RPAREN )
;
initDeclList
: ( initDecl )+
;
initDecl
{ String declName = ""; }
: #( NInitDecl
declarator
( attributeDecl )*
( ASSIGN initializer
| COLON expr
)?
)
;
pointerGroup
: #( NPointerGroup ( STAR ( typeQualifier )* )+ )
;
idList
: ID ( COMMA ID )*
;
initializer
: #( NInitializer (initializerElementLabel)? expr )
| lcurlyInitializer
;
initializerElementLabel
: #( NInitializerElementLabel
(
( LBRACKET expr RBRACKET (ASSIGN)? )
| ID COLON
| DOT ID ASSIGN
)
)
;
lcurlyInitializer
: #( NLcurlyInitializer
initializerList
RCURLY
)
;
initializerList
: ( initializer )*
;
declarator
: #( NDeclarator
( pointerGroup )?
( id:ID
| LPAREN declarator RPAREN
)
( #( NParameterTypeList
(
parameterTypeList
| (idList)?
)
RPAREN
)
| LBRACKET ( expr )? RBRACKET
)*
)
;
parameterTypeList
: ( parameterDeclaration ( COMMA | SEMI )? )+ ( VARARGS )?
;
parameterDeclaration
: #( NParameterDeclaration
declSpecifiers
(declarator | nonemptyAbstractDeclarator)?
)
;
functionDef
: #( NFunctionDef
( functionDeclSpecifiers)?
declarator
(declaration | VARARGS)*
compoundStatement
)
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
functionDeclSpecifiers
:
( functionStorageClassSpecifier
| typeQualifier
| typeSpecifier
)+
;
declarationList
:
( //ANTLR doesn't know that declarationList properly eats all the declarations
//so it warns about the ambiguity
options {
warnWhenFollowAmbig = false;
} :
localLabelDecl
| declaration
)+
;
localLabelDecl
: #("__label__" (ID)+ )
;
compoundStatement
: #( NCompoundStatement
( declarationList
| functionDef
)*
( statementList )?
RCURLY
)
;
statementList
: ( statement )+
;
statement
: statementBody
;
statementBody
: SEMI // Empty statements
| compoundStatement // Group of statements
| #(NStatementExpr expr) // Expressions
// Iteration statements:
| #( "while" expr statement )
| #( "do" statement expr )
| #( "for"
expr expr expr
statement
)
// Jump statements:
| #( "goto" expr )
| "continue"
| "break"
| #( "return" ( expr )? )
// Labeled statements:
| #( NLabel ID (statement)? )
| #( "case" expr (statement)? )
| #( "default" (statement)? )
// Selection statements:
| #( "if"
expr statement
( "else" statement )?
)
| #( "switch" expr statement )
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
expr
: assignExpr
| conditionalExpr
| logicalOrExpr
| logicalAndExpr
| inclusiveOrExpr
| exclusiveOrExpr
| bitAndExpr
| equalityExpr
| relationalExpr
| shiftExpr
| additiveExpr
| multExpr
| castExpr
| unaryExpr
| postfixExpr
| primaryExpr
| commaExpr
| emptyExpr
| compoundStatementExpr
| initializer
| rangeExpr
| gnuAsmExpr
;
commaExpr
: #(NCommaExpr expr expr)
;
emptyExpr
: NEmptyExpression
;
compoundStatementExpr
: #(LPAREN compoundStatement RPAREN)
;
rangeExpr
: #(NRangeExpr expr VARARGS expr)
;
gnuAsmExpr
: #(NGnuAsmExpr
("volatile")?
LPAREN stringConst
( options { warnWhenFollowAmbig = false; }:
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
( options { warnWhenFollowAmbig = false; }:
COLON (strOptExprPair ( COMMA strOptExprPair)* )?
)?
)?
( COLON stringConst ( COMMA stringConst)* )?
RPAREN
)
;
strOptExprPair
: stringConst ( LPAREN expr RPAREN )?
;
assignExpr
: #( ASSIGN expr expr)
| #( DIV_ASSIGN expr expr)
| #( PLUS_ASSIGN expr expr)
| #( MINUS_ASSIGN expr expr)
| #( STAR_ASSIGN expr expr)
| #( MOD_ASSIGN expr expr)
| #( RSHIFT_ASSIGN expr expr)
| #( LSHIFT_ASSIGN expr expr)
| #( BAND_ASSIGN expr expr)
| #( BOR_ASSIGN expr expr)
| #( BXOR_ASSIGN expr expr)
;
conditionalExpr
: #( QUESTION expr (expr)? COLON expr )
;
logicalOrExpr
: #( LOR expr expr)
;
logicalAndExpr
: #( LAND expr expr )
;
inclusiveOrExpr
: #( BOR expr expr )
;
exclusiveOrExpr
: #( BXOR expr expr )
;
bitAndExpr
: #( BAND expr expr )
;
equalityExpr
: #( EQUAL expr expr)
| #( NOT_EQUAL expr expr)
;
relationalExpr
: #( LT expr expr)
| #( LTE expr expr)
| #( GT expr expr)
| #( GTE expr expr)
;
shiftExpr
: #( LSHIFT expr expr)
| #( RSHIFT expr expr)
;
additiveExpr
: #( PLUS expr expr)
| #( MINUS expr expr)
;
multExpr
: #( STAR expr expr)
| #( DIV expr expr)
| #( MOD expr expr)
;
castExpr
: #( NCast typeName RPAREN expr)
;
typeName
: specifierQualifierList (nonemptyAbstractDeclarator)?
;
nonemptyAbstractDeclarator
: #( NNonemptyAbstractDeclarator
( pointerGroup
( (LPAREN
( nonemptyAbstractDeclarator
| parameterTypeList
)?
RPAREN)
| (LBRACKET (expr)? RBRACKET)
)*
| ( (LPAREN
( nonemptyAbstractDeclarator
| parameterTypeList
)?
RPAREN)
| (LBRACKET (expr)? RBRACKET)
)+
)
)
;
unaryExpr
: #( INC expr )
| #( DEC expr )
| #( NUnaryExpr unaryOperator expr)
| #( "sizeof"
( ( LPAREN typeName )=> LPAREN typeName RPAREN
| expr
)
)
| #( "__alignof"
( ( LPAREN typeName )=> LPAREN typeName RPAREN
| expr
)
)
;
/*
exception
catch [RecognitionException ex]
{
reportError(ex);
System.out.println("PROBLEM TREE:\n"
+ _t.toStringList());
if (_t!=null) {_t = _t.getNextSibling();}
}
*/
unaryOperator
: BAND
| STAR
| PLUS
| MINUS
| BNOT
| LNOT
| LAND
| "__real"
| "__imag"
;
postfixExpr
: #( NPostfixExpr
primaryExpr
( PTR ID
| DOT ID
| #( NFunctionCallArgs (argExprList)? RPAREN )
| LBRACKET expr RBRACKET
| INC
| DEC
)+
)
;
primaryExpr
: ID
| Number
| charConst
| stringConst
// JTC:
// ID should catch the enumerator
// leaving it in gives ambiguous err
// | enumerator
| #( NExpressionGroup expr )
;
argExprList
: ( expr )+
;
protected
charConst
: CharLiteral
;
protected
stringConst
: #(NStringSeq (StringLiteral)+)
;
protected
intConst
: IntOctalConst
| LongOctalConst
| UnsignedOctalConst
| IntIntConst
| LongIntConst
| UnsignedIntConst
| IntHexConst
| LongHexConst
| UnsignedHexConst
;
protected
floatConst
: FloatDoubleConst
| DoubleDoubleConst
| LongDoubleConst
;

5551
app/preproc/WTreeParser.java Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,162 @@
// $ANTLR 2.7.2: "WTreeParser.g" -> "WTreeParser.java"$
package processing.app.preproc;
import java.io.*;
import antlr.CommonAST;
import antlr.DumpASTVisitor;
public interface WTreeParserTokenTypes {
int EOF = 1;
int NULL_TREE_LOOKAHEAD = 3;
int LITERAL_typedef = 4;
int LITERAL_asm = 5;
int LITERAL_volatile = 6;
int LCURLY = 7;
int RCURLY = 8;
int SEMI = 9;
int LITERAL_struct = 10;
int LITERAL_union = 11;
int LITERAL_enum = 12;
int LITERAL_auto = 13;
int LITERAL_register = 14;
int LITERAL_extern = 15;
int LITERAL_static = 16;
int LITERAL_const = 17;
int LITERAL_void = 18;
int LITERAL_char = 19;
int LITERAL_short = 20;
int LITERAL_int = 21;
int LITERAL_long = 22;
int LITERAL_float = 23;
int LITERAL_double = 24;
int LITERAL_signed = 25;
int LITERAL_unsigned = 26;
int ID = 27;
int COMMA = 28;
int COLON = 29;
int ASSIGN = 30;
int STAR = 31;
int LPAREN = 32;
int RPAREN = 33;
int LBRACKET = 34;
int RBRACKET = 35;
int VARARGS = 36;
int LITERAL_while = 37;
int LITERAL_do = 38;
int LITERAL_for = 39;
int LITERAL_goto = 40;
int LITERAL_continue = 41;
int LITERAL_break = 42;
int LITERAL_return = 43;
int LITERAL_case = 44;
int LITERAL_default = 45;
int LITERAL_if = 46;
int LITERAL_else = 47;
int LITERAL_switch = 48;
int DIV_ASSIGN = 49;
int PLUS_ASSIGN = 50;
int MINUS_ASSIGN = 51;
int STAR_ASSIGN = 52;
int MOD_ASSIGN = 53;
int RSHIFT_ASSIGN = 54;
int LSHIFT_ASSIGN = 55;
int BAND_ASSIGN = 56;
int BOR_ASSIGN = 57;
int BXOR_ASSIGN = 58;
int QUESTION = 59;
int LOR = 60;
int LAND = 61;
int BOR = 62;
int BXOR = 63;
int BAND = 64;
int EQUAL = 65;
int NOT_EQUAL = 66;
int LT = 67;
int LTE = 68;
int GT = 69;
int GTE = 70;
int LSHIFT = 71;
int RSHIFT = 72;
int PLUS = 73;
int MINUS = 74;
int DIV = 75;
int MOD = 76;
int INC = 77;
int DEC = 78;
int LITERAL_sizeof = 79;
int BNOT = 80;
int LNOT = 81;
int PTR = 82;
int DOT = 83;
int CharLiteral = 84;
int StringLiteral = 85;
int IntOctalConst = 86;
int LongOctalConst = 87;
int UnsignedOctalConst = 88;
int IntIntConst = 89;
int LongIntConst = 90;
int UnsignedIntConst = 91;
int IntHexConst = 92;
int LongHexConst = 93;
int UnsignedHexConst = 94;
int FloatDoubleConst = 95;
int DoubleDoubleConst = 96;
int LongDoubleConst = 97;
int NTypedefName = 98;
int NInitDecl = 99;
int NDeclarator = 100;
int NStructDeclarator = 101;
int NDeclaration = 102;
int NCast = 103;
int NPointerGroup = 104;
int NExpressionGroup = 105;
int NFunctionCallArgs = 106;
int NNonemptyAbstractDeclarator = 107;
int NInitializer = 108;
int NStatementExpr = 109;
int NEmptyExpression = 110;
int NParameterTypeList = 111;
int NFunctionDef = 112;
int NCompoundStatement = 113;
int NParameterDeclaration = 114;
int NCommaExpr = 115;
int NUnaryExpr = 116;
int NLabel = 117;
int NPostfixExpr = 118;
int NRangeExpr = 119;
int NStringSeq = 120;
int NInitializerElementLabel = 121;
int NLcurlyInitializer = 122;
int NAsmAttribute = 123;
int NGnuAsmExpr = 124;
int NTypeMissing = 125;
int Vocabulary = 126;
int Whitespace = 127;
int Comment = 128;
int CPPComment = 129;
int PREPROC_DIRECTIVE = 130;
int Space = 131;
int LineDirective = 132;
int BadStringLiteral = 133;
int Escape = 134;
int Digit = 135;
int LongSuffix = 136;
int UnsignedSuffix = 137;
int FloatSuffix = 138;
int Exponent = 139;
int Number = 140;
int LITERAL___label__ = 141;
int LITERAL_inline = 142;
int LITERAL_byte = 143;
int LITERAL_boolean = 144;
int LITERAL_Servo = 145;
int LITERAL_Wire = 146;
int LITERAL_typeof = 147;
int LITERAL___complex = 148;
int LITERAL___attribute = 149;
int LITERAL___alignof = 150;
int LITERAL___real = 151;
int LITERAL___imag = 152;
}

View File

@ -0,0 +1,151 @@
// $ANTLR 2.7.2: WTreeParser.g -> WTreeParserTokenTypes.txt$
WTreeParser // output token vocab name
LITERAL_typedef="typedef"=4
LITERAL_asm="asm"=5
LITERAL_volatile="volatile"=6
LCURLY=7
RCURLY=8
SEMI=9
LITERAL_struct="struct"=10
LITERAL_union="union"=11
LITERAL_enum="enum"=12
LITERAL_auto="auto"=13
LITERAL_register="register"=14
LITERAL_extern="extern"=15
LITERAL_static="static"=16
LITERAL_const="const"=17
LITERAL_void="void"=18
LITERAL_char="char"=19
LITERAL_short="short"=20
LITERAL_int="int"=21
LITERAL_long="long"=22
LITERAL_float="float"=23
LITERAL_double="double"=24
LITERAL_signed="signed"=25
LITERAL_unsigned="unsigned"=26
ID=27
COMMA=28
COLON=29
ASSIGN=30
STAR=31
LPAREN=32
RPAREN=33
LBRACKET=34
RBRACKET=35
VARARGS=36
LITERAL_while="while"=37
LITERAL_do="do"=38
LITERAL_for="for"=39
LITERAL_goto="goto"=40
LITERAL_continue="continue"=41
LITERAL_break="break"=42
LITERAL_return="return"=43
LITERAL_case="case"=44
LITERAL_default="default"=45
LITERAL_if="if"=46
LITERAL_else="else"=47
LITERAL_switch="switch"=48
DIV_ASSIGN=49
PLUS_ASSIGN=50
MINUS_ASSIGN=51
STAR_ASSIGN=52
MOD_ASSIGN=53
RSHIFT_ASSIGN=54
LSHIFT_ASSIGN=55
BAND_ASSIGN=56
BOR_ASSIGN=57
BXOR_ASSIGN=58
QUESTION=59
LOR=60
LAND=61
BOR=62
BXOR=63
BAND=64
EQUAL=65
NOT_EQUAL=66
LT=67
LTE=68
GT=69
GTE=70
LSHIFT=71
RSHIFT=72
PLUS=73
MINUS=74
DIV=75
MOD=76
INC=77
DEC=78
LITERAL_sizeof="sizeof"=79
BNOT=80
LNOT=81
PTR=82
DOT=83
CharLiteral=84
StringLiteral=85
IntOctalConst=86
LongOctalConst=87
UnsignedOctalConst=88
IntIntConst=89
LongIntConst=90
UnsignedIntConst=91
IntHexConst=92
LongHexConst=93
UnsignedHexConst=94
FloatDoubleConst=95
DoubleDoubleConst=96
LongDoubleConst=97
NTypedefName=98
NInitDecl=99
NDeclarator=100
NStructDeclarator=101
NDeclaration=102
NCast=103
NPointerGroup=104
NExpressionGroup=105
NFunctionCallArgs=106
NNonemptyAbstractDeclarator=107
NInitializer=108
NStatementExpr=109
NEmptyExpression=110
NParameterTypeList=111
NFunctionDef=112
NCompoundStatement=113
NParameterDeclaration=114
NCommaExpr=115
NUnaryExpr=116
NLabel=117
NPostfixExpr=118
NRangeExpr=119
NStringSeq=120
NInitializerElementLabel=121
NLcurlyInitializer=122
NAsmAttribute=123
NGnuAsmExpr=124
NTypeMissing=125
Vocabulary=126
Whitespace=127
Comment=128
CPPComment=129
PREPROC_DIRECTIVE("a line directive")=130
Space=131
LineDirective=132
BadStringLiteral=133
Escape=134
Digit=135
LongSuffix=136
UnsignedSuffix=137
FloatSuffix=138
Exponent=139
Number=140
LITERAL___label__="__label__"=141
LITERAL_inline="inline"=142
LITERAL_byte="byte"=143
LITERAL_boolean="boolean"=144
LITERAL_Servo="Servo"=145
LITERAL_Wire="Wire"=146
LITERAL_typeof="typeof"=147
LITERAL___complex="__complex"=148
LITERAL___attribute="__attribute"=149
LITERAL___alignof="__alignof"=150
LITERAL___real="__real"=151
LITERAL___imag="__imag"=152

View File

@ -1,11 +0,0 @@
#!/bin/sh
rm -f *Lexer.java
rm -f *Recognizer.java
rm -f *TokenTypes.java
rm -f *TokenTypes.txt
rm -f *TreeParser.java
rm -f *TreeParserTokenTypes.java
rm -f *TreeParserTokenTypes.txt
rm -f expanded*.g

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,326 +0,0 @@
package antlr;
/** Java 1.3 AST Recognizer Grammar
*
* Author: (see java.g preamble)
*
* This grammar is in the PUBLIC DOMAIN
*/
class JavaTreeParser extends TreeParser;
options {
importVocab = Java;
}
compilationUnit
: (packageDefinition)?
(importDefinition)*
(typeDefinition)*
;
packageDefinition
: #( PACKAGE_DEF identifier )
;
importDefinition
: #( IMPORT identifierStar )
;
typeDefinition
: #(CLASS_DEF modifiers IDENT extendsClause implementsClause objBlock )
| #(INTERFACE_DEF modifiers IDENT extendsClause interfaceBlock )
;
typeSpec
: #(TYPE typeSpecArray)
;
typeSpecArray
: #( ARRAY_DECLARATOR typeSpecArray )
| type
;
type: identifier
| builtInType
;
builtInType
: "void"
| "boolean"
| "byte"
| "char"
| "short"
| "int"
| "float"
| "long"
| "double"
;
modifiers
: #( MODIFIERS (modifier)* )
;
modifier
: "private"
| "public"
| "protected"
| "static"
| "transient"
| "final"
| "abstract"
| "native"
| "threadsafe"
| "synchronized"
| "const"
| "volatile"
| "strictfp"
;
extendsClause
: #(EXTENDS_CLAUSE (identifier)* )
;
implementsClause
: #(IMPLEMENTS_CLAUSE (identifier)* )
;
interfaceBlock
: #( OBJBLOCK
( methodDecl
| variableDef
)*
)
;
objBlock
: #( OBJBLOCK
( ctorDef
| methodDef
| variableDef
| typeDefinition
| #(STATIC_INIT slist)
| #(INSTANCE_INIT slist)
)*
)
;
ctorDef
: #(CTOR_DEF modifiers methodHead (slist)?)
;
methodDecl
: #(METHOD_DEF modifiers typeSpec methodHead)
;
methodDef
: #(METHOD_DEF modifiers typeSpec methodHead (slist)?)
;
variableDef
: #(VARIABLE_DEF modifiers typeSpec variableDeclarator varInitializer)
;
parameterDef
: #(PARAMETER_DEF modifiers typeSpec IDENT )
;
objectinitializer
: #(INSTANCE_INIT slist)
;
variableDeclarator
: IDENT
| LBRACK variableDeclarator
;
varInitializer
: #(ASSIGN initializer)
|
;
initializer
: expression
| arrayInitializer
;
arrayInitializer
: #(ARRAY_INIT (initializer)*)
;
methodHead
: IDENT #( PARAMETERS (parameterDef)* ) (throwsClause)?
;
throwsClause
: #( "throws" (identifier)* )
;
identifier
: IDENT
| #( DOT identifier IDENT )
;
identifierStar
: IDENT
| #( DOT identifier (STAR|IDENT) )
;
slist
: #( SLIST (stat)* )
;
stat: typeDefinition
| variableDef
| expression
| #(LABELED_STAT IDENT stat)
| #("if" expression stat (stat)? )
| #( "for"
#(FOR_INIT (variableDef | elist)?)
#(FOR_CONDITION (expression)?)
#(FOR_ITERATOR (elist)?)
stat
)
| #("while" expression stat)
| #("do" stat expression)
| #("break" (IDENT)? )
| #("continue" (IDENT)? )
| #("return" (expression)? )
| #("switch" expression (caseGroup)*)
| #("throw" expression)
| #("synchronized" expression stat)
| tryBlock
| slist // nested SLIST
// uncomment to make assert JDK 1.4 stuff work
| #("assert" expression (expression)?)
| EMPTY_STAT
;
caseGroup
: #(CASE_GROUP (#("case" expression) | "default")+ slist)
;
tryBlock
: #( "try" slist (handler)* (#("finally" slist))? )
;
handler
: #( "catch" parameterDef slist )
;
elist
: #( ELIST (expression)* )
;
expression
: #(EXPR expr)
;
expr: #(QUESTION expr expr expr) // trinary operator
| #(ASSIGN expr expr) // binary operators...
| #(PLUS_ASSIGN expr expr)
| #(MINUS_ASSIGN expr expr)
| #(STAR_ASSIGN expr expr)
| #(DIV_ASSIGN expr expr)
| #(MOD_ASSIGN expr expr)
| #(SR_ASSIGN expr expr)
| #(BSR_ASSIGN expr expr)
| #(SL_ASSIGN expr expr)
| #(BAND_ASSIGN expr expr)
| #(BXOR_ASSIGN expr expr)
| #(BOR_ASSIGN expr expr)
| #(LOR expr expr)
| #(LAND expr expr)
| #(BOR expr expr)
| #(BXOR expr expr)
| #(BAND expr expr)
| #(NOT_EQUAL expr expr)
| #(EQUAL expr expr)
| #(LT expr expr)
| #(GT expr expr)
| #(LE expr expr)
| #(GE expr expr)
| #(SL expr expr)
| #(SR expr expr)
| #(BSR expr expr)
| #(PLUS expr expr)
| #(MINUS expr expr)
| #(DIV expr expr)
| #(MOD expr expr)
| #(STAR expr expr)
| #(INC expr)
| #(DEC expr)
| #(POST_INC expr)
| #(POST_DEC expr)
| #(BNOT expr)
| #(LNOT expr)
| #("instanceof" expr expr)
| #(UNARY_MINUS expr)
| #(UNARY_PLUS expr)
| primaryExpression
;
primaryExpression
: IDENT
| #( DOT
( expr
( IDENT
| arrayIndex
| "this"
| "class"
| #( "new" IDENT elist )
| "super"
)
| #(ARRAY_DECLARATOR typeSpecArray)
| builtInType ("class")?
)
)
| arrayIndex
| #(METHOD_CALL primaryExpression elist)
| ctorCall
| #(TYPECAST typeSpec expr)
| newExpression
| constant
| "super"
| "true"
| "false"
| "this"
| "null"
| typeSpec // type name used with instanceof
;
ctorCall
: #( CTOR_CALL elist )
| #( SUPER_CTOR_CALL
( elist
| primaryExpression elist
)
)
;
arrayIndex
: #(INDEX_OP expr expression)
;
constant
: NUM_INT
| CHAR_LITERAL
| STRING_LITERAL
| NUM_FLOAT
| NUM_DOUBLE
| NUM_LONG
;
newExpression
: #( "new" type
( newArrayDeclarator (arrayInitializer)?
| elist (objBlock)?
)
)
;
newArrayDeclarator
: #( ARRAY_DECLARATOR (newArrayDeclarator)? (expression)? )
;

View File

@ -1,3 +0,0 @@
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool java.g
# now build the pde stuff that extends the java classes
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool -glib java.g pde.g

View File

@ -1,304 +0,0 @@
/* -*- mode: antlr; c-basic-offset: 4; indent-tabs-mode: nil -*- */
header {
package processing.app.preproc;
import processing.app.*;
}
class PdeRecognizer extends JavaRecognizer;
options {
importVocab = Java;
exportVocab = PdePartial;
codeGenMakeSwitchThreshold=10; // this is set high for debugging
codeGenBitsetTestThreshold=10; // this is set high for debugging
// developers may to want to set this to true for better
// debugging messages, however, doing so disables highlighting errors
// in the editor.
defaultErrorHandler = false; //true;
}
tokens {
CONSTRUCTOR_CAST; EMPTY_FIELD;
}
pdeProgram
// only java mode programs will have their own public classes or
// imports (and they must have at least one)
: ( "public" "class" | "import" ) => javaProgram
{ PdePreprocessor.programType = PdePreprocessor.JAVA; }
// the syntactic predicate here looks for any minimal (thus
// the non-greedy qualifier) number of fields, followed by
// the tokens that represent the definition of loop() or
// some other member function. java mode programs may have such
// definitions, but they won't reach this point, having already been
// selected in the previous alternative. static mode programs
// don't have member functions.
//
| ( ( options {greedy=false;}: possiblyEmptyField)* "void" IDENT LPAREN )
=> activeProgram
{ PdePreprocessor.programType = PdePreprocessor.ACTIVE; }
| staticProgram
{ PdePreprocessor.programType = PdePreprocessor.STATIC; }
;
// advanced mode is really just a normal java file
javaProgram
: compilationUnit
;
activeProgram
: (possiblyEmptyField)+
;
staticProgram
: (statement)*
;
// copy of the java.g rule with WEBCOLOR_LITERAL added
constant
: NUM_INT
| CHAR_LITERAL
| STRING_LITERAL
| NUM_FLOAT
| NUM_LONG
| NUM_DOUBLE
| webcolor_literal
;
// of the form #cc008f in PDE
webcolor_literal
: w:WEBCOLOR_LITERAL
{ Preferences.getBoolean("preproc.web_colors") &&
w.getText().length() == 6 }? // must be exactly 6 hex digits
;
// copy of the java.g builtInType rule
builtInConsCastType
: "void"
| "boolean"
| "byte"
| "char"
| "short"
| "int"
| "float"
| "long"
| "double"
;
// our types include the java types and "color". this is separated into two
// rules so that constructor casts can just use the original typelist, since
// we don't want to support the color type as a constructor cast.
//
builtInType
: builtInConsCastType
| "color" // aliased to an int in PDE
{ Preferences.getBoolean("preproc.color_datatype") }?
;
// constructor style casts.
constructorCast!
: t:consCastTypeSpec[true]
LPAREN!
e:expression
RPAREN!
// if this is a string literal, make sure the type we're trying to cast
// to is one of the supported ones
//
{ #e.getType() != STRING_LITERAL ||
( #t.getType() == LITERAL_byte ||
#t.getType() == LITERAL_double ||
#t.getType() == LITERAL_float ||
#t.getType() == LITERAL_int ||
#t.getType() == LITERAL_long ||
#t.getType() == LITERAL_short ) }?
// create the node
//
{#constructorCast = #(#[CONSTRUCTOR_CAST,"CONSTRUCTOR_CAST"], t, e);}
;
// A list of types that be used as the destination type in a constructor-style
// cast. Ideally, this would include all class types, not just "String".
// Unfortunately, it's not possible to tell whether Foo(5) is supposed to be
// a method call or a constructor cast without have a table of all valid
// types or methods, which requires semantic analysis (eg processing of import
// statements). So we accept the set of built-in types plus "String".
//
consCastTypeSpec[boolean addImagNode]
// : stringTypeSpec[addImagNode]
// | builtInConsCastTypeSpec[addImagNode]
: builtInConsCastTypeSpec[addImagNode]
// trying to remove String() cast [fry]
;
//stringTypeSpec[boolean addImagNode]
// : id:IDENT { #id.getText().equals("String") }?
// {
// if ( addImagNode ) {
// #stringTypeSpec = #(#[TYPE,"TYPE"],
// #stringTypeSpec);
// }
// }
// ;
builtInConsCastTypeSpec[boolean addImagNode]
: builtInConsCastType
{
if ( addImagNode ) {
#builtInConsCastTypeSpec = #(#[TYPE,"TYPE"],
#builtInConsCastTypeSpec);
}
}
;
// Since "color" tokens are lexed as LITERAL_color now, we need to have a rule
// that can generate a method call from an expression that starts with this
// token
//
colorMethodCall
: c:"color" {#c.setType(IDENT);} // this would default to LITERAL_color
lp:LPAREN^ {#lp.setType(METHOD_CALL);}
argList
RPAREN!
;
// copy of the java.g rule with added constructorCast and colorMethodCall
// alternatives
primaryExpression
: (consCastTypeSpec[false] LPAREN) => constructorCast
{ Preferences.getBoolean("preproc.enhanced_casting") }?
| identPrimary ( options {greedy=true;} : DOT^ "class" )?
| constant
| "true"
| "false"
| "null"
| newExpression
| "this"
| "super"
| LPAREN! assignmentExpression RPAREN!
| colorMethodCall
// look for int.class and int[].class
| builtInType
( lbt:LBRACK^ {#lbt.setType(ARRAY_DECLARATOR);} RBRACK! )*
DOT^ "class"
;
// the below variable rule hacks are needed so that it's possible for the
// emitter to correctly output variable declarations of the form "float a, b"
// from the AST. This means that our AST has a somewhat different form in
// these rules than the java one does, and this new form may have its own
// semantic issues. But it seems to fix the comma declaration issues.
//
variableDefinitions![AST mods, AST t]
: vd:variableDeclarator[getASTFactory().dupTree(mods),
getASTFactory().dupTree(t)]
{#variableDefinitions = #(#[VARIABLE_DEF,"VARIABLE_DEF"], mods,
t, vd);}
;
variableDeclarator[AST mods, AST t]
: ( id:IDENT (lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK!)*
v:varInitializer (COMMA!)? )+
;
// java.g builds syntax trees with an inconsistent structure. override one of
// the rules there to fix this.
//
explicitConstructorInvocation!
: t:"this" LPAREN a1:argList RPAREN SEMI
{#explicitConstructorInvocation = #(#[CTOR_CALL, "CTOR_CALL"],
#t, #a1);}
| s:"super" LPAREN a2:argList RPAREN SEMI
{#explicitConstructorInvocation = #(#[SUPER_CTOR_CALL,
"SUPER_CTOR_CALL"],
#s, #a2);}
;
// quick-n-dirty hack to the get the advanced class name. we should
// really be getting it from the AST and not forking this rule from
// the java.g copy at all. Since this is a recursive descent parser, we get
// the last class name in the file so that we don't end up with the classname
// of an inner class. If there is more than one "outer" class in a file,
// this heuristic will fail.
//
classDefinition![AST modifiers]
: "class" i:IDENT
// it _might_ have a superclass...
sc:superClassClause
// it might implement some interfaces...
ic:implementsClause
// now parse the body of the class
cb:classBlock
{#classDefinition = #(#[CLASS_DEF,"CLASS_DEF"],
modifiers,i,sc,ic,cb);
PdePreprocessor.advClassName = i.getText();}
;
possiblyEmptyField
: field
| s:SEMI {#s.setType(EMPTY_FIELD);}
;
class PdeLexer extends JavaLexer;
options {
importVocab=PdePartial;
exportVocab=Pde;
}
// We need to preserve whitespace and commentary instead of ignoring
// like the supergrammar does. Otherwise Jikes won't be able to give
// us error messages that point to the equivalent PDE code.
// WS, SL_COMMENT, ML_COMMENT are copies of the original productions,
// but with the SKIP assigment removed.
WS : ( ' '
| '\t'
| '\f'
// handle newlines
| ( options {generateAmbigWarnings=false;}
: "\r\n" // Evil DOS
| '\r' // Macintosh
| '\n' // Unix (the right way)
)
{ newline(); }
)+
;
// Single-line comments
SL_COMMENT
: "//"
(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
{newline();}
;
// multiple-line comments
ML_COMMENT
: "/*"
( /* '\r' '\n' can be matched in one alternative or by matching
'\r' in one iteration and '\n' in another. I am trying to
handle any flavor of newline that comes in, but the language
that allows both "\r\n" and "\r" and "\n" to all be valid
newline is ambiguous. Consequently, the resulting grammar
must be ambiguous. I'm shutting this warning off.
*/
options {
generateAmbigWarnings=false;
}
:
{ LA(2)!='/' }? '*'
| '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('*'|'\n'|'\r')
)*
"*/"
;
WEBCOLOR_LITERAL
: '#'! (HEX_DIGIT)+
;