Пример #1
0
int _tmain(int argc, _TCHAR* argv[])
{
	const char* buffer = NULL;
	if (argv[1] == NULL)
		buffer = ReadFile(L"RecursParser.txt");
	else buffer = ReadFile(argv[1]);
	//s = (char*)buffer;

	int val = GetG0(buffer);

	printf("eval = <%d> \n", val);

	return 0;
}
Пример #2
0
int main()
{
    FILE*  in = fopen("input.txt", "r");
 //   FILE* out = fopen("output.txt", "w");

    char* str = read_string(in);
    int result = 0;
    int bracket_count = 0;

    try
    {
        int length = strlen(str);

        for (int i = 0; i < length; i++)
        {
            if (str[i] == '(')
            {
                if ('0' <= str[i+1] && str[i+1] <= '9' || str[i+1] == '(')
                {
                    bracket_count++;
                }
                else
                {
                    throw 2;
                }
            }

            if (str[i] == ')')
            {
                if (str[i+1] == '+' || str[i+1] == '-' || str[i+1] == '*' || str[i+1] == '/' || str[i+1] == '\0' || str[i+1] == ')')
                {
                    bracket_count--;
                }
                else
                {
                    throw 2;
                }
            }
        }
        if (bracket_count != 0)
        {
            throw 2;
        }

        result = GetG0(str);
    }
    catch (int error)
    {
        switch (error)
        {
            case 0:
            {
                printf("# Division by zero. ");
                break;
            }
            case 1:
            {
                printf("# Unknown error. ");
                break;
            }
            case 2:
            {
                printf("# Wrong bracket order. ");
                break;
            }
            case 3:
            {
                printf("# Wrong symbolic equation. ");
                break;
            }
        }

        printf("Program will be terminated #");
        free(str);
        fclose(in);
        return 0;
    }

    for(int i = 0; i < buf_count; i++)
    {
        printf("%c", buf[i]);
    }

    printf("\n\n%d", result);

    free(str);
 //   fclose(out);
    fclose(in);
    return 0;

}
Пример #3
0
int _tmain(int argc, _TCHAR* argv[])
{
	if (!strcmp(wtoc(argv[1]), "-help"))
	{
		PrintHelp();
		system("pause");
		return 0;
	}
	//char* buffer = ReadFile(L"tempLang.txt");
	char* buffer = ReadFile(argv[1]);
	if (buffer == NULL) { printf("NO FILE!!"); return 1; }
	int countOfLexem = 0;
	lex* lexic = Lexer(buffer, &countOfLexem);

	errno_t err1 = fopen_s(&Fdotty, "E:\\C++\\Derivative\\Derivative\\dumpTree.gv", "w");
	fprintf(Fdotty, "graph graphname {");

	errno_t err2 = fopen_s(&ftrans, "FileForASM.txt", "w");

	for (int i = 0; i < countOfLexem; i++)
	{
		printf("lexem number %d :\n"
			"value <%s>\n"
			"type <%d>\n"
			"current pos <%s>\n\n", i, lexic[i].val, lexic[i].type, lexic[i].pos);
	}

	Var.vars = new char*[COUNTOFREGISTER];

	node* top = GetG0(lexic);
	if (!top) printf("SYNTAX ERROR!!!\n"
		"at this symbol %s \n", s->pos);
	s++;
	node* funcTop = GetG0(s);
	node* Main = new node;
	NODECTOR(Main, "main", T_op, top, funcTop);
	if (!top) printf("SYNTAX ERROR!!!\n"
		"at this symbol %s \n", s->pos);
	int count = 0;
	PrintTree(Main, &count);

	FILE* fout = NULL;
	errno_t err = fopen_s(&fout, "Expression.txt", "w");
	Print(Main, fout);
	DottyTree(Main);
	int countOfJump = 0, pop = 0, flag = 0;
	Translate(Main, countOfJump, &pop, flag);
	//fprintf(ftrans, "end");
	//reg regis = {};

	fprintf(Fdotty,"}");
	fclose(Fdotty);
	fclose(ftrans);
	/////////////////////////////////////////////////
	//char* FROM = "C:\\Users\\Vladimir\\Documents\\Visual Studio 2013\\Projects\\ENLang\Debug"

	/////////////////////////////////////////////////
	system("E:\\C++\\Graphviz2.38\\bin\\dotty.exe E:\\C++\\Derivative\\Derivative\\dumpTree.gv");
	system("pause");

	return 0;
}