ua.gradsoft.termware.parsers.terms
Class TermReader

java.lang.Object
  extended by ua.gradsoft.termware.parsers.terms.TermReader
All Implemented Interfaces:
TermReaderConstants

public class TermReader
extends Object
implements TermReaderConstants

Parser for TermWare language.


Field Summary
 Token jj_nt
           
 boolean lookingAhead
           
 Token token
           
 TermReaderTokenManager token_source
           
 
Fields inherited from interface ua.gradsoft.termware.parsers.terms.TermReaderConstants
ARGS_DOTS, BIT_AND, BIT_NEGATE, BIT_OR, COMMA, DEFAULT, DIVIDE, DOT, DOUBLE_LITERAL, EOF, EQ, EQ_GREATER, EXPONENT, FALSE, GREATER, GREATER_EQ, IDENT, IN, INTEGER_LITERAL, LEFT_ARROW, LEFT_SHIFT, LESS, LESS_EQ, LOGICAL_AND, LOGICAL_NOT, LOGICAL_OR, MINUS, MOD, MULTIPLY, NAMPERSAND, NEQ, NIL, PLUS, QUESTION, RIGHT_SHIFT, STRING_LITERAL, tokenImage, TRUE, TWO_DIVIDE, TWO_DOTS, TWO_TWO_DOTS, X_LITERAL
 
Constructor Summary
TermReader(InputStream stream)
           
TermReader(InputStream stream, String encoding)
           
TermReader(InputStream in, String fname, int lineCorrection, TermWareInstance instance)
           
TermReader(Reader stream)
           
TermReader(Reader in, String fname, int lineCorrection, TermWareInstance instance)
           
TermReader(TermReaderTokenManager tm)
           
 
Method Summary
 void disable_tracing()
           
 void enable_tracing()
           
 boolean eofReached()
           
 ParseException generateParseException()
           
 Token getNextToken()
           
 StringIndex getStringIndex()
           
 Token getToken(int index)
           
static void main(String[] args)
           
 Term readBoolean()
           boolean: "true" | "false"
 Term readDouble()
           double :
 Term readInteger()
           integer :
INTEGER_LITERAL: (["0"-"9"])+("L"|"B")?
 Term readLetTerm()
           let_term : "let" term
'let t' is synonim of let(t).
 Term readNIL()
           nil: "NIL"
 Term readPatternTail()
           set_tail : ":" term | "," term_comma_list
 Term readPrimitive()
           primitive: string | integer | double | boolean | nil
 Term readScopedName()
           scoped_name : ( "::" ) *
Example:
 Term readStatement()
           statement : term ";" | term |
 Term readStatementWrapped()
           
 Term readString()
           string:
where STRING_LITERAL described by next regular expression:
 Term readTerm()
           term : let_term | term_expression0
 Term[] readTermArgs()
           term_args : "(" term_comma_list ")"
 Term[] readTermCommaList()
           term_comma_list : [ term ( "," term )* ]
 Term readTermExpression0()
           term_expression0 : term_expression1 [ "[" term_expression1 "]" ] [ "->" term_expression0 [ "[" term_expression1 "]" ] ]
Example:
 Term readTermExpression1()
           term_expression1 : term_expression2 [ "?" term_expression1 ":" term_expression1 ]
Example:
 Term readTermExpression10()
           term_expression10 : term_expression11 ( ( "*" | "/" | "%" ) term_expression11 )*
x * y is synonim for multiply(x,y) x / y is synonim for divide(x,y) x % y is synonim for mod(x,y)
 Term readTermExpression11()
           term_expression11 : ( [ "+" | "-" | "!" | "~" ] term_expression10 ) | term_expression12
+x is synonim for plus(x) -x is synonim for minus(x) !x is synonim for logical_not(x) ~x is synonim for bit_negate(x)
 Term readTermExpression12()
           term_expression12 : term_expression13 ( "." term_expression13 )*
x.y is synonim for apply(x,y)
 Term readTermExpression13()
           term_expression13 : term_expression_14 [ ".." ( x ) ]
 Term readTermExpression14()
           term_expression14 : term_expression_last
 Term readTermExpression15()
           term_expression15 : term_expression_last
 Term readTermExpression2()
           term_expression2 : term_expression3 [ "||" term_expression2 ]
x || y is synonim for logical_or(x,y)
 Term readTermExpression3()
           term_expression3 : term_expression4 [ "&&" term_expression3 ]
x && y is synonim for logical_and(x,y)
 Term readTermExpression4()
           term_expression4 : term_expression5
 Term readTermExpression5()
           term_expression5 : term_expression6 [ "&" term_expression5 ]
x & y is synonim for bit_and(x,y)
 Term readTermExpression6()
           term_expression6 : term_expression7 [ ( "==" | "!=" ) term_expression7 ]
x == y is synonim for eq(x,y) x != y is synonim for neq(x,y)
 Term readTermExpression7()
           term_expression7 : term_expression8 [ ( "<" | ">" | "<=" | ">=" | "=>" | "in" ) term_expression8 ]
x < y is synonim for less(x,y) x > y is synonim for greater(x,y) x <= y is synonim for less_eq(x,y) x >= y is synonim for greater_eq(x,y) x => y is synonim for eq_greater(x,y) x in y is synonim for _in(x,y)
 Term readTermExpression8()
           term_expression8 : term_expression9 ( ( "<<" | ">>" ) term_expression9 )*
x << y is synonim for left_shift(x,y) x >> y is synonim for right_shift(x,y)
 Term readTermExpression9()
           term_expression9 : term_expression10 ( ( "+" | "-" ) term_expression10 )*
x + y is synonim for plus(x,y) x - y is synonim for minus(x,y)
 Term readTermExpressionLast()
           term_expression_last : scoped_name [ term_args ] | primitive | x | "(" term ")" | "{" term set_tail "}" | "{" "}" | "[" term_comma_list "]"
{ x1, x2, ..
 Term readTermExpressionWhere()
           
 Term readWhereAssigments()
           
 Term readX()
           x :
where id described by next pattern:
 void ReInit(InputStream stream)
           
 void ReInit(InputStream stream, String encoding)
           
 void ReInit(Reader stream)
           
 void ReInit(TermReaderTokenManager tm)
           
 void setFname(String fname)
           
 void setTermWareInstance(TermWareInstance instance)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

token_source

public TermReaderTokenManager token_source

token

public Token token

jj_nt

public Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

TermReader

public TermReader(InputStream in,
                  String fname,
                  int lineCorrection,
                  TermWareInstance instance)

TermReader

public TermReader(Reader in,
                  String fname,
                  int lineCorrection,
                  TermWareInstance instance)

TermReader

public TermReader(InputStream stream)

TermReader

public TermReader(InputStream stream,
                  String encoding)

TermReader

public TermReader(Reader stream)

TermReader

public TermReader(TermReaderTokenManager tm)
Method Detail

main

public static void main(String[] args)

readStatementWrapped

public Term readStatementWrapped()
                          throws TermWareException
Throws:
TermWareException

setTermWareInstance

public void setTermWareInstance(TermWareInstance instance)

setFname

public void setFname(String fname)

getStringIndex

public StringIndex getStringIndex()

eofReached

public final boolean eofReached()

readStatement

public final Term readStatement()
                         throws ParseException,
                                TermWareException
statement : term ";" | term |

Throws:
ParseException
TermWareException
See Also:
readTerm()

readTerm

public final Term readTerm()
                    throws ParseException,
                           TermWareException
term : let_term | term_expression0

Throws:
ParseException
TermWareException
See Also:
readLetTerm(), readTermExpression0()

readLetTerm

public final Term readLetTerm()
                       throws ParseException,
                              TermWareException
let_term : "let" term
'let t' is synonim of let(t). default behaviour - add rule t to current ruleset.

Throws:
ParseException
TermWareException
See Also:
readTerm()

readTermExpression0

public final Term readTermExpression0()
                               throws ParseException,
                                      TermWareException
term_expression0 : term_expression1 [ "[" term_expression1 "]" ] [ "->" term_expression0 [ "[" term_expression1 "]" ] ]
Example:
   x->y
   fact($x) [|$x==1|] -> 1
 
TODO: in addition we check (non-grammar) existence of comment to set help for main term of left pattern, if our grammar is a rule.

Throws:
ParseException
TermWareException
See Also:
readTermExpression1()

readTermExpressionWhere

public final Term readTermExpressionWhere()
                                   throws ParseException,
                                          TermWareException
Throws:
ParseException
TermWareException

readWhereAssigments

public final Term readWhereAssigments()
                               throws ParseException,
                                      TermWareException
Throws:
ParseException
TermWareException

readTermExpression1

public final Term readTermExpression1()
                               throws ParseException,
                                      TermWareException
term_expression1 : term_expression2 [ "?" term_expression1 ":" term_expression1 ]
Example:
    x ? y : z
 
is synonim for if(x,y,z)

Throws:
ParseException
TermWareException
See Also:
readTermExpression1(), readTermExpression2()

readTermExpression2

public final Term readTermExpression2()
                               throws ParseException,
                                      TermWareException
term_expression2 : term_expression3 [ "||" term_expression2 ]

readTermExpression3

public final Term readTermExpression3()
                               throws ParseException,
                                      TermWareException
term_expression3 : term_expression4 [ "&&" term_expression3 ]

Throws:
ParseException
TermWareException
See Also:
readTermExpression3(), readTermExpression4()

readTermExpression4

public final Term readTermExpression4()
                               throws ParseException,
                                      TermWareException
term_expression4 : term_expression5

Throws:
ParseException
TermWareException
See Also:
readTermExpression4(), readTermExpression5()

readTermExpression5

public final Term readTermExpression5()
                               throws ParseException,
                                      TermWareException
term_expression5 : term_expression6 [ "&" term_expression5 ]

Throws:
ParseException
TermWareException
See Also:
readTermExpression5(), readTermExpression6()

readTermExpression6

public final Term readTermExpression6()
                               throws ParseException,
                                      TermWareException
term_expression6 : term_expression7 [ ( "==" | "!=" ) term_expression7 ]

Throws:
ParseException
TermWareException
See Also:
readTermExpression7()

readTermExpression7

public final Term readTermExpression7()
                               throws ParseException,
                                      TermWareException
term_expression7 : term_expression8 [ ( "<" | ">" | "<=" | ">=" | "=>" | "in" ) term_expression8 ]

Throws:
ParseException
TermWareException
See Also:
readTermExpression8()

readTermExpression8

public final Term readTermExpression8()
                               throws ParseException,
                                      TermWareException
term_expression8 : term_expression9 ( ( "<<" | ">>" ) term_expression9 )*

Throws:
ParseException
TermWareException
See Also:
readTermExpression9()

readTermExpression9

public final Term readTermExpression9()
                               throws ParseException,
                                      TermWareException
term_expression9 : term_expression10 ( ( "+" | "-" ) term_expression10 )*

Throws:
ParseException
TermWareException
See Also:
TODO: commentAttribute.

readTermExpression10

public final Term readTermExpression10()
                                throws ParseException,
                                       TermWareException
term_expression10 : term_expression11 ( ( "*" | "/" | "%" ) term_expression11 )*

Throws:
ParseException
TermWareException
See Also:
readTermExpression11()

readTermExpression11

public final Term readTermExpression11()
                                throws ParseException,
                                       TermWareException
term_expression11 : ( [ "+" | "-" | "!" | "~" ] term_expression10 ) | term_expression12

Throws:
ParseException
TermWareException
See Also:
readTermExpression10(), readTermExpression12()

readTermExpression12

public final Term readTermExpression12()
                                throws ParseException,
                                       TermWareException
term_expression12 : term_expression13 ( "." term_expression13 )*

Throws:
ParseException
TermWareException
See Also:
readTermExpression13()

readTermExpression13

public final Term readTermExpression13()
                                throws ParseException,
                                       TermWareException
term_expression13 : term_expression_14 [ ".." ( x ) ]

Throws:
ParseException
TermWareException
See Also:
readTermExpression14()

readTermExpression14

public final Term readTermExpression14()
                                throws ParseException,
                                       TermWareException
term_expression14 : term_expression_last

Throws:
ParseException
TermWareException
See Also:
readTermExpressionLast()

readTermExpression15

public final Term readTermExpression15()
                                throws ParseException,
                                       TermWareException
term_expression15 : term_expression_last

Throws:
ParseException
TermWareException
See Also:
readTermExpressionLast()

readTermExpressionLast

public final Term readTermExpressionLast()
                                  throws ParseException,
                                         TermWareException
term_expression_last : scoped_name [ term_args ] | primitive | x | "(" term ")" | "{" term set_tail "}" | "{" "}" | "[" term_comma_list "]"

Throws:
ParseException
TermWareException
See Also:
readScopedName(), readTermArgs(), readPrimitive(), readX(), readTerm(), readPatternTail(), readTermCommaList()

readScopedName

public final Term readScopedName()
                          throws ParseException,
                                 TermWareException
scoped_name : ( "::" ) *
Example:
   x
   x::y
   x::y::z
 

Throws:
ParseException
TermWareException

readPatternTail

public final Term readPatternTail()
                           throws ParseException,
                                  TermWareException
 set_tail : ":" term
           |
             "," term_comma_list

Throws:
ParseException
TermWareException
See Also:
readTerm(), readTermCommaList()

readX

public final Term readX()
                 throws ParseException,
                        TermWareException
x :
where id described by next pattern:
 X_LITERAL : "$" (["0"-"9"]|["a"-"z"]|["A"-"Z"]|"_")+ 
 

Example:
  $x
  $myVariable

Throws:
ParseException
TermWareException

readTermArgs

public final Term[] readTermArgs()
                          throws ParseException,
                                 TermWareException
 
  term_args : "(" term_comma_list ")" 

Throws:
ParseException
TermWareException
See Also:
readTermCommaList()

readTermCommaList

public final Term[] readTermCommaList()
                               throws ParseException,
                                      TermWareException
term_comma_list : [ term ( "," term )* ]

Throws:
ParseException
TermWareException
See Also:
readTerm()

readPrimitive

public final Term readPrimitive()
                         throws ParseException,
                                TermWareException
 primitive: string | integer | double | boolean | nil

Throws:
ParseException
TermWareException
See Also:
readString(), readInteger(), readDouble(), readBoolean(), readNIL()

readString

public final Term readString()
                      throws ParseException,
                             TermWareException
string:
where STRING_LITERAL described by next regular expression:
  STRING_LITERAL : "\""
  ( ( ~["\"","\\"])
  | ("\\" (
            ["n","t","v","b","r","f","\\","'","\""]
           |
            "0" (["0"-"7"])*
           |
            ["1"-"9"] (["0"-"9"])*
           |
            ("0x" | "0X") (["0"-"9","a"-"f","A"-"F"])+
          )
    )
  )*
  "\"" 
i. e. "C-like" string.

Throws:
ParseException
TermWareException

readInteger

public final Term readInteger()
                       throws ParseException,
                              TermWareException
integer :
INTEGER_LITERAL: (["0"-"9"])+("L"|"B")?

Throws:
ParseException
TermWareException

readDouble

public final Term readDouble()
                      throws ParseException,
                             TermWareException
double :

Throws:
ParseException
TermWareException

readBoolean

public final Term readBoolean()
                       throws ParseException,
                              TermWareException
boolean: "true" | "false"

Throws:
ParseException
TermWareException

readNIL

public final Term readNIL()
                   throws ParseException,
                          TermWareException
nil: "NIL"

Throws:
ParseException
TermWareException

ReInit

public void ReInit(InputStream stream)

ReInit

public void ReInit(InputStream stream,
                   String encoding)

ReInit

public void ReInit(Reader stream)

ReInit

public void ReInit(TermReaderTokenManager tm)

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

generateParseException

public ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()