Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Maybe something for the math library... a WIP Math Parser!
#22
the same checking you describe is also done in the lexer ( see lex()) first you check for whitespaces and ignore them, then eol, then you check wheter it's a number, then you check for keywords, well and everything else is either a completely messed up token that doesn't follow one of the lexer rules or it's a variablename/constant. of course you have to keep track of already defined variables and constants. you could for example have such a udt

type variable
name as string * 255
expression as string * 10000
end type

type constant
name as string * 255
value as double
end type

and a datatstructure ( maybe linked list ) that keeps track of the currently in use variables and constants. you could get along with two arrays like

dim variables(MAX_VARIABLES) as variable
dim constants(MAX_CONSTANTS) as variable

so everytime you find a token that is only composed of letters and that is not a keyword you look that token up in the arrays and if you can find it either return the value along with the tokentype to the parser, or you first add that variable/constant to that arrays.

that's basically it, but uhm i'm to lazy to implement that. but it shouldn't be to hard.
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply


Messages In This Thread
Maybe something for the math library... a WIP Math Parser! - by marzecTM - 03-09-2005, 01:20 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)