Skip to content

Commit

Permalink
Have the basic forms defined in the parser. Starting to work on the a…
Browse files Browse the repository at this point in the history
…nalyzer piece in clojure.
  • Loading branch information
Eric Thor authored and Eric Thor committed Oct 30, 2009
1 parent 001342d commit 0fff916
Show file tree
Hide file tree
Showing 10 changed files with 1,046 additions and 875 deletions.
652 changes: 424 additions & 228 deletions src/ide-tools/src/Example/ClojureParser.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ide-tools/src/Example/ClojureSym.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Wed Oct 28 16:52:58 EDT 2009
// Fri Oct 30 16:01:38 EDT 2009
//----------------------------------------------------

package Example;
Expand Down
158 changes: 124 additions & 34 deletions src/ide-tools/src/org/enclojure/cup/clojure.cup
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java_cup.runtime.*;
import org.enclojure.flex._Lexer;
import java.io.*;
import org.enclojure.flex.*;
import clojure.lang.*;

parser code {:
public static void main(String args[]) throws Exception {
Expand All @@ -16,6 +17,7 @@ parser code {:
new ClojureParser(new _Lexer(new java.io.FileInputStream(args[0]))).parse();
}
}

:}

terminal NEWLINE
Expand Down Expand Up @@ -91,63 +93,151 @@ terminal STRING_LITERAL;
terminal WRONG_STRING_LITERAL;
terminal NULL_LITERAL;

non terminal s_expr, map,vector,set,list,empty_list;
non terminal literal,series,empty,list_expr,pair_expr,expr_part,expr_atom,atom,operands,operand,expression;
nonterminal Object s_expr;
nonterminal Object expr_part;
nonterminal Object map;
nonterminal Object vector;
nonterminal Object set;
nonterminal Object list;
nonterminal Object empty_list;
nonterminal Object expression;
nonterminal Object literal;
nonterminal Object series,empty;
nonterminal Object atom;
nonterminal Object operands;
nonterminal Object operand;
nonterminal Object symbol;

start with s_expr;

s_expr ::= expr_part
s_expr ::= expr_part:e
{: RESULT = e; :}
;

expr_part ::= expr_part atom
| atom;
expr_part ::= expr_part:e1 atom:e2
{:
if (e1 instanceof IPersistentCollection)
RESULT = RT.conj((IPersistentCollection)e1,e2);
RESULT = RT.vector(e1,e2);
:}
| atom:e
{: RESULT = e; :}
;

series ::=
list
| vector
| map
| set;
list:e
{: RESULT = e; :}
| vector:e
{: RESULT = e; :}
| map:e
{: RESULT = e; :}
| set:e
{: RESULT = e; :}
;

operand ::= atom;
operand ::= atom:e
{:RESULT = e; :}
;

operands
::= operands operand
| operand
::= operands:e1 operand:e2
{:
if (e1 instanceof IPersistentCollection)
{
System.out.println("operands:conj " + e1 + "," + e2);
RESULT = RT.conj((IPersistentCollection)e1,e2);
} else
{
System.out.println("operands:vec " + e1 + "," + e2);
RESULT = RT.vector(e1,e2);
}
:}
| operand:e
{:
System.out.println("operand " + e );
RESULT = e;
:}
;

list ::= LEFT_PAREN operands RIGHT_PAREN;

list ::= LEFT_PAREN operands:e RIGHT_PAREN
{:
System.out.println("list [" + e +"]");
RESULT = RT.list (e);
:}
;

vector ::= LEFT_SQUARE operands:e RIGHT_SQUARE
{: System.out.println("vector [" + e +"]"); :}
{:
RESULT = RT.vector(e);
System.out.println("vector [" + e +"]");
:}
;

set ::= SHARP LEFT_CURLY operands:e RIGHT_CURLY
{: System.out.println("set #{" + e +"}"); :}
{:
RESULT = RT.set (e);
System.out.println("set #{" + e +"}");
:}
;

map ::= LEFT_CURLY operands:e RIGHT_CURLY
{: System.out.println("map {" + e +"}"); :}
;
map ::= LEFT_CURLY operand:e1 operand:e2 RIGHT_CURLY
{:
RESULT = RT.map(e1,e2);
System.out.println("map {" + e1 + "," + e2 +"}"); :}
;

pair_expr ::= s_expr s_expr;

literal ::=
INTEGER_LITERAL
| BIG_INT_LITERAL
| LONG_LITERAL
| FLOAT_LITERAL
| DOUBLE_LITERAL
| BIG_DECIMAL_LITERAL
| RATIO
| CHAR_LITERAL
| STRING_LITERAL
| WRONG_STRING_LITERAL
| KEYWORD
| NULL_LITERAL
INTEGER_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| BIG_INT_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| LONG_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| FLOAT_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| DOUBLE_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| BIG_DECIMAL_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| RATIO:e
{: RESULT = RT.readString((String)e); :}
| CHAR_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| STRING_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| WRONG_STRING_LITERAL:e
{: RESULT = RT.readString((String)e); :}
| KEYWORD:e
{: RESULT = RT.readString((String)e); :}
| NULL_LITERAL:e
{: RESULT = RT.readString((String)e); :}
;

atom ::= series
| literal;
symbol ::= symATOM:ns symNS_SEP symATOM:sym
{:
RESULT = clojure.lang.Symbol.create((String)ns,(String)sym);
System.out.println("symbol " + ns + "/" + sym);
:}
| symATOM:sym
{:
RESULT = clojure.lang.Symbol.create((String)sym);
System.out.println("symbol "+ sym);
:}
| symDOT:sym
{:
RESULT = clojure.lang.Symbol.create((String)sym);
System.out.println("symbol "+ sym);
:}
;

atom ::= series:e
{: RESULT = e; :}
| literal:e
{: RESULT = e; :}
| symbol:e
{: RESULT = e; :}
;

empty ::= /* empty */
;
Expand Down
2 changes: 2 additions & 0 deletions src/ide-tools/src/org/enclojure/flex/ClojureSymbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@


public class ClojureSymbol extends Symbol {

public final static Var _tokenMap = (Var)RT.var("org.enclojure.idetools.tokens","-TOKENS-");
public IPersistentMap _tokenType;
public Object _data;
public int _line;
Expand Down
Loading

0 comments on commit 0fff916

Please sign in to comment.