Commits

Jordan Earls committed 1de51f7

Working on parsing arguments to opcodes now

  • Participants
  • Parent commits 763f15e

Comments (0)

Files changed (2)

 
 char* skip_whitespace(char* part, int len)
 {
+  if(len==-1)
+  {
+    len=strlen(part);
+  }
   for(int i=0;i<len;i++)
   {
     char c=part[i];
 
 #define assert_that(x) if(!(x)){return -1;}
 
+char* parse_label(char* arg, char[8] buffer)
+{
+  int i=0;
+  while(true)
+  {
+    char c=*arg;
+    if(IS_WHITESPACE(c) || c == ']' || c==',' || c==NULL)
+    {
+      buffer[8]=0;
+      return arg;
+    }
+    if(i<7)
+    {
+      buffer[i]=c;
+    }
+    i++;
+  }
+  
+}
+
+int lasm_parse_argument(char* arg, opcode_argument_t* buf)
+{
+  char* skipped=skip_whitespace(arg, len);
+  buf->indirect=false;
+  if(skipped[0]=='[')
+  {
+    buf->indirect=true;
+  }
+  skipped=skip_whitespace(&skipped[1], -1);
+  if(IS_NUMBER(skipped[1])) //immediate number
+  {
+    buf->immediate=true;
+    buf->value=strtol(skipped, &skipped, 0);
+  }else if(skipped[1]='$') //label
+  {
+    skipped=parse_label(skipped+2, buf->label);
+  }else{ //register
+    
+  }
+  
+  
+}
+
+
+
 int lasm_handle_opcode(lasm_parse_state_t* parse, char** groups)
 {
   if(!strcmp("xor", groups[0]))
       assert_that(!strcmp("8", groups[1]));
       parse->is_8bit=true;
     }
+    
   }
   else
   {
 }
 #undef assert_that
 
+static char lasm_group_holder[4][5]={{0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0} ,{0,0,0,0,0}};
 
+//returns 0 on successful opcode parsed and turned into template
+//returns -1 on error, 1 on insignificant line 
 int lasm_parse_part(lasm_parse_state_t* parse, char* part)
 {
   int len=strlen(part);
     {
       return 1;
     }
+    if(lasm_parse_opcode(skipped, lasm_group_holder)==-1)
+    {
+      return -1;
+    }
+    if(lasm_handle_opcode(parse, lasm_group_holder) == -1)
+    {
+      return -1;
+    }
   }
   else
   {
   
 } lasm_state_t;
 
+typedef struct lasm_opcode_argument
+{
+  bool immediate;
+  bool reg;
+  bool indirect;
+  int value;
+  char label[8];
+}lasm_opcode_argument_t;
+
 typedef struct lasm_error
 {
   char *msg;
 enum EXPECTED_PARSE
 {
   OPCODE,
-  OPCODE_EXTENSION,
   ARG1,
   ARG2,
   ENDING
 
 
 #define IS_WHITESPACE(c) (c==' ' || c=='\t' || c=='\r' || c=='\n')
+#define IS_NUMBER(c) (c>='0' && c<='9')
 
 //"public" interface