예제 #1
0
파일: Parser.cpp 프로젝트: Arkm4n/Syntaxer
    sptr<Node> Parser::ParseWith()
    {
        sptr<StmntNode> root(new StmntNode(currToken));
        NextToken(); // Skip with
        sptr<Node> subroot(new VarListNode(ParseVar(), "Var list"));

        while(MatchSkip(COMMA, -1))
            subroot->PushChild(ParseVar());

        root->PushChild(subroot);
        Expect(DO, -1);
        root->PushChild(ParseStatement());
        return root;
    }
예제 #2
0
파일: Parser.cpp 프로젝트: Arkm4n/Syntaxer
 sptr<Node> Parser::ParseAssign(sptr<VarNode> ident)
 {
     sptr<AssignNode> root(new AssignNode(ParseVar(ident), currToken));
     Expect(ASSIGN, -1);
     root->PushChild(ParseExp());
     return root;
 }
예제 #3
0
bool cVarParser::ParseCondExp(const string& input)
{
   int condEndPos = input.find("?");
   string cond(input.begin(), input.begin() + condEndPos);
   int condNeqPos = cond.find("!=");
   int condEqPos = cond.find("==");

   if (condEqPos == -1 && condNeqPos == -1)
   {
      cond += "!=";
      condNeqPos = cond.find("!=");
   }

   if (condEqPos >= 0 || condNeqPos >= 0)
   {
      if (!ParseEquality(cond))
      {
         LogFile.eSysLog("error parsing '%s'", input.c_str());
         return false;
      }
      condOp = (condEqPos >= 0)?condEq:condNeq;
   }
   else
   {
      LogFile.eSysLog("error parsing '%s'", input.c_str());
      return false;
   }

   string truefalse(input.begin() + condEndPos + 1, input.end());
   int elsePos = truefalse.find(":");
   if (elsePos >= 0)
   {
      string truePart(truefalse.begin(), truefalse.begin() + elsePos);
      string falsePart(truefalse.begin() + elsePos + 1, truefalse.end());
      if (ParseVar(truePart) && ParseVar(falsePart))
      {
         condvarTrue = Strip(truePart);
         condvarFalse = Strip(falsePart);
	 type = cVarParser::condition;
         return true;
      }
   }
   LogFile.eSysLog("error parsing '%s'", input.c_str());
   condEqLeft = condEqRight = "";
   return false;
}
예제 #4
0
bool CArea::GetValueFromVo(string VO)
{
	if (!ParseTypeMode(VO)) return false;
	if (!ParseDataType(VO)) return false;
	if (!ParseAxis(VO)) return false;
	if (!ParseVar(VO)) return false;
	if (!ParseDefLine(VO)) return false;
	if (!ParseWeight(VO)) return false;
	if (!ParseOutput(VO)) return false;
	return true;
}
예제 #5
0
파일: Parser.cpp 프로젝트: Arkm4n/Syntaxer
 sptr<ExprNode> Parser::ParsePrimary()
 {
     sptr<ExprNode> primary = nullptr;
     if (Match(INTEGER, REAL, HEX, CHARACTER, STRING, -1))
     {
         primary = sptr<ConstNode>(new ConstNode(currToken));
         NextToken();
     }
     else if (Match(IDENT, -1))
     {
         sptr<VarNode> ident = ParseIdent();
         primary = Match(OPENBRAC, -1) ? ParseVar(ParseFuncCall(ident)) : ParseVar(ident);
     }
     else if (Match(OPENBRAC, -1))
     {
         NextToken();
         primary = ParseExp();
         if (Match(CLOSEBRAC)) NextToken();
         else throw ParserException("Enclosed bracket error");
     }
     return primary;
 }
예제 #6
0
char *ParseVar(char *Buff, const char **Line, ListNode *LocalVars, int Flags)
{
char *VarName=NULL, *OutStr=NULL, *Tempstr=NULL;
const char *ptr, *vptr;

OutStr=Buff;
ptr=*Line;

if (*ptr=='(') ptr++;

	while ((*ptr !=')') && (*ptr !='\0'))
	{
		if (*ptr=='$') 
		{
			ptr++;
			Tempstr=ParseVar(Tempstr,&ptr,LocalVars,Flags);
			VarName=CatStr(VarName,Tempstr);
		}
		 else VarName=AddCharToStr(VarName,*ptr);
	 ptr++;
	}

*Line=ptr; //very important! Otherwise the calling process will not 
	   //know we have consumed some of the text!

	//Now lookup var/format/append to output
	if (! (Flags & SUBS_CASE_VARNAMES)) strlwr(VarName);

	vptr=GetVar(LocalVars,VarName);

	if (Flags & SUBS_QUOTE_VARS) OutStr=CatStr(OutStr,"'");

	if (Flags & SUBS_STRIP_VARS_WHITESPACE) 
	{
		Tempstr=CopyStr(Tempstr,vptr);
		StripTrailingWhitespace(Tempstr);
		StripLeadingWhitespace(Tempstr);
   	OutStr=CatStr(OutStr,Tempstr);
	}
  else OutStr=CatStr(OutStr, vptr);

	if (Flags & SUBS_QUOTE_VARS) OutStr=CatStr(OutStr,"'");

DestroyString(VarName);
DestroyString(Tempstr);

return(OutStr);
}
예제 #7
0
bool cVarParser::ParseAssign(const string& input)
{
   int assignPos = input.find("=");
   if (assignPos >= 0)
   {
      string var(input.begin(), input.begin() + assignPos);
      if (ParseVar(var))
      {
         varName = Strip(var);
         string assign(input.begin() + assignPos + 1, input.end());
         return ParseExp(assign);
      }
   }
   LogFile.eSysLog("error parsing '%s'", input.c_str());
   return false;
}
예제 #8
0
char *SubstituteVarsInString(char *Buffer, const char *Fmt, ListNode *Vars, int Flags)
{
char *ReturnStr=NULL, *VarName=NULL, *Tempstr=NULL;
const char *FmtPtr;
int count, VarIsPointer=FALSE;
ListNode *Curr;
int len=0, i;

ReturnStr=CopyStr(Buffer,"");

if (! Fmt) return(ReturnStr);


FmtPtr=Fmt;
while (*FmtPtr !=0)
{
	switch (*FmtPtr)
	{

		case '\\':
			FmtPtr++;
			switch (*FmtPtr)
			{
			   case 't':
				ReturnStr=AddCharToStr(ReturnStr,' ');
				len=StrLen(ReturnStr);
				while ((len % 4) !=0)
				{
				ReturnStr=AddCharToStr(ReturnStr,' ');
				len++;
				}
			   break;

			   case 'r':
				ReturnStr=AddCharToStr(ReturnStr,'\r');
				len++;
			   break;

			   case 'n':
				ReturnStr=AddCharToStr(ReturnStr,'\n');
				len++;
			   break;

			   default:
				ReturnStr=AddCharToStr(ReturnStr,*FmtPtr);
				len++;
			}
		break;

		case '$':
		FmtPtr++;
		/*
			if (*FmtPtr=='$')
			{
				 VarIsPointer=TRUE;
				 FmtPtr++;
			}
			if (*FmtPtr=='(') FmtPtr++;
			*/

		ReturnStr=ParseVar(ReturnStr, &FmtPtr, Vars, Flags);
 		break;

		case '"':
			FmtPtr++;
			while (*FmtPtr && (*FmtPtr !='"')) 
			{
			 	ReturnStr=AddCharToStr(ReturnStr,*FmtPtr);
				len++;
				FmtPtr++;
			}
			break;
 
		default:
			 ReturnStr=AddCharToStr(ReturnStr,*FmtPtr);
			 len++;
	}

FmtPtr++;
}


DestroyString(Tempstr);
DestroyString(VarName);
return(ReturnStr);
}