parse.c
/*
 *  parseSourceLine - parse a line of source text
 *
 *  This is the main processing function of the assembler. The line of source code
 *  to be processed is expected to be found in the global sourceLine array.
 */
parse a line of source text
This is the main processing function of the assembler. The line of source code
to be processed is expected to be found in the global sourceLine array.
parse a line of source text This is the main processing function of the assembler . The line of source code to be processed is expected to be found in the global sourceLine array .
ErrorCode parseSourceLine(void) {
    ErrorCode err;
    NamedInstruction *inst;
    int len;
    MacroDefn *macroDefn;
    char *s;
    Symbol *symbol;
    Token token;
    err = Err_None;
    resetLocationField();
    resetErrorRegistrations();
    listSource();
    if (sourceLine[0] == '*' || sourceLine[0] == '\0') {
        listFlush(currentSection);
        return err;
    }
    getFields();
      Process the location field. It may have at most one token,
      and the one token must be an unqualified name.
    s = getNextToken(locationField, &token);
    switch (token.type) {
    case TokenType_Name:
        if (*s == '\0' && isUnqualifiedName(&token)) {
            locationFieldToken = copyToken(&token);
        }
        else {
            err = registerError(Err_LocationField);
        }
        break;
    case TokenType_None:
         do nothing
        break;
    case TokenType_Error:
        err = registerError(token.details.error.code);
        break;
    default:
        err = registerError(Err_LocationField);
        break;
    }
      Process the result field. First, check for a macro call, then
      check for a pseudo-instruction or a named machine instruction.
      if no matches are found for those, attempt to match other
      machine instruction patterns.
    len = strlen(resultField);
    if (len > 0) {
          Process macro calls
        macroDefn = findMacroDefn(resultField, len);
        if (macroDefn != NULL) {
            listCodeLocation(currentSection);
            err = registerError(callMacro(macroDefn, locationFieldToken));
        }
          Process pseudo-instructions and named machine instructions
        else {
            inst = findInstruction(resultField, len);
            if (inst != NULL) {
                if ((inst->attributes & INST_MACHINE) != 0) {
                    if (currentModule->id[0] != '\0' && isCodeSection(currentSection)) {
                        if (locationFieldToken != NULL) {
                            err = registerError(addLocationSymbol(currentSection,
                                                                  locationFieldToken->details.name.ptr,
                                                                  locationFieldToken->details.name.len,
                                                                  SYM_PARCEL_ADDRESS));
                        }
                        err = registerError((*inst->handler)());
                    }
                    else {
                        err = registerError(Err_InstructionPlacement);
                    }
                }
                else {  pseudo-instruction
                    err = registerError((*inst->handler)());
                }
            }
              Process other machine instruction forms
            else if (currentModule->id[0] != '\0' && isCodeSection(currentSection)) {
                err = registerError(processMachineInstruction());
            }
            else {
                err = registerError(Err_InstructionPlacement);
            }
        }
    }
    listErrorIndications();
    listFlush(currentSection);
    return err;
}
ErrorCode parseSourceLine ( void ) { ErrorCode err ; NamedInstruction * inst ; int len ; MacroDefn * macroDefn ; char * s ; Symbol * symbol ; Token token ; err = Err_None ; resetLocationField ( ) ; resetErrorRegistrations ( ) ; listSource ( ) ; if ( sourceLine [ 0 ] == ' ' || sourceLine [ 0 ] == ' \0 ' ) { listFlush ( currentSection ) ; return err ; } getFields ( ) ; s = getNextToken ( locationField , & token ) ; switch ( token . type ) { case TokenType_Name : if ( * s == ' \0 ' && isUnqualifiedName ( & token ) ) { locationFieldToken = copyToken ( & token ) ; } else { err = registerError ( Err_LocationField ) ; } break ; case TokenType_None : break ; case TokenType_Error : err = registerError ( token . details . error . code ) ; break ; default : err = registerError ( Err_LocationField ) ; break ; } len = strlen ( resultField ) ; if ( len > 0 ) { macroDefn = findMacroDefn ( resultField , len ) ; if ( macroDefn != NULL ) { listCodeLocation ( currentSection ) ; err = registerError ( callMacro ( macroDefn , locationFieldToken ) ) ; } else { inst = findInstruction ( resultField , len ) ; if ( inst != NULL ) { if ( ( inst -> attributes & INST_MACHINE ) != 0 ) { if ( currentModule -> id [ 0 ] != ' \0 ' && isCodeSection ( currentSection ) ) { if ( locationFieldToken != NULL ) { err = registerError ( addLocationSymbol ( currentSection , locationFieldToken -> details . name . ptr , locationFieldToken -> details . name . len , SYM_PARCEL_ADDRESS ) ) ; } err = registerError ( ( * inst -> handler ) ( ) ) ; } else { err = registerError ( Err_InstructionPlacement ) ; } } else { err = registerError ( ( * inst -> handler ) ( ) ) ; } } else if ( currentModule -> id [ 0 ] != ' \0 ' && isCodeSection ( currentSection ) ) { err = registerError ( processMachineInstruction ( ) ) ; } else { err = registerError ( Err_InstructionPlacement ) ; } } } listErrorIndications ( ) ; listFlush ( currentSection ) ; return err ; }
parseSourceLine - parse a line of source text
  This is the main processing function of the assembler.
parseSourceLine - parse a line of source text This is the main processing function of the assembler .
// //  Process the location field. It may have at most one token, //  and the one token must be an unqualified name. // // do nothing // //  Process the result field. First, check for a macro call, then //  check for a pseudo-instruction or a named machine instruction. //  if no matches are found for those, attempt to match other //  machine instruction patterns. // // //  Process macro calls // // //  Process pseudo-instructions and named machine instructions // // pseudo-instruction // //  Process other machine instruction forms //