flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Parser...

Author
Thread Post new topic Reply to topic
metalfishx



Joined: 30 Sep 2004
Posts: 65
Location: Florida, Uruguay
metalfishx 04 Nov 2004, 13:55
Hello world Smile
Im trying to build a parser with pure macro that ill use on my basic compiler Smile
But i have some issues that maybe some master can helpme on...
This is the start of my parser:

Code:
;MY START OF A PARSER
;Modified a little to be more hadnly hehe, but still 
;i need figure out how to join the found chars to test keywords..

macro Parse{
CharCounter = 0
virtual at 0
     ;The code to be parsed
}


;The code is writed here; between Parse and EndParse


macro EndParse{
     ;The size in bytes of the code
     CODE_SIZE = $
     ;Main loop Smile
repeat CODE_SIZE
      ;$ is the address; CODE_SIZE is the char count, % is the repeat percent done
      load char byte from $ - CODE_SIZE + % - 1
      CODE_POINTER = CODE_SIZE - %
      if char = 'A' | char = 'a' ;aA
        display "A"
        CharCounter = CharCounter + 1
      else if char = 'B' | char = 'b' ;bB
        display "B"
        CharCounter = CharCounter + 1
      else if char = 'C' | char = 'c' ;cC
        display "C"
        CharCounter = CharCounter + 1
      else if char = 'D' | char = 'd' ;dD
        display "D"
        CharCounter = CharCounter + 1
      else if char = 'E' | char = 'e' ;eE
        display "E"
        CharCounter = CharCounter + 1
      else if char = 'F' | char = 'f' ;fF
        display "F"
        CharCounter = CharCounter + 1
      else if char = 'G' | char = 'g' ;gG
        display "G"
        CharCounter = CharCounter + 1
      else if char = 'H' | char = 'h' ;hH
        display "H"
        CharCounter = CharCounter + 1
      else if char = 'I' | char = 'i' ;iI
        display "I"
        CharCounter = CharCounter + 1
      else if char = 'J' | char = 'j' ;jJ
        display "J"
        CharCounter = CharCounter + 1
      else if char = 'K' | char = 'k' ;kK
        display "K"
        CharCounter = CharCounter + 1
      else if char = 'L' | char = 'l' ;lL
        display "L"
        CharCounter = CharCounter + 1
      else if char = 'M' | char = 'm' ;mM
        display "M"
        CharCounter = CharCounter + 1
      else if char = 'N' | char = 'n' ;nN
        display "N"
        CharCounter = CharCounter + 1
      else if char = 'O' | char = 'o' ;oO
        display "O"
        CharCounter = CharCounter + 1
      else if char = 'P' | char = 'p' ;pP
        display "P"
        CharCounter = CharCounter + 1
      else if char = 'Q' | char = 'q' ;qQ
        display "Q"
        CharCounter = CharCounter + 1
      else if char = 'R' | char = 'r'
        display "R"
        CharCounter = CharCounter + 1
      else if char = 'S' | char = 's' ;sS
        display "S"
        CharCounter = CharCounter + 1
      else if char = 'T' | char = 't' ;tT
        display "T"
        CharCounter = CharCounter + 1
      else if char = 'U' | char = 'u' ;uU
        display "U"
        CharCounter = CharCounter + 1
      else if char = 'V' | char = 'v' ;vV
        display "V"
        CharCounter = CharCounter + 1
      else if char = 'W' | char = 'w' ;wW
        display "W"
        CharCounter = CharCounter + 1
      else if char = 'X' | char = 'x' ;xX
        display "X"
        CharCounter = CharCounter + 1
      else if char = 'Y' | char = 'y' ;yY
        display "Y"
        CharCounter = CharCounter + 1
      else if char = 'Z' | char = 'z' ;zZ
        display "Z"
        CharCounter = CharCounter + 1
      ;SIMBOLS
      else if char = '"'
          display '"'
      else if char = ' '
          display ' '
      else if char = 0
          display 13,10,'END OF THE CODE'
      else if char = 13
          display 13
      else if char = 10
          display 10
      end if
end repeat
end virtual
}


;Start the code parsing
Parse
     db 'dim tete as string',13,10,\
     'msgbox "Hello World" ',13,10,\
     'Halt',0
EndParse
    


This is just to show that the Chars are readed ok; but my problem is how to build the tokens.
Maybe im fool, but, how to atach each char to a var? For example, i have used:

Code:

.....
      else if ..char = 7Ah | ..char = 5Ah ;zZ
          display "Found Z",13,10
          ..token#..char
        tokenlenghtcounter = tokenlenghtcounter + 1
....
    


Even i try with:

Code:

.....
      else if ..char = 7Ah | ..char = 5Ah ;zZ
          display "Found Z",13,10
          ..token#'Z'
        tokenlenghtcounter = tokenlenghtcounter + 1
....
    


But not work.

I need this to see the formed word is a knowed token to recognise the word; if the word is "DIM" then do something for example.. Smile

Can the macro masters tellme how i can store each found char in a var?
Also, can some one join to this parser project in asm? Very Happy

Thanks!

_________________
---------------------------------------
Roberto A. Berrospe Machin
Ruta Internet, Florida Uruguay
---------------------------------------


Last edited by metalfishx on 05 Nov 2004, 14:24; edited 2 times in total
Post 04 Nov 2004, 13:55
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20527
Location: In your JS exploiting you and your system
revolution 04 Nov 2004, 22:00
This is a problem that cannot be solved unless you know the tokens beforehand and test for each token (probably with a macro iterating through each token over an input parameter).

Basically the problem comes to this: the variable names (labels) cannot be made during assembly time.
Post 04 Nov 2004, 22:00
View user's profile Send private message Visit poster's website Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85 05 Nov 2004, 00:09
Hi!

I wrote some macros after your problem, but without success.

I'm not a 'macro master', so I hope to be wrong: FASM currently lacks some features, which precludes your project to be completed. Talking about macro recursion, non-fixed repeat's and string manipulation.

But the problem here is that the % operator takes place before load operator(which seems to do a name = M[location]).
Post 05 Nov 2004, 00:09
View user's profile Send private message Reply with quote
metalfishx



Joined: 30 Sep 2004
Posts: 65
Location: Florida, Uruguay
metalfishx 05 Nov 2004, 02:23
hi guys.
Well, you both are right in something (is complicated to do this) Smile hehe.
But actually this code i made is workign; maybe i dont explain as well, what i need next is, when a new char is found, join this char to the others, and after joined, i need test if the actual joined chars are one keyword. I have tested with token#char, and things like this, but dont work, i have problems. beppe85, % and all in load are working as well; try to write the code as is it actuall to a new fasm document, and compile them, anb you will see the messages; all the correspondent chars are found and you see the message "Found Bla"...
The thing i need to figure out is how to join the chars and test these joined chars looking for a keyword name.. and so on... Smile
im thinking about store; but i still dont figure out how to implement...
ok, thanks four you responses! ill contiunue, theres will be a way; i think nothing is impossible in this world, haha
Smile
Post 05 Nov 2004, 02:23
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.