[Mathlib-commitlog] SF.net SVN: mathlib:[661] JMathLib/trunk/src/jmathlib/core/interpreter
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-09 19:22:36
|
Revision: 661
http://mathlib.svn.sourceforge.net/mathlib/?rev=661&view=rev
Author: st_mueller
Date: 2009-01-09 19:22:29 +0000 (Fri, 09 Jan 2009)
Log Message:
-----------
changed Parser, now parsing of cd somedirectory is possible. Also cd("somedirectory") still works.
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/core/interpreter/LexicalAnalyser.java
JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/LexicalAnalyser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/LexicalAnalyser.java 2009-01-09 19:20:18 UTC (rev 660)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/LexicalAnalyser.java 2009-01-09 19:22:29 UTC (rev 661)
@@ -64,12 +64,10 @@
/**default constructor - creates the lexical analyser object with an empty string*/
public LexicalAnalyser()
{
- reservedWords = " break do exit try catch continue ";
- reservedWords += " for help history hold if load more return ";
- reservedWords += " load dir ls save set show who whos ";
- reservedWords += " cd chdir clear diary echo format ";
- reservedWords += " type global isglobal ";
- reservedWords += " save switch while "; // trailing " " is very important !!
+ reservedWords = " break catch continue ";
+ reservedWords += " for foreach global if ";
+ reservedWords += " persistent return switch try while ";
+ reservedWords += " global isglobal "; // trailing " " is very important !!
delimiterWords = " end endif else elseif endfunction endwhile endfor ";
delimiterWords += " case default otherwise endswitch ";
delimiterChars = ",()[];{}\n";
Modified: JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java
===================================================================
--- JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-01-09 19:20:18 UTC (rev 660)
+++ JMathLib/trunk/src/jmathlib/core/interpreter/Parser.java 2009-01-09 19:22:29 UTC (rev 661)
@@ -177,7 +177,7 @@
OperandToken retToken = null; // holds token to be returned
Token peekToken = peekNextToken(deliTyp); // holds next (actual) token
-
+
if (peekToken == null)
{
// No more tokens available
@@ -241,6 +241,9 @@
{
// variables (e.g. aaa or b)
retToken = (OperandToken)getNextToken(deliTyp);
+
+ ErrorLogger.debugLine("Parser parseSingle ppp "+retToken.toString());
+
// check if the variable is followed by a dot operator
if (peekNextToken(deliTyp) instanceof DotOperatorToken)
@@ -267,6 +270,44 @@
retToken = parseFunctionAndParameters( new FunctionToken(name), null );
}
}
+ else if ( (peekNextToken(deliTyp) instanceof VariableToken) ||
+ (peekNextToken(deliTyp) instanceof CharToken) )
+ {
+ // parse something like disp hello instead of disp("hello")
+ // parse something like disp "hello" instead of disp("hello")
+ // convert arguments into char arrays
+
+ String name = ((VariableToken)retToken).getName();
+ FunctionToken func = new FunctionToken(name);
+
+ Token next = null ;
+ while(true)
+ {
+ next = peekNextToken();
+ if (next==null)
+ break;
+
+ //ErrorLogger.debugLine("Parser: var var "+next.toString());
+
+ if (next instanceof DelimiterToken)
+ {
+ break;
+ }
+ else if ( (next instanceof VariableToken) ||
+ (next instanceof CharToken) )
+ {
+ String s = next.toString();
+ ErrorLogger.debugLine("Parser: var var variable "+next.toString());
+ getNextToken();
+ func.setOperands(new OperandToken[] {(OperandToken)new CharToken(s)});
+ }
+ else
+ Errors.throwMathLibException("Parser: var var");
+ }
+
+ return func;
+
+ }
else
ErrorLogger.debugLine("Parser: VariableToken: " + retToken.toString());
}
@@ -931,7 +972,7 @@
FunctionToken func = (FunctionToken)nextToken;
// check if it is a special function e.g. "global a b c"
- if (func.getName().equals("global") || func.getName().equals("isglobal"))
+ if ( func.getName().equals("global") || func.getName().equals("isglobal"))
{
ErrorLogger.debugLine("Parser: found global");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|