
#include "ass.h"

extern indx;
extern char line[];

operand1()
{
    int dummy;

    if (reg() != -1)
        return FALSE;
    if (line[indx] == '(')
    {
        brackreg();
        if (line[indx] == '+')
            indx++;
        return FALSE;
    }
    if (line[indx] == '#')
    {
        indx++;
        expr(&dummy,&dummy,&dummy,FALSE);
        return TRUE;
    }
    if (line[indx] == '@')
    {
        indx++;
        if (line[indx] == '(')
        {
            brackreg();
            if (line[indx] == '+')
            {
                indx++;
                return FALSE;
            }
            else
                error("'+' expected");
        }
        if (line[indx]=='-' && line[indx+1]=='(')
        {
            indx++;
            brackreg();
            return FALSE;
        }
        if (line[indx] == '#')
        {
            indx++;
            expr(&dummy,&dummy,&dummy,FALSE);
            return TRUE;
        }
        expr(&dummy,&dummy,&dummy,FALSE);
        if (line[indx] == '(')
            brackreg();
        return TRUE;
    }
    if (line[indx]=='-' && line[indx+1]=='(')
    {
        indx++;
        brackreg();
        return FALSE;
    }
    expr(&dummy,&dummy,&dummy,FALSE);
    if (line[indx] == '(')
        brackreg();
    return TRUE;
}

reg()
{
    register r;
    
    if (line[indx]=='r' && line[indx+1]>='0' && line[indx+1]<='7')
        r=line[indx+1]-'0';
    else if (line[indx]=='s' && line[indx+1]=='p')
        r=6;
    else if (line[indx]=='p' && line[indx+1]=='c')
        r=7;
    else
        r=-1;
    if (r != -1)
        indx+=2;
    return r;
}

mustreg()
{
    register r;
    
    if ((r=reg()) == -1)
        error("register expected");
    return r;
}

brackreg()
{
    register r;

    indx++;
    r=mustreg();
    if (line[indx++] != ')')
        error("')' expected");
    return r;
}
