Пример #1
0
globle void CheckSyntaxFunction(
  DATA_OBJECT *returnValue)
  {
   DATA_OBJECT theArg;

   /*===============================*/
   /* Set up a default return value */
   /* (TRUE for problems found).    */
   /*===============================*/

   SetpType(returnValue,SYMBOL);
   SetpValue(returnValue,TrueSymbol);

   /*=====================================================*/
   /* Function check-syntax expects exactly one argument. */
   /*=====================================================*/

   if (ArgCountCheck("check-syntax",EXACTLY,1) == -1) return;

   /*========================================*/
   /* The argument should be of type STRING. */
   /*========================================*/

   if (ArgTypeCheck("check-syntax",1,STRING,&theArg) == FALSE)
     { return; }

   /*===================*/
   /* Check the syntax. */
   /*===================*/

   CheckSyntax(DOToString(theArg),returnValue);
  }
Пример #2
0
int main(int argc, char **argv)
{
  //check usage
  if(argc != 2) {
      fprintf(stderr, "--------------------------------------------------\n");
      fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
      fprintf(stderr, "--------------------------------------------------\n");
      fprintf(stderr, "filename: File containing EDISON execution script.\n");
      fprintf(stderr, "--------------------------------------------------\n");
      exit(1);
  }
  
  //parse the source file and check for
  //syntaxical errors
  CmCParser *srcParser = new CmCParser;
  CmCError error = CheckSyntax(argv[1], srcParser);
  if(error.errorCode_) {
    Report(&error, argv[1], srcParser);
    exit(1);
  }

  //execute script
  error = Run(srcParser);
  if(error.errorCode_) {
    Report(&error, argv[1], srcParser);
    exit(1);
  }

  //de-allocate parser
  delete srcParser;

  return 0;
}
wxString wxStringFormatter::Parse(wxString input)
{
	if(CheckSyntax(input)) return input;
	input = DoBlocks(input);
	input = DoFunctions(input);
	input = ReplaceSymbols(input);
	input = DoConcat(input);
	return input;
}
LRESULT LuaScriptEditorView::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
   if (wParam == IDT_TIMER_SYNTAX_CHECK)
   {
      KillTimer(IDT_TIMER_SYNTAX_CHECK);

      CheckSyntax();
   }

   return 0;
}
Пример #5
0
/****************************************************
  DisplayResults( )
  Display script file information
****************************************************/
void CScript::DisplayResults(string scriptfile){

  ifstream in;
  ofstream out("temp.fil",ios::out);
  string line;
  string lineout;
  streamsize count;
  int linecount = 0;
  int num_errors = 0;
  int status = 0;
  char c[255];
  bool validformat = true;
  
  //in.open("script.gam");
  in.open(scriptfile.c_str());    //filename passed as command line argument
  if(!in){
   exit(0); 
  }

  cout << "*********************************" << endl;
  cout << "Grace Engine v0.1 Sript Processor" << endl;
  cout << "*********************************" << endl;
    
  while (getline(in, line)){  //get one line at a time from script file
    lineout= CleanUp(line);   //clean up line
    linecount += 1;
    cout << linecount << ": " << lineout << endl;  
    if( lineout.find(";") != string::npos) Push(lineout);
    status = CheckSyntax(lineout);
    if (status > SYNTAX_OK) num_errors += 1;

    switch (status){  //check for syntax errors
      case SYNTAX_OK:
        out << lineout << endl;
        break;
      case SYNTAX_PARENTHESIS:
        cout << "        ^ ^ ^ " << endl;
        cout << "       Parenthesis...open or closed...doesn't add up!" <<
                 endl<< endl;
        break;
      case SYNTAX_OPEN_PARENTHESIS:
        cout << "        ^ ^ ^ " << endl;
        cout << "       Open parenthesis is missing!" << endl<< endl;
        break;
      case SYNTAX_CLOSED_PARENTHESIS:
        cout << "        ^ ^ ^ " << endl;
        cout << "       Closed parenthesis is missing!" << endl<< endl;
        break;
      case SYNTAX_SEMICOLON:
        cout << "        ^ ^ ^ " << endl;
        cout << "       Missing semicolon!" << endl<< endl;
        break;
      case SYNTAX_UNKNOWN:
        cout << "        ^ ^ ^ " << endl;
        cout << "       Unknown error!" << endl<< endl;
        break;
      case SYNTAX_QUOTE:
        cout << "        ^ ^ ^ " << endl;
        cout << "       Odd number of quotation marks.!" << endl<< endl;
        break;
      
    } 
  }
  
  //check braces
  if(left_brace != right_brace){
    num_errors++;
    cout << "        ^ ^ ^ " << endl;
    cout << "       Number of left and right braces are unequal!" << endl<< endl;
  }
  
  cout << endl;
  cout << "*********************************" << endl;
  cout << num_errors << " errors was/were detected!" << endl;
  cout << "*********************************" << endl;
  cout << endl;
  number_errors = num_errors;
  //return num_errors;
}
Пример #6
0
int 
OpenDocument(
    WORD    mode,
    WORD    type,
    int     doc,
    LPSTR   FileName,
    int     dupView,
    int     Preference,
    BOOL    bUserActivated
    )

/*++

Routine Description:

    This routine is used to create a new document or to duplicate
    the view of an existing document.

Arguments:

    mode        - Supplies MODE_DUPLICATE if the document is to be duplicated
                           MODE_RELOAD if the file is to be reloaded
                           MODE_CREATE if the document is to be created
    type        - Supplies the document type
    doc         - Supplies
    FileName    - Supplies a pointer to the name of the file for the document
    dupView     - Supplies the view to be duplicated (mode == MODE_DUPLICATE)
    Preference  - Supplies the view preference (-1 if none)
    bUserActivated - Indicates whether this action was initiated by the
                user or by windbg. The value is to determine the Z order of
                any windows that are opened.

Return Value:

    -1 on failure
    view number on success (>= 0)
    return-value - Description of conditions needed to return value. - or -

--*/

{
    LPLINEREC   pl;
    int         nView = 0;
    BOOL        create;
    int         n;
    int         language;
    LPDOCREC    d;
    LPVIEWREC   views;

    //
    //  In mode duplicate, we create a new nView being a copy of the previous
    //  nView of the same document
    //

    if (mode == MODE_DUPLICATE) {

        //
        // Search a free entry for the nView we will create
        //

        if ( (Preference != -1) && Views[ Preference ].Doc == -1 ) {
            nView = Preference;
        } else {
            for (nView = 0; (nView < MAX_VIEWS) && (Views[nView].Doc != -1); nView++);
        }

        if (nView == MAX_VIEWS) {
            ErrorBox(ERR_Too_Many_Opened_Views);
            return -1;
        }

        //
        // Copy parameters from previous nView
        //

        Assert( Docs[Views[dupView].Doc].FirstView >= 0);

        //
        //      Find the last nView for this document
        //

        n = dupView;
        while (Views[n].NextView != -1) {
            n = Views[n].NextView;
        }

        Assert(n < MAX_VIEWS);

        //
        //     Attach new nView to last one found
        //

        Views[nView] = Views[n];
        Views[n].NextView = nView;
        Views[nView].hwndClient = NULL;

        //
        //
        //

        Views[nView].iYTop = Views[dupView].iYTop;

        //
        //     Enlist nView in window menu
        //

        AddWindowMenuItem(Views[dupView].Doc, nView);

        return nView;

    } else if (mode == MODE_RELOAD) {
        nView = Docs[doc].FirstView;
    }

    //
    // First search a free entry for the document
    //

    if (mode != MODE_RELOAD) {
        for (doc = 0; (doc < MAX_DOCUMENTS) && (Docs[doc].FirstView != -1); doc++);
    }

    if (doc >= MAX_DOCUMENTS) {
        ErrorBox(ERR_Too_Many_Opened_Documents);
        return -1;
    }

    d = &Docs[doc];

    if (type == DOC_WIN) {

        //
        //      Check if file is not already loaded
        //

        if (mode == MODE_RELOAD) {
            DestroyDocument(doc);
            language = SetLanguage(doc);
        } else {
            if (FileName != NULL) {
                TCHAR szAbsolutePath[_MAX_PATH] = {0};

                Assert(sizeof(szAbsolutePath) == sizeof(d->szFileName));

                // We may have a relative path name to a file. Try to get the absolute path.
                if ( _fullpath(szAbsolutePath, FileName, sizeof(szAbsolutePath) ) ) {
                    // success
                    _tcscpy(d->szFileName, szAbsolutePath);
                } else {
                    // error. Use as is.
                    _tcscpy(d->szFileName, FileName);
                }

                for (n = 0; n < MAX_DOCUMENTS; n++) {
                    if (Docs[n].FirstView != -1
                        && _strcmpi(Docs[n].szFileName, d->szFileName) == 0) {

                        SetMessageText_StatusBar(ERR_File_Already_Loaded, STATUS_INFOTEXT, FileName);
                        MessageBeep(0);

                        //
                        //  Reactivate window
                        //

                        //SendMessage(g_hwndMDIClient, WM_MDIACTIVATE, (WPARAM) Views[Docs[n].FirstView].hwndFrame, 0L);
                        ActivateMDIChild(Views[Docs[n].FirstView].hwndFrame, bUserActivated);
                        return -1;
                    }
                }

                language = SetLanguage(doc);

            } else {
                // shouldn't happen anymore
                Assert(0);
// BUGBUG - dead code - kcarlos
#if 0
                //
                //  Initialize document record and first nView
                //

                register int i, j;

                for (i = 0; i < MAX_DOCUMENTS; i++) {
                    CreateUntitled(d->FileName, i + 1);
                    for (j = 0; j < MAX_DOCUMENTS; j++) {
                        if (j != doc &&
                            _strcmpi (d->szFileName, Docs[j].szFileName) == 0) {
                            break;
                        }
                    }
                    if (j >= MAX_DOCUMENTS) {
                        break;
                    }
                }

                language = C_LANGUAGE;
#endif
            }
        }
    } else {

        WORD winTitle;
        char rgch[MAX_MSG_TXT];

        language = NO_LANGUAGE;

        //
        //  Non Document type, Load window title from ressource
        //

        switch (type) {

        case DISASM_WIN:
            winTitle = SYS_DisasmWin_Title;
            break;       
        case COMMAND_WIN:
            winTitle = SYS_CmdWin_Title;
            break;
        case MEMORY_WIN:
            winTitle = SYS_MemoryWin_Title;
            break;
        default:
            Assert(FALSE);
            return -1;
            break;
        }
        Dbg(LoadString(g_hInst, winTitle, rgch, MAX_MSG_TXT));
        RemoveMnemonic(rgch, d->szFileName);

        if (type == MEMORY_WIN) {
            lstrcat (d->szFileName,"(");
            lstrcat (d->szFileName,TempMemWinDesc.szAddress);
            lstrcat (d->szFileName,")");
        }
    }

    //
    //  Then search a free entry for the first nView we will create
    //

    if (mode != MODE_RELOAD) {

        if ( (Preference != -1) && Views[ Preference ].Doc == -1 ) {
            nView = Preference;
        } else {
            for (nView = 0; nView < MAX_VIEWS && Views[nView].Doc != -1; nView++);
        }
        if (nView == MAX_VIEWS) {
            ErrorBox(ERR_Too_Many_Opened_Views);
            return -1;
        }
    }

    //
    // Check if file exist
    //

    if (mode == MODE_CREATE || type != DOC_WIN) {
        create = TRUE;
    } else {
        if (mode == MODE_OPEN || FileExist(FileName)) {
            create = FALSE;
        } else {
            if (mode == MODE_OPENCREATE) {
                // Tell the user that the file does not exist.

                // kcarlos
                // BUGBUG
                // Quick hack. To fix a bug, hopefully this all disappear soon.
                VarMsgBox(hwndFrame, SYS_Does_Not_Exist_Create, MB_OK, FileName);
                return -1;
            } else {
                create = FALSE;
            }
        }
    }

    d->readOnly = FALSE;
    d->docType = type;
    d->language = (WORD) language;
    d->untitled = (FileName == NULL);
    d->ismodified = FALSE;

    if (create) {

        LPBLOCKDEF pb;

        //
        //  Initialize the file with a null-string
        //


        d->LastBlock = d->FirstBlock = (LPBLOCKDEF)DocAlloc(sizeof(BLOCKDEF));
        GetSystemTimeAsFileTime(&d->time);

        if (d->FirstBlock == NULL) {
            ErrorBox(SYS_Allocate_Memory);
            return -1;
        }

        pb = d->FirstBlock;

        //
        //  Initialize first block
        //

        pb->PrevBlock = pb->NextBlock = NULL;
        pb->LastLineOffset = 0;

        //
        // Initialize first line
        //

        pl = (LPLINEREC)pb->Data;
        pl->PrevLength = 0;
        pl->Length = LHD;
        pl->Status = 0;

        d->NbLines = 1;         // We start with one null line

    } else {

        //
        // Load the file and check if it's a valid one
        //

        if (!LoadFile(doc)) {
            return -1;
        }
    }

    //
    // Initialize current pointers
    //

    d->CurrentBlock = d->FirstBlock;
    d->CurrentLine = 0;
    d->CurrentLineOffset = 0;
    pl = (LPLINEREC)(d->FirstBlock->Data);
    ExpandTabs(&pl);

    //
    // Undo/redo part
    //

    d->undo.h = 0;
    d->redo.h = 0;
    d->playCount = REC_CANNOTUNDO;
    if (g_contGlobalPreferences_WkSp.m_dwUndoResize == 0 || type != DOC_WIN) {
        d->recType = REC_STOPPED;
    } else {
        d->recType = REC_UNDO;
    }
    CreateRecBuf(doc, REC_UNDO, g_contGlobalPreferences_WkSp.m_dwUndoResize);

    if (mode == MODE_RELOAD) {
        RefreshWindowsTitle(doc);
    } else {

        //
        //  Initialize nView part
        //

        views = &Views[nView];
        views->NextView = -1;
        views->X = views->Y = 0;
        views->hwndClient = views->hwndFrame = NULL;
        views->hScrollBar = g_contGlobalPreferences_WkSp.m_bHorzScrollBars;
        views->vScrollBar = g_contGlobalPreferences_WkSp.m_bVertScrollBars;
        views->scrollFactor = 0;
        views->iYTop = -1;

        //
        //  Everything is OK, add title in window menu and return the nView
        //

        d->FirstView = nView;
        views->Doc = doc;
        AddWindowMenuItem(doc, nView);
    }

    //
    // Check syntax if C
    //

    if (d->language == C_LANGUAGE) {
        d->lineTop = 0;
        d->lineBottom = d->NbLines;
        CheckSyntax(doc);
    }

    return nView;
}                                       // OpenDocument()
Пример #7
0
BOOL FAR  MergeFile(LPSTR FileName, int view)
{
    HCURSOR hSaveCursor;
    char line[MAX_USER_LINE + 1];
    int offset; //Current offset of storage in block
    int lineLen; // length of line
    BYTE prevLength; //Previous line size
    LPVIEWREC v = &Views[view];
    WORD res;
    LPDOCREC d =&Docs[v->Doc];
    LPLINEREC pCurLine, pLastLine;
    LPBLOCKDEF pCurBlock, pNewBlock;
    long y;

    Assert( v->Doc >= 0);


    if ((hFileDoc = _lopen(FileName, OF_READ)) == HFILE_ERROR)
          return ErrorBox(ERR_File_Open, (LPSTR)FileName);

    if ((pszBufferDoc = DocAlloc(DISK_BLOCK_SIZE)) == NULL) {
        ErrorBox(SYS_Allocate_Memory);
        goto error1;
    }

    dwBytesReadDoc = DISK_BLOCK_SIZE;
    dwOffsetDoc = DISK_BLOCK_SIZE;
    lineLen = 0;

    //Delete selected text if any
    if (v->BlockStatus) {

        long XR, YR;

        GetBlockCoord (view, &(v->X), &(v->Y), &XR, &YR);
        DeleteStream(view, v->X, v->Y, XR, YR, FALSE);
    }

    //Set the Hour glass cursor
          hSaveCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));

    //Insert first line

    res = LoadLine(line, &lineLen, d->NbLines);
    if (res == END_OF_FILE || res == END_OF_LINE) {

        //Add a CR+LF
        if (res == END_OF_LINE) {
            line[lineLen] = CR;
            line[lineLen + 1] = LF;
            lineLen += 2;
        }
        if (!InsertBlock(v->Doc, v->X, v->Y, (WORD) lineLen, line))
            goto error2;
    }
    else {

        if (res == ERR_File_Read || res == ERR_Not_A_Text_File)
              ErrorBox(res, (LPSTR)FileName);
        goto error2;
    }

    if (res != END_OF_FILE) {

        //Get current line status (we just inserted it)

        y = v->Y;
        if (!FirstLine(v->Doc, &pCurLine, &y, &pCurBlock))
              return FALSE;

        //Get next line (just after the line we just inserted)

        if (!NextLine(v->Doc, &pCurLine, &y, &pCurBlock))
              return FALSE;

        //Set offset to StoreLine start
              offset =  (LPSTR)pCurLine - (LPSTR)pCurBlock->Data;
        prevLength = pCurLine->PrevLength;

        //Split block in 2 blocks by first allocating a new block and then
        //copying right side of block in new block

        if (!AllocateBlock(pCurBlock, pCurBlock->NextBlock, &pNewBlock))
              return FALSE;

        pLastLine = (LPLINEREC)(pCurBlock->Data + pCurBlock->LastLineOffset);
        memmove(pNewBlock->Data, (LPSTR)pCurLine,
              (LPSTR)pLastLine - (LPSTR)pCurLine + pLastLine->Length);

        //Set new old block len and new new block len
              pCurBlock->LastLineOffset = (LPSTR)pCurLine - (LPSTR)pCurBlock->Data - pCurLine->PrevLength;
        pNewBlock->LastLineOffset = (LPSTR)pLastLine - (LPSTR)pCurLine;

        //Backward links next block with new one
        if (pCurBlock->NextBlock == NULL)
              d->LastBlock = pNewBlock;
        else
              (pCurBlock->NextBlock)->PrevBlock = pNewBlock;

        //Forward link current block with new block

        pCurBlock->NextBlock = pNewBlock;

        CloseLine(v->Doc, &pCurLine, y, &pCurBlock);

        //Read and store all lines in new blocks

        res = LoadLine(line, &lineLen, d->NbLines);
        while (res == END_OF_LINE) {

            //Truncate a file too large

            if (d->NbLines >= MAX_LINE_NUMBER - 1) {
                ErrorBox(ERR_Truncate_Doc);
                res = END_OF_FILE;
                break;
            }

            if (!StoreLine(line, lineLen, &offset, &prevLength, &pCurBlock)) {
                res = END_ABORT;
                break;
            }

            res = LoadLine(line, &lineLen, ++d->NbLines);
        }

        //Take decisions
        switch (res) {

          case END_OF_FILE:

            //Store last line
            if (StoreLine(line, lineLen, &offset, &prevLength, &pCurBlock)) {

                d->NbLines++;

                //Forward link of last allocated block with new block

                pCurBlock->NextBlock = pNewBlock;

                //Backward link of new block with last allocated block

                pNewBlock->PrevBlock = pCurBlock;
                ((LPLINEREC)(pNewBlock->Data))->PrevLength = (BYTE)(lineLen + LHD);

                //Free memory

                if (!DocFree(pszBufferDoc))
                      InternalErrorBox(SYS_Free_Memory);

                //Restore cursor

                SetCursor(hSaveCursor);

                //Check syntax if C

                if (d->language == C_LANGUAGE) {
                    d->lineTop = 0;
                    d->lineBottom = d->NbLines;
                    CheckSyntax(v->Doc);
                }
                SetVerticalScrollBar(view, TRUE);

                PosXY(view, v->X, v->Y, FALSE);
                InvalidateRect(v->hwndClient, (LPRECT)NULL, FALSE);

                CloseHandle (hFileDoc);
                return TRUE;
            }
            else
                goto abort;

          case ERR_File_Read:
          case ERR_Not_A_Text_File:
            ErrorBox(res, (LPSTR)FileName);
            //Fall through

          case END_ABORT:
            {

              abort:
                SetCursor(hSaveCursor);
                break;
            }

          default:
            Assert(FALSE);
            break;
        }

    } else
          InvalidateRect(v->hwndClient, (LPRECT)NULL, FALSE);

  error2: {
        SetCursor (hSaveCursor);
        if (!DocFree(pszBufferDoc))
              InternalErrorBox(SYS_Free_Memory);
    }

  error1: {
        CloseHandle (hFileDoc);
    }

    return FALSE;
}                                       /* MergeFile() */
Пример #8
0
LRESULT ScoreErrorsDlg::OnCheck(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CheckSyntax();
	return 0;
}