예제 #1
0
파일: syntax.c 프로젝트: tkmr/tonburi-scm
sExpression *evalSyntaxRuleIter(sExpression *syntax, sExpression *parameters, sExpression *rule){
  if(isList(syntax) && isList(parameters)){
    if(isSymbol(cadr(toList(syntax))) && (strcmp(toSymb(cadr(toList(syntax)))->name, "...") == 0)){
      applySyntaxToRule(syntax, parameters, rule);
      return &sTrue;
    }
    else{
      sExpression *result = evalSyntaxRuleIter(car(toList(syntax)), car(toList(parameters)), rule);
      if(isNull(result)){
        return &sNull;
      }
      else{
        return evalSyntaxRuleIter(cdr(toList(syntax)), cdr(toList(parameters)), rule);
      }
    }
  }
  else if(isNull(syntax) && !isNull(parameters)){
    return &sNull;
  }
  else if(isSymbol(syntax)){
    if(strcmp(toSymb(syntax)->name, "_") == 0){
      return &sTrue;
    }
    else{
      applySyntaxToRule(syntax, parameters, rule);
      return &sTrue;
    }
  }
  else if(isNull(syntax) && isNull(parameters)){
    return &sTrue;
  }
  return &sNull;
}
예제 #2
0
파일: step7_quote.cpp 프로젝트: BlinkD/mal
static malValuePtr quasiquote(malValuePtr obj)
{
    const malSequence* seq = isPair(obj);
    if (!seq) {
        return mal::list(mal::symbol("quote"), obj);
    }

    if (isSymbol(seq->item(0), "unquote")) {
        // (qq (uq form)) -> form
        checkArgsIs("unquote", 1, seq->count() - 1);
        return seq->item(1);
    }

    const malSequence* innerSeq = isPair(seq->item(0));
    if (innerSeq && isSymbol(innerSeq->item(0), "splice-unquote")) {
        checkArgsIs("splice-unquote", 1, innerSeq->count() - 1);
        // (qq (sq '(a b c))) -> a b c
        return mal::list(
            mal::symbol("concat"),
            innerSeq->item(1),
            quasiquote(seq->rest())
        );
    }
    else {
        // (qq (a b c)) -> (list (qq a) (qq b) (qq c))
        // (qq xs     ) -> (cons (qq (car xs)) (qq (cdr xs)))
        return mal::list(
            mal::symbol("cons"),
            quasiquote(seq->first()),
            quasiquote(seq->rest())
        );
    }
}
예제 #3
0
int main()
{
	pst head = NULL;
	printf("vvedyte vyrazhenye\n");
	char s[60];
	scanf("%s", s);
	int length = strlen(s);
	for(int i = 0; i < length; i++)
	{
		if (!isSymbol(s[i]))
			push(head, s[i] - '0');
		else 
			if (isSymbol(s[i]))
			{
				int a = front(head);
				pop(head);
				int b = front(head);
				pop(head);
				push(head, makeOperation(s[i], a, b));
			}
	}
	printf("result = ");
	printf("%d\n",front(head));
	deleteStack(head);
	return 0;
}
예제 #4
0
void addPlus(const char *a,char *b){
    int i=0,j=0;
    if(a[i]=='\0'){
        b[i]='\0';
        return;
    }
    while(1){
        if(a[i+1]=='\0'){
            b[j]=a[i];
            j++;
            b[j]='\0';
            break;
        }
        // printf("%d %d %d\n",(a[i]=='*'),(isSymbol(a[i+1])==1||a[i+1]=='('),((a[i]=='*')&&(isSymbol(a[i+1])==1||a[i+1]=='('))   );
        // printf("a[i] = %c a[i+1]=%c",a[i],a[i+1] );
        // printf(" isSymbol(a[i+1])=%d\n",isSymbol(a[i+1]));
        if((  isSymbol(a[i])==1&&(isSymbol(a[i+1])==1||(a[i+1]=='('))  )||  (isSymbol(a[i])==1&&(a[i+1]=='('))
            || (isSymbol(a[i+1])==1&&(a[i]==')')) || ((a[i]==')')&&(a[i+1]=='(')) ||
            ((a[i]=='*')&&(isSymbol(a[i+1])==1||a[i+1]=='('))  ){
            //printf("A[i]=%c\n",a[i] );
            b[j]=a[i];
            j++;
            b[j]='+';
            j++;
            i++;
            continue;
        }else{
            b[j]=a[i];
            j++;
            i++;
        }
    }
}
예제 #5
0
파일: syntax.c 프로젝트: jarvinet/scheme
/* (define foo ...)
 * (define (foo n) ...)
 */
void definitionVariable(Register result, Register exp)
{
    cdr(result, exp);
    car(result, result);
    if (!isSymbol(result))
	car(result, result);
}
예제 #6
0
파일: PdTypes.cpp 프로젝트: Apolotary/libpd
std::string List::getSymbol(const unsigned int index) const {
	if(!isSymbol(index)) {
		std::cerr << "Pd: List: object " << index << " is not a symbol" << std::endl;
		return "";
	}
	return objects[index].symbol;
}
예제 #7
0
파일: Cell.cpp 프로젝트: wibbe/scheme-cpp
 std::string Cell::toString() const
 {
   if (isSymbol())
     return symname(m_value);
     
   return string_value(m_value);
 }
예제 #8
0
	bool environment::numberArgsOK(boost::any vars, boost::any vals)
	{
		return ((isEMPTY(vars) && isEMPTY(vals)) ||
				isSymbol(vars) ||
				(isPair(vars) && isPair(vals) &&
				 numberArgsOK(rest(vars), rest(vals))));
	}
예제 #9
0
파일: misc.c 프로젝트: tkmr/tonburi-scm
Bool firstSymbol(sList *list, char *name){
  sExpression *first = car(list);
  if(isSymbol(first)){
    return (strcmp(toSymb(first)->name, name) == 0) ? TRUE : FALSE;
  }
  return FALSE;
}
예제 #10
0
Lexeme Lexal::readNumber(int startLine, int startPos, wchar_t first)
{
    std::wstring number;
    number += first;
    Lexeme::Type type = Lexeme::Integer;
    
    while (! reader.isEof()) {
        wchar_t ch = reader.getNextChar();
        pos++;
        if (isDigit(ch))
            number += ch;
        else if (L'.' == ch) {
            if (Lexeme::Integer == type) {
                type = Lexeme::Float;
                number += ch;
            } else
                throw Exception(L"To many dots in number at " + 
                        posToStr(line, pos));
        } else if ((! isSymbol(ch)) && (! isWhiteSpace(ch)))
            throw Exception(L"invalid number at " + posToStr(line, pos));
        else {
            pos--;
            reader.ungetChar(ch);
            break;
        }
    }

    if (L'.' == number[number.length() - 1])
        throw Exception(L"Missing digit after dot at " + posToStr(line, pos));

    return Lexeme(type, number, startLine, startPos);
}
예제 #11
0
Expression *ASTBuilder::parseFunctionDefinition() {
	// gather the name, the arguments and the body
	std::string fnName = getNextToken()->getData();

	// TODO: sanity checking 

	Token *t = getNextToken();
	cout << t->getData() << endl;
	if(t->getData().compare("|") != 0) {
		cout << "Error: astbuilder.cpp:157" << endl;
	}
	t = getNextToken();
	vector<std::string> args;

	// simple error checking
	int commas = 0;
	while(t != NULL && t->getData().compare("|") != 0) {
		std::string data = t->getData();
		if(t->getData().compare(",") == 0){
			++commas;
		} else {
			// ensure that it can be a variable name
			if(!isSymbol(data)){
				cout << "Error: astbuilder.cpp:171" << endl;
			}
			args.push_back(data);
		}

		t = getNextToken();
	}

	if(args.size() != (commas + 1)) {
		cout << "Error: astbuilder.cpp:180" << endl;
	}

	// create a prototype 
	PrototypeExpression *proto = new PrototypeExpression(fnName, args);


	// now need to get all of the body functions
	// can have function calls and assigments
	
	// the current token is the closing | around the arguments
	t = getNextToken();
	bool endFound = false;
	while(t != NULL) {
		std::string data = t->getData();

		if(data.compare("end") == 0){
			// end of the function definition
			endFound = true;
			break;
		}

		t = getNextToken();
	}
	
	return proto;
}
예제 #12
0
파일: JSCell.cpp 프로젝트: B-Stefan/webkit
JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
{
    if (isString())
        return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
    if (isSymbol())
        return static_cast<const Symbol*>(this)->toPrimitive(exec, preferredType);
    return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
}
예제 #13
0
파일: JSCell.cpp 프로젝트: B-Stefan/webkit
bool JSCell::getPrimitiveNumber(ExecState* exec, double& number, JSValue& value) const
{
    if (isString())
        return static_cast<const JSString*>(this)->getPrimitiveNumber(exec, number, value);
    if (isSymbol())
        return static_cast<const Symbol*>(this)->getPrimitiveNumber(exec, number, value);
    return static_cast<const JSObject*>(this)->getPrimitiveNumber(exec, number, value);
}
예제 #14
0
파일: JSCell.cpp 프로젝트: B-Stefan/webkit
double JSCell::toNumber(ExecState* exec) const
{ 
    if (isString())
        return static_cast<const JSString*>(this)->toNumber(exec);
    if (isSymbol())
        return static_cast<const Symbol*>(this)->toNumber(exec);
    return static_cast<const JSObject*>(this)->toNumber(exec);
}
예제 #15
0
파일: syntax.c 프로젝트: tkmr/tonburi-scm
Bool isSyntaxRules(sExpression *exp){
  if(isList(exp) && isSymbol(car(toList(exp)))){
    if(strcmp(toSymb(car(toList(exp)))->name, "syntax-rules") == 0){
      return TRUE;
    }
  }
  return FALSE;
}
예제 #16
0
파일: syntax.c 프로젝트: tkmr/tonburi-scm
Bool isDefinitionSyntax(sExpression *exp){
  if(isList(exp) && isSymbol(car(toList(exp)))){
    if(strcmp(toSymb(car(toList(exp)))->name, "define-syntax") == 0){
      return TRUE;
    }
  }
  return FALSE;
}
예제 #17
0
bool Compiler2Pass::ValidateToken(const uint rulepathIDX, const uint activeRuleID)
{
	int tokenlength = 0;
	// assume the test is going to fail
	bool Passed = false;
	uint TokenID = mRootRulePath[rulepathIDX].mTokenID;
	// only validate token if context is correct
	if (mSymbolTypeLib[TokenID].mContextKey & mActiveContexts) {
	
		// if terminal token then compare text of symbol with what is in source
		if ( mSymbolTypeLib[TokenID].mRuleID == 0){

			if (positionToNextSymbol()) {
				// if Token is supposed to be a number then check if its a numerical constant
				if (TokenID == mValueID) {
					float constantvalue;
					if(Passed = isFloatValue(constantvalue, tokenlength)) {
						mConstants.push_back(constantvalue);
					}
					
				}
				// compare token symbol text with source text
				else Passed = isSymbol(mRootRulePath[rulepathIDX].mSymbol, tokenlength);
					
				if(Passed) {
					TokenInst newtoken;
					// push token onto end of container
					newtoken.mID = TokenID;
					newtoken.mNTTRuleID = activeRuleID;
					newtoken.mLine = mCurrentLine;
					newtoken.mPos = mCharPos;

					mTokenInstructions.push_back(newtoken);
					// update source position
					mCharPos += tokenlength;

					// allow token instruction to change the ActiveContexts
					// use token contexts pattern to clear ActiveContexts pattern bits
					mActiveContexts &= ~mSymbolTypeLib[TokenID].mContextPatternClear;
					// use token contexts pattern to set ActiveContexts pattern bits
					mActiveContexts |= mSymbolTypeLib[TokenID].mContextPatternSet;
				}
			}

		}
		// else a non terminal token was found
		else {

			// execute rule for non-terminal
			// get rule_ID for index into  rulepath to be called
			Passed = processRulePath(mSymbolTypeLib[TokenID].mRuleID);
		}
	}


	return Passed;

}
/**
 * Resolve a token to a parse option keyword.
 *
 * @return The corresponding keyword code.
 */
InstructionSubKeyword RexxToken::parseOption()
{
    // not a symbol?  not a keyword
    if (!isSymbol())
    {
        return SUBKEY_NONE;
    }
    return static_cast<InstructionSubKeyword>(resolveKeyword(stringValue, parseOptions, tabSize(parseOptions)));
}
예제 #19
0
파일: variable.c 프로젝트: tkmr/tonburi-scm
/* ------------- assingment value ---------------------*/
static sSymbol *assignSynbol(sExpression *exp){
  if(isList(exp)){
    sExpression *temp = cadr(toList(exp));
    if(isSymbol(temp)){
      return toSymb(temp);
    }
  }
  return toSymb(newSymbol("_error"));
}
/**
 * Resolve a token to a keyword value.
 *
 * @return The keyword identifier.
 */
InstructionKeyword RexxToken::keyword()
{
    // not a symbol?  not a keyword
    if (!isSymbol())
    {
        return KEYWORD_NONE;
    }
    return static_cast<InstructionKeyword>(resolveKeyword(stringValue, keywordInstructions, tabSize(keywordInstructions)));
}
/**
 * Resolve a condition name to a keyword code.
 *
 * @return The keyword code corresponding to the condition name.
 */
ConditionKeyword RexxToken::condition()
{
    // not a symbol?  not a keyword
    if (!isSymbol())
    {
        return CONDITION_NONE;
    }
    return static_cast<ConditionKeyword>(resolveKeyword(stringValue, conditionKeywords, tabSize(conditionKeywords)));
}
예제 #22
0
파일: JSCell.cpp 프로젝트: B-Stefan/webkit
JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const
{
    if (isString())
        return static_cast<const JSString*>(this)->toObject(exec, globalObject);
    if (isSymbol())
        return static_cast<const Symbol*>(this)->toObject(exec, globalObject);
    ASSERT(isObject());
    return jsCast<JSObject*>(const_cast<JSCell*>(this));
}
/**
 * Resolve a token to a subkeyword on a directive instruction.
 *
 * @return The code for the sub keyword.
 */
DirectiveSubKeyword RexxToken::subDirective()
{
    // not a symbol?  not a keyword
    if (!isSymbol())
    {
        return SUBDIRECTIVE_NONE;
    }
    return static_cast<DirectiveSubKeyword>(resolveKeyword(stringValue, subDirectives, tabSize(subDirectives)));
}
예제 #24
0
Expression *ASTBuilder::parseExpression() {
	Token *t = getCurrentToken();
	std::string data = t->getData();

	if(isSymbol(data)) return parseIdentifierExpression();
	if(isInteger(data)) return parseIntegerExpression();
	if(!data.compare("(")) return parseParensExpression();

	return NULL;
}
예제 #25
0
파일: variable.c 프로젝트: tkmr/tonburi-scm
/* --------- define value --------------------- */
static sSymbol *definitionSymbol(sExpression *exp){
  if(isList(exp)){
    sExpression *temp = cadr(toList(exp));
    if(isSymbol(temp)){
      return toSymb(temp);
    }else{
      return toSymb(car(toList(temp)));
    }
  }
  return toSymb(newSymbol("_error"));
}
예제 #26
0
파일: eval.c 프로젝트: tkmr/tonburi-scm
static sExpression *checkParametersIter(sExpression *parameters, sExpression *arguments){
  if(isList(arguments)){
    if(isList(parameters) && isSymbol(car(toList(parameters)))){
      return cons(car(toList(parameters)),
                  checkParametersIter(cdr(toList(parameters)),
                                      cdr(toList(arguments))));
    }else{
      return &sNull;
    }
  }
  return &sNull;
}
예제 #27
0
파일: variable.c 프로젝트: tkmr/tonburi-scm
static void putVars(sList *parameterNames, sList *arguments, TCMAP *mapdb){
  sExpression *firstP = car(parameterNames);
  sExpression *firstA = car(arguments);
  char *pName;
  void *aPointer;
  void *pPointer;
  int aSize;
  int pSize;

  if(isNull(firstP)){
    return;
  }

  if(isSymbol(firstP)){
    pName = toSymb(firstP)->name;
  }else{
    return;
  }

  pPointer = pName;
  pSize = strlen(pName) * sizeof(char);
  aPointer = firstA->value;
  aSize = firstA->valueSize;

  TCXSTR *str = getTypeTag(pName);
  tcmapput(mapdb, pPointer, pSize, aPointer, aSize);
  tcmapput(mapdb, (char *)tcxstrptr(str), tcxstrsize(str), &(firstA->type), sizeof(sType));

  sExpression *remainP = cdr(parameterNames);
  sExpression *remainA = cdr(arguments);
  if(isList(remainP) && isList(remainA)){
    return putVars(toList(remainP), toList(remainA), mapdb);
  }else if(isSymbol(remainP)){
    sList *lastOneParameter = toList(cons(remainP, &sNull));
    sList *lastOneArgument  = toList(cons(remainA, &sNull));
    return putVars(lastOneParameter, lastOneArgument, mapdb);
  }
  return;
}
예제 #28
0
static int ParseBrowser(SEXP CExpr, SEXP rho)
{
    int rval = 0;
    if (isSymbol(CExpr)) {
	const char *expr = CHAR(PRINTNAME(CExpr));
	if (!strcmp(expr, "c") || !strcmp(expr, "cont")) {
	    rval = 1;
	    SET_RDEBUG(rho, 0);
	} else if (!strcmp(expr, "f")) {
	    rval = 1;
	    RCNTXT *cntxt = R_GlobalContext;
	    while (cntxt != R_ToplevelContext 
		      && !(cntxt->callflag & (CTXT_RETURN | CTXT_LOOP))) {
		cntxt = cntxt->nextcontext;
	    }
	    cntxt->browserfinish = 1;	    
	    SET_RDEBUG(rho, 1);
	    R_BrowserLastCommand = 'f';
	} else if (!strcmp(expr, "help")) {
	    rval = 2;
	    printBrowserHelp();
	} else if (!strcmp(expr, "n")) {
	    rval = 1;
	    SET_RDEBUG(rho, 1);
	    R_BrowserLastCommand = 'n';
	} else if (!strcmp(expr, "Q")) {

	    /* Run onexit/cend code for everything above the target.
	       The browser context is still on the stack, so any error
	       will drop us back to the current browser.  Not clear
	       this is a good thing.  Also not clear this should still
	       be here now that jump_to_toplevel is used for the
	       jump. */
	    R_run_onexits(R_ToplevelContext);

	    /* this is really dynamic state that should be managed as such */
	    SET_RDEBUG(rho, 0); /*PR#1721*/

	    jump_to_toplevel();
	} else if (!strcmp(expr, "s")) {
	    rval = 1;
	    SET_RDEBUG(rho, 1);
	    R_BrowserLastCommand = 's';	    
	} else if (!strcmp(expr, "where")) {
	    rval = 2;
	    printwhere();
	    /* SET_RDEBUG(rho, 1); */
	}
    }
    return rval;
}
예제 #29
0
파일: syntax.c 프로젝트: tkmr/tonburi-scm
static void *applySyntaxToRule(sExpression *key, sExpression *value, sExpression *rule){
  if(isList(key) && isList(cdr(toList(key))) && isSymbol(cadr(toList(key))) && (strcmp(toSymb(cadr(toList(key)))->name, "...") == 0) &&
     isList(rule) && isList(cdr(toList(rule))) && isSymbol(cadr(toList(rule))) && (strcmp(toSymb(cadr(toList(rule)))->name, "...") == 0))
  {
    if(isList(value)){
      if(isSymbol(car(toList(rule)))){
        sExpression *tempRule = newSymbol(toSymb(car(toList(rule)))->name);
        evalSyntaxRuleIter(car(toList(key)), car(toList(value)), tempRule);

        if(isSymbol(tempRule) && strcmp(toSymb(tempRule)->name, toSymb(car(toList(rule)))->name) == 0){
          //printExp(rule);
        }
        else{
          if(isNull(cdr(toList(value)))){
            rule->value = cons(tempRule, &sNull)->value;
          }
          else{
            rule->value = cons(tempRule,
                             cons(car(toList(rule)),
                                  cdr(toList(rule))))->value;
            rule->type = LIST_TAG;
            applySyntaxToRule(key, cdr(toList(value)), cdr(toList(rule)));
          }
        }
      }
    }
  }
  else if(isList(rule)){
    applySyntaxToRule(key, value, car(toList(rule)));
    applySyntaxToRule(key, value, cdr(toList(rule)));
  }
  else if(isSymbol(rule) && strcmp(toSymb(key)->name, toSymb(rule)->name) == 0){
    rule->value = value->value;
    rule->type = value->type;
  }
}
예제 #30
0
bool CScanner::ParseSymbol()
{
	string TempString = "";
	UpdateCurrentToken();	
	while (isSymbol(cget()) && TempString.length() < 3)
		TempString += cget(), IncPos();
	while(!SymbolicTokenMapping.find(TempString))
	{
		TempString.erase(TempString.end() - 1), DecPos();
	}
	CurrentToken.Kind = SymbolicTokenMapping[TempString];
	CurrentToken.Value.reset();
	CurrentToken.Value = TempString;
	return true;
}